Reputation: 1
I use Hubspot API.
I try to craete contact info. Type this code using powershell (5.1version and 7.2)
curl.exe --request POST --url "https://api.hubapi.com/crm/v3/objects/contacts?hapikey=$apiKey"
--header 'content-type: application/json' -d "{\"properties\": {\"email\":\"$email\",\"firstname\":\"$firstname\"}}"
but error
return {"status":"error","message":"Invalid input JSON on line 1, column 3: Unexpected character ('\\' (code 92)): was expecting double-quote to start field name","correlationId":"2086b3bc-abe5-4f90-a79c-213d45bb2a97"}
I try this code using single quote after -d. and then create contact info.
curl.exe --request POST --url "https://api.hubapi.com/crm/v3/objects/contacts?hapikey=$apiKey" --header 'content-type: application/json' -d '{\"properties\": {\"email\":\"[email protected]\",\"firstname\":\"k\"}}'
but I want to substitute variables. So I want to use double quote.
Upvotes: 0
Views: 255
Reputation: 1
I solved by myself.
put double-quotes and backslash between variable.
ConvertTo-Json
setting 2. to curl.exe
like this
$contactBody = @{
'"properties"' = @{
'"firstname"' = "`"$firstname`""
'"email"' = "`"$email`""
}
}
$contactBodyJson = ConvertTo-Json $contactBody
curl.exe --request POST --url "https://api.hubapi.com/crm/v3/objects/contacts?hapikey=$apiKey" --header 'content-type: application/json' -d $contactBodyJson
Upvotes: 0