Advertisement
Guest User

Untitled

a guest
Jan 18th, 2019
110
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.89 KB | None | 0 0
  1. import requests
  2. import json
  3. import os
  4.  
  5. def getSuppliers(token,clientID):
  6.     """Access Token gets passed from the API and then makes a request to the client to get a list of all the suppliers"""
  7.     url_suppliers = "https://api.avetta.com/admin/v1/clients/" + str(clientID) + "/suppliers?offset=3000"
  8.     payload = ""
  9.     headers = {
  10.         'Authorization': token,
  11.         'cache-control': "no-cache",
  12.         'Postman-Token': "803d5bbd-707f-42a4-831e-401d06af07da"
  13.     }
  14.  
  15.     response = requests.request("GET", url_suppliers, data=payload, headers=headers)
  16.     r = response.json()
  17.     # Trying to figure out how to change dir with user input for now it will just save on C drive and u can search the file name
  18.     #os.chdir(r"C:\Users\GiulianoAltobelli\Documents\Tickets".replace('\\','/'))
  19.     with open("testingfileabc.json", 'w') as outfile:
  20.         json.dump(r, outfile)
  21.  
  22.  
  23.     #print(response.text)
  24.  
  25.  
  26. def GetAccessToken():
  27.     """This is a call to the API to grant authentication and store the access token"""
  28.     url_access_token = "https://api.avetta.com/auth/v1/token"
  29.     username = input("Please enter username")
  30.     password = input("Please enter password")
  31.     clientID = input("Please input Client Mongo ID")
  32.     #file = input("Please copy and paste the address of the directore where you would like to store the JSON file")
  33.     authentication = "{\n\t\"username\":\"" + str(username) + "\",\n\t\"password\":\"" + str(password) + "\",\n\t\"grant_type\":\"password\"\n\t\n}"
  34.     #print(authentication)
  35.     headers = {
  36.         'Content-Type': "application/json",
  37.         'cache-control': "no-cache",
  38.         'Postman-Token': "00440380-2194-4868-9d7c-a7184ae8ee44"
  39.     }
  40.  
  41.     response = requests.request("POST", url_access_token, data=authentication, headers=headers)
  42.     r = response.json()
  43.     token = r["access_token"]
  44.     return(getSuppliers(token,clientID))
  45. GetAccessToken()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement