API - Foreign Languages

SOLVE
rarayav
Participant

Hi,
Whenever we try to Create/Update a contact using the API to a contact whois name/last name is in foreign language, we get a 400 Bad Request error.

How should we encode that? or deal with the issue?

 

I try with UTF8Encoding C#

Example: Villalón

 

Thanks!

0 Upvotes
1 Accepted solution

Accepted Solutions
WendyGoh
Solution
HubSpot Employee

Hey @rarayav,

 

I tried using the v3 endpoint 

 

POST crm/v3/objects/contacts?hapikey={{myhapikey}}

 

{
  "properties": {
    "lastname": "Villalón",
"firstname": "18test"
  }
}

and I'm seeing that a contact with the last name Villalón was created successfully:

 

Screen Shot 2020-05-18 at 11.29.08 AM.png

 

Could you try removing the encoding charset=utf-8? 

 

View solution in original post

0 Upvotes
4 Replies 4
WendyGoh
HubSpot Employee

Hey @rarayav,

 

It doesn't appear that HubSpot does encoding on our end. I made a simple POST request to this endpoint

 

POST https://api.hubspot.com/contacts/v1/contact?hapikey={{my hapikey}}

 

with the following POST body

 

Screen Shot 2020-05-15 at 10.32.33 AM.png

 

and I'm able to see the contact name shows up just fine:

 

Screen Shot 2020-05-15 at 10.32.51 AM.png

0 Upvotes
rarayav
Participant
Could it be that the problem is the api version I am using?
My code:
 
string url = "https://api.hubapi.com/crm/v3/objects/contacts?hapikey={MyApiKey}";
WebRequest myReq = WebRequest.Create(url);
myReq.Method = "POST";
myReq.ContentType = "application/json; charset=utf-8";
string data = "{\"properties\":{ \"lastname\": \"Villalón\" } }";
 
When I remove the accent mark it works, but that doesn't work for me
0 Upvotes
WendyGoh
Solution
HubSpot Employee

Hey @rarayav,

 

I tried using the v3 endpoint 

 

POST crm/v3/objects/contacts?hapikey={{myhapikey}}

 

{
  "properties": {
    "lastname": "Villalón",
"firstname": "18test"
  }
}

and I'm seeing that a contact with the last name Villalón was created successfully:

 

Screen Shot 2020-05-18 at 11.29.08 AM.png

 

Could you try removing the encoding charset=utf-8? 

 

View solution in original post

0 Upvotes
rarayav
Participant

the following worked

(C#)

 

HttpWebRequest request = (HttpWebRequest)WebRequest.Create("https://api.hubapi.com/crm/v3/objects/contacts?hapikey=XXXXXX");
request.Method = "POST";
request.Accept = "application/json";
request.ContentType = "application/json";

using (var streamWriter = new StreamWriter(request.GetRequestStream()))
{
string data = "{\"properties\": {\"lastname\": \"Villalón\",\"firstname\": \"19test\", \"hubspot_owner_id\": \"47664540\"}} ";

streamWriter.Write(data);
}

var response = request.GetResponse();
string text;

using (var sr = new StreamReader(response.GetResponseStream()))
{
text = sr.ReadToEnd();
}
return text;

 

 

thank you very much for your help