Trying to upload contact list via Upload Contact Lists feature in powershell script. Looks like it's working, but no contacts are imported Get response:
correlationId
35517118-160f-45a4-b5d3-8cc97307a040
Code below:
$environment = "usw2.pure.cloud";
$id = Removed
$secret = Removed
$FilePath = '\Users\kroght\OneDrive - Cedars-Sinai Health System\Documents\genesys parse\pfs_selfpay.txt'
$auth = [System.Convert]::ToBase64String([System.Text.Encoding]::UTF8.GetBytes("${id}:${secret}"))
$response = Invoke-WebRequest -Uri "https://login.${environment}/oauth/token" -Method POST -Body @{grant_type='client_credentials'} -Headers @{"Authorization"="Basic ${auth}"}
$responseData = $response.content | ConvertFrom-Json
#Wrtie the Bearer token to a variable.
$bearer = "Bearer " + $responseData.access_token
write-host $bearer
$ContactListID = REMOVED
$URL = 'https://apps.usw2.pure.cloud/uploads/v2/contactlist';
$fileBytes = [System.IO.File]::ReadAllBytes($FilePath);
$fileEnc = [System.Text.Encoding]::GetEncoding('UTF-8').GetString($fileBytes);
$boundary = [System.Guid]::NewGuid().ToString();
$LF = "r
n";
$headers = New-Object "System.Collections.Generic.Dictionary[[String],[String]]"
$headers.Add("authorization", $bearer)
$bodyLines = (
"--$boundary",
"Content-Disposition: form-data; name="file
"; filename="temp.txt
"",
"id: $ContactListID",
"fileType: contactlist",
"contact-id-name: Contact ID",
"Content-Type: application/octet-stream$LF",
$fileEnc,
"--$boundary--$LF"
) -join $LF
Write-Host $headers
Write-Host $bodyLines
try{
Invoke-RestMethod -Uri $URL -Method Post -ContentType "multipart/form-data; boundary="$boundary
"" -Headers $headers -Body $bodyLines
}
catch{
Write-Host "Error Message:" $.Exception.Message
Write-Host $.ErrorDetails.Message
Write-Host $ContactListID.id "," $ContactListID
}