Skip to content

Instantly share code, notes, and snippets.

@krypted
Last active April 25, 2018 01:57
Show Gist options
  • Save krypted/328c4ac0c9ac556eb92e87ea17505423 to your computer and use it in GitHub Desktop.
Save krypted/328c4ac0c9ac556eb92e87ea17505423 to your computer and use it in GitHub Desktop.
import requests
import json
import sys
print("Connecting to Salesforce")
print("")
access_token_url = 'https://login.salesforce.com/services/oauth2/token'
data = {
'grant_type': 'password',
'client_id': 'INSERTYOURCLIENTIDHERE',
'client_secret': 'INSERTYOURCLIENTSECRETHERE',
'username': sys.argv[1],
'password': sys.argv[2]
}
headers = {
'content-type': 'application/x-www-form-urlencoded'
}
req = requests.post(access_token_url, data=data, headers=headers)
response = req.json()
print("Completed OAuth Response ==> ")
print(json.dumps(response, indent=4,))
print("")
access_token = response['access_token']
print("Access Token ==> " + access_token)
data = {
'format': 'json',
'oauth_token': access_token
}
req = requests.post(response['id'], data=data, headers=headers)
response = req.json()
print("Completed Identity Response ==> ")
print(json.dumps(response, indent=4,))
print("")
print("First Name ==> " + response['first_name'])
print("Last Name ==> " + response['last_name'])
print("Email ==> " + response['email'])
print("")
print("Disconnecting from Salesforce")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment