-
-
Save zsprackett/5851549 to your computer and use it in GitHub Desktop.
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 json | |
import requests | |
url = "<<instanceurl>>/rest/v10/oauth2/token" | |
payload = {"grant_type":"password","username":"<<username>>","password":"<<password>>","client_id":"sugar"} | |
r = requests.post(url, data=json.dumps(payload)) | |
response = json.loads(r.text) | |
if response[u'error']: | |
print response[u'error_message'] | |
token = response[u'access_token'] | |
print 'Success! OAuth token is ' + token | |
url = "<<instanceurl>>/rest/v10/me" | |
headers = { "Content-Type" : "application/json", "OAuth-Token": token } | |
r = requests.get(url, headers=headers); | |
response = json.loads(r.text) | |
if response[u'error']: | |
print response[u'error_message'] | |
print r.json() | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment