File size: 1,697 Bytes
29d6991
564b7f3
c0519eb
7d91e63
 
 
 
 
 
c0519eb
564b7f3
29d6991
c0519eb
29d6991
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
c0519eb
7d91e63
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
import requests
from simple_salesforce import Salesforce

# Salesforce credentials (Directly included in the code)
consumer_key = '3MVG9PwZx9R6_UrfAEK05VEm.bbDjlyPoEYQnaiFNTcDfa05aATw.cuifiB.xlmJ3WkGveCyJErK5tsrgq_DM'
consumer_secret = 'A4689ACC32DE07D94AD5511490C95FE63D98C30091170BA6ECF3286FF2AE44E0'
username = 'venkatramana@sandbox.com'
password = 'Seta12345@'
security_token = 'Drl0jchCwLBfvX4ODMeFDksP'

# Salesforce OAuth URL for production (use test.salesforce.com for sandbox)
auth_url = 'https://login.salesforce.com/services/oauth2/token'

# Prepare the data for OAuth token exchange
data = {
    'grant_type': 'password',
    'client_id': consumer_key,
    'client_secret': consumer_secret,
    'username': username,
    'password': f'{password}{security_token}'  # Password and security token concatenated
}

# Make the POST request to exchange credentials for an access token
response = requests.post(auth_url, data=data)

# Check if authentication was successful
if response.status_code == 200:
    # Extract the access token from the response
    access_token = response.json().get('access_token')
    instance_url = response.json().get('instance_url')
    
    # Use the access token to authenticate Salesforce
    sf = Salesforce(instance_url=instance_url, session_id=access_token)
    
    # Fetch Quote data from Salesforce (replace 'YOUR_QUOTE_ID' with actual Quote ID)
    quote_data = sf.query("SELECT Customer_Name__c, Quote_Date__c, Origination_Location__c, Total_Amount__c FROM Quote__c WHERE Id = 'YOUR_QUOTE_ID'")
else:
    print(f"Error authenticating: {response.status_code}")
    print(response.text)

# Return quote data
def get_quote_data():
    return quote_data