caffeinatedmike

Asi AccessToken

Aug 9th, 2018
228
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.80 KB | None | 0 0
  1. import requests
  2. import json
  3. import sys
  4.  
  5. base_url = 'https://sandbox-productservice.asicentral.com/api/v4/{0}'
  6. creds = {'Asi':'ASINUMBER', 'Username':'USERNAME', 'Password':'PASSWORD'}
  7.  
  8. sess = requests.Session()
  9. sess.headers.update({'Content-Type':'application/json', 'Accept':'application/json'})
  10.  
  11. auth_resp = sess.post(base_url.format('Login'), data = json.dumps(creds))
  12. if auth_resp.status_code == 200:
  13.     sess.headers.update({'AuthToken':auth_resp.json()['AccessToken']})
  14.     #We now have an access token for our session
  15.     #Now we can make requests to get & post products
  16.     #Here's an example of getting all product data for a specific product
  17.     print sess.get(base_url.format('product/%s' % 'REPLACEWITHANEXISTINGXID')).json()
  18. else:
  19.     raise ValueError('Credentials are invalid.')
  20.     sys.exit()
Advertisement
Add Comment
Please, Sign In to add comment