Files
Gainsight/Scripts/API_Tests/update_prop_from_email.py

56 lines
1.8 KiB
Python
Raw Normal View History

import requests
import Apikeys
import csv
apikey = Apikeys.talkspace_1099
url_email = "https://api.northpass.com/v2/people?filter[email][eq]="
import_list = "/Users/normrasmussen/Downloads/Talkspace-bulk.csv"
def getfromEmail(url_email, apikey, import_list):
uuid = ""
with open(import_list, newline='') as csvfile:
file = csv.reader(csvfile, delimiter=',')
for items in file:
email = items[0]
url = url_email + f"{email}"
headers = {
"accept": "*/*",
"x-api-key": apikey,
"content-type": "application/json",
}
response = requests.get(url, headers=headers)
if response.status_code == 200:
response = response.json()
for data in response["data"]:
uuid = data["id"]
items.append(uuid)
# print(uuid)
add_multi_prop(uuid)
else:
print("Another Error!")
def add_multi_prop(uuid):
url = "https://api.northpass.com/v2/properties/people/bulk"
payload = {"data": [
{
"type": "person_properties",
"attributes": {"properties": {
"paid": "true",
}},
"id": uuid
}
]}
headers = {
"accept": "application/json",
"content-type": "application/json",
"X-Api-Key": apikey}
response = requests.post(url, json=payload, headers=headers)
if response.status_code == 404 or response.status_code == 403:
print(f"Error {response.status_code} with user {uuid}")
else:
print(f"Successfully Added props for {uuid}!")
if __name__ == "__main__":
getfromEmail(url_email, apikey, import_list)