I'm trying to automate the upload contact list process. I try to use the /uploads/v2/contactlist API but without success. Follow how I'm calling the API:
To add to my answer, there's documentation here on uploading contact lists.
It appears that your body may be incorrect; The server is expecting multipart form-data, not JSON. You have the correct header but the body format isn't.
I'm still with some problems. It's very strange due that in Postman runs perfectly but when I get the Powershell code generated in Postman and run as a script I got the 400 status. Follow the code in Powershell. Where am I doing wrong?
PS.: I already try: without the boundary in the headers; using ContentType = 'text/plain'; using ContentType = "application/octet-stream".
function ImportContactList($ContactListID,$FileName) {
$headers = New-Object "System.Collections.Generic.Dictionary[[String],[String]]"
$headers.Add("Authorization", "Bearer "+$token)
I'm not personally familiar with building requests in powershell, but the 400 response is indicating that something is malformed in your request. Refer to the values used in the example Ronan linked above, as well as the multipart form data RFC that defines the format for such a request.
Thanks for your reply, Tim!
It is strange because when I run it on Postman, the upload is done. I got the code from Postman, but it didn't work.
I try to run in cURL too and here are the response:
2021-02-03 11:20:16 ::: Request curl -X POST -H 'Authorization: Bearer $token' -F 'id="19e73dac-9b87-44b6-a8e8-fb39bfa10826"' -F "file=@C:\FDR\LoadFiles\1-TST_PC_20210203_TestDaniel.csv" -F 'fileType="contactlist"' -F 'contact-id-name="PLATFORM-DEBTOR-XLOCATOR"' 'https://apps.mypurecloud.com/uploads/v2/contactlist'
2021-02-03 11:20:23 ::: Result {"correlationId":"171b137c-94df-4eb7-beb5-55e31c940b71"}
In this case, the API returns me the correlation ID, but the file was not uploaded.
The error associated with that correlation ID is "A ContactList with id $ContactListID could not be found". It appears that the literal value $ContactListID is being used as the ID for the contact list. Either your request is sending that value or your request is malformed in some way that's preventing the service from getting the ID you're trying to send.