I'm trying to upload new records to a contact list using python, but I am not sure how I have to make the request (I always get 400 error, bad request) . Here is the code I've tried:
url = "https://apps.mypurecloud.ie/uploads/v2/contactlist"
with open("example.csv", "rb") as f:
headers = {'Authorization': 'Bearer ' + token}
body = {
"id" : contact_list_id,
"file": f.read(),
"fileType" : "contactlist",
"contact-id-name": "Id"
}
r = requests.post(url, data=body, headers=headers)
Could someone tell me how can I do the request?
Thank you
The request's content-type must be multipart/form-data.
I am a newbie on Python so I hope I haven't forgotten something below.
I just tried the following and it seems to work.
2 things to change in your request: files=body in the request (files is to have multipart/form-data), and use of tuples (None, xxxx) for parameters other than file.
body = {
"id": (None, contact_list_id),
"file": f.read(),
"fileType": (None, "contactlist"),
"contact-id-name": (None, "Id")
}
r = requests.post(url, files=body, headers=headers)