APIs & Integrations

BCamaglia
Member

Contacts Build Import - multipart - Unable to process JSON error

Hello -

 

I have search this community as well as posted on Slack regarding this issue.  I update thousands of contacts daily and need to send them in bulk as processing them one at a time takes too long.  I have followed the documentation and suggestions made by others without success.  I am hopeing someone here can point out the obvious mistake and get me on my way.

 

I wrote a simple PowerShell script to send the bulk file.  HubSpot receives the request and returns an error 'Uable to process JSON'.  Here is my code, file, and HubSpot API messages.  In the below code, I generated the JSON by first creating an array and then converting to JSON.  I have also written the variable as text and convert to JSON - failed with the same error.  I have written the variable as JSON directly - failed with the same error.  As you can see, the request body in the HubSpot API log looks correct.  HubSpot appears to be receiving the correct information. Why is this error occurring and not processing?

 

I have spent hours on this and would greatly appreciate any help.

Thanks

Bryan

 

PowerShell Code:

$dt3 = Get-Date -format yyyyMMdd

$fileNameExist = 'Batch_'+$dt3+'_N.csv'
$fileNameExist2 = 'Batch_'+$dt3+'_N'

$formatRequestExist8 = @{
'name' = "$fileNameExist2"
'files' = (
@{
'fileName' = "$fileNameExist"
'fileFormat' = "CSV"
'dateFormat' = "YEAR_MONTH_DAY"
'fileImportPage' = @{
'hasHeader' = $true
'columnMappings' = (
@{
'columnObjectTypeId' = "0-1"
'columnName' = "firstName"
'propertyName' = "firstname"
'idColumnType' = $null
},
@{
'columnObjectTypeId' = "0-1"
'columnName' = "lastName"
'propertyName' = "lastname"
'idColumnType' = $null
},
@{
'columnObjectTypeId' = "0-1"
'columnName' = "email"
'propertyName' = "email"
'idColumnType' = $null
}
)
}
}
)
} | ConvertTo-Json -depth 10

$formatRequestExist88 = $formatRequestExist8.replace(' ','')


$uri = "https://api.hubspot.com/crm/v3/imports"


$filePath="E:\itAutomation\Hubspot\ToHubspot\New\"+$fileNameExist
$filePath2 = "/E:/itAutomation/Hubspot/ToHubspot/New/"+$fileNameExist

$fileBin = [System.IO.File]::ReadAlltext($filePath)
$boundary = [System.Guid]::NewGuid().ToString()
$LF = "`r`n"
$bodyLines = (
"--$boundary",
"Content-Disposition: form-data; name=`"importRequest`"$LF",
#"Content-Type: application/json;charset=utf-8$LF",
$formatRequestExist88,
"--$boundary",
"Content-Disposition: form-data; name=`"files`"; filename=`"$filePath2`"",
#"Content-Type: application/octet-stream$LF",
"Content-Type: text/csv$LF",
$fileBin,
"--$boundary--$LF"
) -join $LF


$headers = New-Object "System.Collections.Generic.Dictionary[[String],[String]]"
$headers.Add("Content-Type", "multipart/form-data; boundary=`"$boundary`"")
$headers.Add("Authorization", "Bearer pat-na**********")

write-host "Headers"
$headers #| ConvertTo-Json}
write-host "Body"
$bodyLines

[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls -bor
[Net.SecurityProtocolType]::Tls11 -bor [Net.SecurityProtocolType]::Tls12

Invoke-RestMethod -Uri $uri -Method Post -Headers $headers -Body $bodyLines

 

CSV Source File:

firstName,lastName,email
Joe,Smith,jsmith99901@gmail.com

 

API Log Information

Request Header:

{
"User-Agent": [
"Mozilla/5.0 (Windows NT; Windows NT 10.0; en-US) WindowsPowerShell/5.1.17763.1971"
],
"CDN-Loop": [
"cloudflare; subreqs=1"
],
"Accept-Encoding": [
"gzip"
],
"True-Client-IP": [
"1***"
],
"CF-Connecting-IP": [
"1***"
],
"X-HubSpot-Trace": [
"414c1a9d1cb0c2bff441a43caae3d5f9"
],
"Authorization": [
"Bearer pat-na******"
],
"X-HubSpot-Correlation-Id": [
"6899b906-ce85-455a-9d64-d63406738049"
],
"x-envoy-external-address": [
"1***"
],
"X-HS-Internal-Request": [
"1"
],
"Content-Length": [
"913"
],
"X-Real-IP": [
"1***"
],
"Content-Type": [
"multipart/form-data; boundary=\"556b036f-5eb0-4ec9-b41d-40df2ee79df3\""
],
"x-request-id": [
"6899b906-ce85-455a-9d64-d63406738049"
],
"cf-worker": [
"hubspot.com"
],
"CF-Ray": [
"82cb64ada28f169a-SJC"
],
"CF-IPCountry": [
"US"
],
"X-Forwarded-Proto": [
"https"
],
"Connection": [
"close"
],
"X-Request-Start": [
"1701098825.913"
],
"X-HS-Internal-User-Request": [
"0"
],
"Host": [
"api.hubspot.com"
],
"CF-Visitor": [
"{\"scheme\":\"https\"}"
],
"X-HS-User-Request": [
"0"
],
"CF-EW-Via": [
"15"
],
"X-Forwarded-Port": [
"443"
],
"X-Amzn-Trace-Id": [
"Root=1-6564b549-5795de530b252eec35288a92"
],
"X-Forwarded-For": [
"1****"
],
"x-envoy-expected-rq-timeout-ms": [
"60000"
],
"X-Scheme": [
"https"
]
}

 

Request Body:

--556b036f-5eb0-4ec9-b41d-40df2ee79df3
Content-Disposition: form-data; name="importRequest"

{
"name":"Batch_20231127_N",
"files":{
"fileFormat":"CSV",
"dateFormat":"YEAR_MONTH_DAY",
"fileImportPage":{
"hasHeader":true,
"columnMappings":[
{
"idColumnType":null,
"columnName":"firstName",
"propertyName":"firstname",
"columnObjectTypeId":"0-1"
},
{
"idColumnType":null,
"columnName":"lastName",
"propertyName":"lastname",
"columnObjectTypeId":"0-1"
},
{
"idColumnType":null,
"columnName":"email",
"propertyName":"email",
"columnObjectTypeId":"0-1"
}
]
},
"fileName":"Batch_20231127_N.csv"
}
}
--556b036f-5eb0-4ec9-b41d-40df2ee79df3
Content-Disposition: form-data; name="files"; filename="/E:/itAutomation/Hubspot/ToHubspot/New/Batch_20231127_N.csv"
Content-Type: text/csv

firstName,lastName,email
Joe,Smith,jsmith99901@gmail.com

--556b036f-5eb0-4ec9-b41d-40df2ee79df3--

 

Response Header:

{
"Content-Type": [
"{\"type\":\"application\",\"subtype\":\"json\",\"parameters\":{\"charset\":\"UTF-8\"},\"wildcardType\":false,\"wildcardSubtype\":false}"
],
"X-HubSpot-RateLimit-Daily": [
"500000"
],
"X-HubSpot-RateLimit-Daily-Remaining": [
"499997"
],
"X-HubSpot-RateLimit-Interval-Milliseconds": [
"10000"
],
"X-HubSpot-RateLimit-Remaining": [
"149"
],
"X-HubSpot-RateLimit-Max": [
"150"
],
"X-HubSpot-RateLimit-Secondly": [
"15"
],
"X-HubSpot-RateLimit-Secondly-Remaining": [
"14"
]
}

 

Response Body:

{"status":"error","message":"Unable to process JSON","correlationId":"6899b906-ce85-455a-9d64-d63406738049"}

 

 

1 Reply 1
IVallejo
HubSpot Employee
HubSpot Employee

Contacts Build Import - multipart - Unable to process JSON error

Hello team, I would greatly appreciate any suggestions or recommendations you may have on this matter. Thank you in advance for your assistance.

0 Upvotes