Last active
February 24, 2023 00:39
-
-
Save wadewegner/7557434 to your computer and use it in GitHub Desktop.
Simple Python scripts for making a token request against the Force.com REST APIs. The first does not include the security token and the second does. You will want to use the second one.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import requests | |
consumer_key = "YOUR_CONSUMER_KEY" | |
consumer_secret = "YOUR_CUSTOMER_SECRET" | |
username = "YOUR_USER_NAME" | |
password = "YOUR_PASSWORD" | |
payload = { | |
'grant_type': 'password', | |
'client_id': consumer_key, | |
'client_secret': consumer_secret, | |
'username': username, | |
'password': password | |
} | |
r = requests.post("https://login.salesforce.com/services/oauth2/token", | |
headers={"Content-Type":"application/x-www-form-urlencoded"}, | |
data=payload) | |
print r.content |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import requests | |
consumer_key = "YOUR_CONSUMER_KEY" | |
consumer_secret = "YOUR_CUSTOMER_SECRET" | |
username = "YOUR_USER_NAME" | |
password = "YOUR_PASSWORD" | |
security_token = "YOUR_SECURITY_TOKEN" | |
payload = { | |
'grant_type': 'password', | |
'client_id': consumer_key, | |
'client_secret': consumer_secret, | |
'username': username, | |
'password': password + security_token | |
} | |
r = requests.post("https://login.salesforce.com/services/oauth2/token", | |
headers={"Content-Type":"application/x-www-form-urlencoded"}, | |
data=payload) | |
print r.content |
what if i need to use a cert?
very helpful, thank you!
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This was very useful today! Thanks.