Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import requests
- import json
- import os
- def getSuppliers(token,clientID):
- """Access Token gets passed from the API and then makes a request to the client to get a list of all the suppliers"""
- url_suppliers = "https://api.avetta.com/admin/v1/clients/" + str(clientID) + "/suppliers?offset=3000"
- payload = ""
- headers = {
- 'Authorization': token,
- 'cache-control': "no-cache",
- 'Postman-Token': "803d5bbd-707f-42a4-831e-401d06af07da"
- }
- response = requests.request("GET", url_suppliers, data=payload, headers=headers)
- r = response.json()
- # 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
- #os.chdir(r"C:\Users\GiulianoAltobelli\Documents\Tickets".replace('\\','/'))
- with open("testingfileabc.json", 'w') as outfile:
- json.dump(r, outfile)
- #print(response.text)
- def GetAccessToken():
- """This is a call to the API to grant authentication and store the access token"""
- url_access_token = "https://api.avetta.com/auth/v1/token"
- username = input("Please enter username")
- password = input("Please enter password")
- clientID = input("Please input Client Mongo ID")
- #file = input("Please copy and paste the address of the directore where you would like to store the JSON file")
- authentication = "{\n\t\"username\":\"" + str(username) + "\",\n\t\"password\":\"" + str(password) + "\",\n\t\"grant_type\":\"password\"\n\t\n}"
- #print(authentication)
- headers = {
- 'Content-Type': "application/json",
- 'cache-control': "no-cache",
- 'Postman-Token': "00440380-2194-4868-9d7c-a7184ae8ee44"
- }
- response = requests.request("POST", url_access_token, data=authentication, headers=headers)
- r = response.json()
- token = r["access_token"]
- return(getSuppliers(token,clientID))
- GetAccessToken()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement