Spaces:
Sleeping
Sleeping
Update utils/database_handler.py
Browse files- utils/database_handler.py +29 -14
utils/database_handler.py
CHANGED
|
@@ -10,21 +10,36 @@ SECURITY_TOKEN = "GH9RG97LroDoLe6gAAOHaJBP"
|
|
| 10 |
|
| 11 |
# Authenticate with Salesforce
|
| 12 |
def get_salesforce_access_token():
|
|
|
|
| 13 |
try:
|
| 14 |
-
|
| 15 |
-
|
| 16 |
-
|
| 17 |
-
|
| 18 |
-
|
| 19 |
-
|
| 20 |
-
|
| 21 |
-
|
| 22 |
-
|
| 23 |
-
|
| 24 |
-
|
| 25 |
-
|
| 26 |
-
|
| 27 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 28 |
return None, None
|
| 29 |
|
| 30 |
# Save user to Salesforce
|
|
|
|
| 10 |
|
| 11 |
# Authenticate with Salesforce
|
| 12 |
def get_salesforce_access_token():
|
| 13 |
+
"""Authenticate with Salesforce Developer Org and get an access token."""
|
| 14 |
try:
|
| 15 |
+
# Authentication URL for Salesforce production and Developer Org
|
| 16 |
+
auth_url = "https://login.salesforce.com/services/oauth2/token"
|
| 17 |
+
|
| 18 |
+
# Payload with credentials
|
| 19 |
+
payload = {
|
| 20 |
+
"grant_type": "password",
|
| 21 |
+
"client_id": "3MVG9PwZx9R6_UrcDlsRUsfM9CGTVKE82QnI5Vz02b.lv3H2yjDv_wy9.nrYihWYLUD1bv08N_qCG_gxiV5y8", # Consumer Key
|
| 22 |
+
"client_secret": "94983416FB1DF4E754B56F69982F07D94D8971523E6893B8A62D75CD8E9E3A34", # Consumer Secret
|
| 23 |
+
"username": "surendra@sathkrutha.ccom", # Developer Org username
|
| 24 |
+
"password": "Lavanyanaga@123" + "GH9RG97LroDoLe6gAAOHaJBP", # Password + Security Token
|
| 25 |
+
}
|
| 26 |
+
|
| 27 |
+
# Send POST request to authenticate
|
| 28 |
+
response = requests.post(auth_url, data=payload)
|
| 29 |
+
|
| 30 |
+
# Print full response for debugging
|
| 31 |
+
print("Response Status Code:", response.status_code)
|
| 32 |
+
print("Response Text:", response.text)
|
| 33 |
+
|
| 34 |
+
response.raise_for_status() # Raise error for bad HTTP responses
|
| 35 |
+
|
| 36 |
+
# Parse and return the access token and instance URL
|
| 37 |
+
access_token = response.json().get("access_token")
|
| 38 |
+
instance_url = response.json().get("instance_url")
|
| 39 |
+
print(f"Successfully authenticated. Instance URL: {instance_url}")
|
| 40 |
+
return access_token, instance_url
|
| 41 |
+
except requests.exceptions.RequestException as e:
|
| 42 |
+
print(f"Error obtaining Salesforce access token: {e}")
|
| 43 |
return None, None
|
| 44 |
|
| 45 |
# Save user to Salesforce
|