DV,Walmart, API Tests

This commit is contained in:
Norm Rasmussen
2022-11-03 21:06:46 -04:00
parent f9d4502301
commit 45f1f32b3b
6 changed files with 145 additions and 100 deletions

View File

@ -3,11 +3,13 @@ import sys
import http
import pandas as pd
apiKey = "SlpQlju219WnWogn94dQUT6Yt"
#groupName = sys.argv[1]
peopleCsv = "/Users/normrasmussen/Downloads/peopletogroups.csv"
# Enter your API Key between the quotation marks.
apiKey = ""
groupName = sys.argv[1]
peopleCsv = "/path/to/file/peopletogroups.csv"
def createGroup(groupName, apiKey):
#apiKey = input("What is your API Key? ")
# Create a Group endpoint - params: group_uuid
url = "https://api.northpass.com/v2/groups"
payload = {"data": {"attributes": {"name": f"{groupName}"}}}
@ -40,58 +42,42 @@ def getgroupId(people, groupresponse, apiKey):
ppltoGroup(people, groupID, apiKey)
def ppltoGroup(people, groupID, apiKey):
print(groupID)
# Add People to a Group. Params needed: group_uuid
url = f"https://api.northpass.com/v2/groups/{groupID}/relationships/people"
# Loop through this payload and/or add everyone as new { "type":"people", "id":"uuid"}
#for uuid in people:
# itempayload = []
# jsonpayload = { "type":"people", "id":uuid },
# itempayload.append(jsonpayload)
payload = {"data": [
for uuid in people:
payload = {"data": [
{
"type":"people",
"id":people
"id":uuid
},
# { "type":"people", "id":people[1]},
# { "type":"people", "id":people[2]},
]}
# Add People to a Group. Params needed: group_uuid
url = f"https://api.northpass.com/v2/groups/{groupID}/relationships/people"
headers = {
"accept": "*/*",
"content-type": "application/json",
"X-Api-Key": apiKey
}
response = requests.post(url, json=payload, headers=headers)
if "404" in response.text:
print("Error returned for this user. Collecting names.")
errorNames(apiKey, uuid)
else:
pass
def errorNames(apiKey, uuid):
url = f"https://api.northpass.com/v2/people/{uuid}"
headers = {
"accept": "*/*",
"content-type": "application/json",
"accept": "application/json",
"X-Api-Key": apiKey
}
print(url)
print(payload)
print(headers)
response = requests.post(url, json=payload, headers=headers)
print(response.text)
response = requests.get(url, headers=headers)
response = response.json()
errorList = []
names = response["data"]["attributes"]["full_name"]
errorList.append(names)
fullNames(errorList)
def fullNames(errorList):
print(errorList)
if __name__ == "__main__":
ppltoGroup(people="0b31c435-c18b-4573-984e-32cda57045b4", groupID="4f83841f-939f-469f-b98f-29ce7f980c6e",apiKey="SlpQlju219WnWogn94dQUT6Yt")
#createGroup(groupName, apiKey)
url = "https://api.northpass.com/v2/groups/4c2e807c-2b65-4ce7-a359-2e470fe4f322/relationships/people"
payload = {"data": [
{
"type": "people",
"id": "0b31c435-c18b-4573-984e-32cda57045b4"
},
{
"type": "people",
"id": "0b31c435-c18b-4573-984e-32cda57045b4"
}
]}
headers = {
"accept": "*/*",
"content-type": "application/json",
"X-Api-Key": "SlpQlju219WnWogn94dQUT6Yt"
}
response = requests.post(url, json=payload, headers=headers)
print(response.text)
createGroup(groupName, apiKey)