APIs & Integrations

DouglasAcosta
Participant

Invalid JSON Input

I am constantly receiving errors from the "new event" API due to accented or special characters (most of them spanish accents and punctuation) that are present in the event extraData field.

I would like to know why these characters cause errors?
Is there any setting for my app that could accept accented characters and punctuation marks in the JSON object?

Best regards

Douglas Acosta

Here is a sample error messaje

Invoke-WebRequest : {"status":"error","message":"Invalid input JSON on line 1, column 440: Invalid UTF-8 middle byte 0x61\n at [Source:
java.io.ByteArrayInputStream@7e553fc9; line: 1, column:
452]","correlationId":"20d75edc-8dbf-4500-87fa-d817caf557df","requestId":"ecab85ffeb0f4b838e75470fea949912"}
At E:\BI\PROJECTS\SSIS\MT_DW\MT_DW\EC_LiveChatToHubspot.ps1:211 char:13
+             Invoke-WebRequest -uri $url -Body $new_event -Headers $he ...
+             ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : InvalidOperation: (System.Net.HttpWebRequest:HttpWebRequest) [Invoke-WebRequest], WebException
    + FullyQualifiedErrorId : WebCmdletWebResponseException,Microsoft.PowerShell.Commands.InvokeWebRequestCommand
0 Upvotes
5 Replies 5
DouglasAcosta
Participant

Invalid JSON Input

Hi Connor, sure the app id is 184462 and I think the portal id is this 4187609 (not quite sure)

0 Upvotes
cbarley
HubSpot Alumni
HubSpot Alumni

Invalid JSON Input

Cool no worries, i'll take a look through the logs of the app to see which requests are failing so don't worry about the portal id. I'll reach back out when I have more info!

0 Upvotes
cbarley
HubSpot Alumni
HubSpot Alumni

Invalid JSON Input

Hi @Douglas, thanks for that extra info, very helpful. I was just looking more for a raw request to HubSpot that you're making so that I can try to reproduce the issue, but your response above should suffice. Can you reply with your App ID, and the HubID to the portal where this request is failing?

0 Upvotes
DouglasAcosta
Participant

Invalid JSON Input

Hi Connor

I am encoding each string as UTF-8 but keep receiving error messages when accented characters are present.

Here is a sample event I am sending, notice the "ú" character

{"id":"P8KQIHYOTW-1","email":"algo@algo.com","eventTypeId":"382537","MT_ChatID":"P8KQIHYOTW-1","extraData":{"urlinicio":"https://www.mashpilodge.com/es/","fecha":"14/05/2018","chatLines":[{"autor":"Carmen Elena Velasco","hora":"14:51","mensaje":"Hello, would you like to talk about our products?"},{"autor":"Paúl","hora":"....

By now I am replacing all of these characters with another character but it is not the ideal solution. Do you think we can work this out? what else would you need to identify the error.

The environment I am using is:
The data comes from a SQLServer 2017 (collation SQL_Latin1_General_CP1_CI_AS, codepage 1252, locale 1033)

I am using powershell as my interface to call Hubspot APIs
using powershell I am stripping all control characters
$ControlCharacters = "r|n|`t|\"

and I am translating the data from sqlserver *codepage 1252 to UTF-8"
[Text.Encoding]::UTF8.GetString([Text.Encoding]::GetEncoding(1252).GetBytes($sourcedata))

UPDATE: I tried with different code pages: 65001 (unicode) also
[Text.Encoding]::UTF8.GetString([Text.Encoding]::GetEncoding(65001).GetBytes($sourcedata))

0 Upvotes
cbarley
HubSpot Alumni
HubSpot Alumni

Invalid JSON Input

Hi @Douglas, happy to help here! Are you using the Timeline API here: https://developers.hubspot.com/docs/methods/timeline/timeline-overview#extra-data to make your requests? If so, can I see an example body for a PUT request that you're making with the endpoint? I'll be able to clarify with my team which characters are supported, but if it's included in the UTF-8 character set, then it should be okay I believe.

0 Upvotes