Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import requests
- import json
- import sys
- base_url = 'https://sandbox-productservice.asicentral.com/api/v4/{0}'
- creds = {'Asi':'ASINUMBER', 'Username':'USERNAME', 'Password':'PASSWORD'}
- sess = requests.Session()
- sess.headers.update({'Content-Type':'application/json', 'Accept':'application/json'})
- auth_resp = sess.post(base_url.format('Login'), data = json.dumps(creds))
- if auth_resp.status_code == 200:
- sess.headers.update({'AuthToken':auth_resp.json()['AccessToken']})
- #We now have an access token for our session
- #Now we can make requests to get & post products
- #Here's an example of getting all product data for a specific product
- print sess.get(base_url.format('product/%s' % 'REPLACEWITHANEXISTINGXID')).json()
- else:
- raise ValueError('Credentials are invalid.')
- sys.exit()
Advertisement
Add Comment
Please, Sign In to add comment