Skip to content

Instantly share code, notes, and snippets.

@wadewegner
Last active February 24, 2023 00:39
Show Gist options
  • Star 5 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save wadewegner/7557434 to your computer and use it in GitHub Desktop.
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.
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
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
@AntoOnline
Copy link

This was very useful today! Thanks.

@gbdavidx
Copy link

what if i need to use a cert?

@abeburnett
Copy link

very helpful, thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment