Hello,
Context:
Every week I do two to three contact imports that I add to a statistical list afterwards to trigger a workflow (send emails).
I want to automate these imports using Python/API-HubSpot.
I coded a code that doesn’t work, I don’t really understand where the error comes from.
What I want to do: import contacts on HubSpot with the API and then add them in my static list.
My code:
```
AddList = “https://api.hubapi.com/contacts/v1/lists/LIST_ID/add?hapikey=API-Key”
emailList = “”
with open(“contacts - in.csv”) as csv_file:
csv_reader = csv.reader(csv_file, delimiter=‘,’)
line_count = 0
for row in csv_reader:
# This will skip the header row;
if line_count == 0:
line_count += 1
pass
else:
# My emails happen to be in column c, you may need to change this.
# If the csv file is open in excel column A = 0, B = 1, C = 2, D = 3…
emailList += “\”“+row[2] + “\”,\n”
line_count += 1
mydata = “”“{
“vids”: [],
“emails”: [
“””+emailList[:-2]+“”" #This will remove the extra spaces and characters at the end
]
}“”"
headers = {‘content-type’: ‘application/json’}
response = requests.request(“POST”, AddList, headers = headers, data = mydata)
print(response.text.encode(‘utf8’))
print(response.status_code)
```
ERROR:
![]()
Thanks for your help ![]()