3

Does anyone know how we are supposed to call the REST API to store special characters? I have tried the following methods:

  • No special handling at all. I noticed Parse can handle special characters such as #@$ etc. so I figured I will give this a shot. This ends up with no luck. sample curl query is:

curl -X POST \ -H "X-Parse-Application-Id: appId" \ -H "X-Parse-REST-API-Key: apikey" \ -H "Content-Type: application/json;" \ -d '{"testString":"é"}' \ https://api.parse.com/1/classes/TestObject

This returns "{"code":107,"error":"The object contained an invalid utf8 string"}" which is sort of expected.

  • Then I thought I would add the charset header in the post call, i.e.

curl -X POST \ -H "X-Parse-Application-Id: appId" \ -H "X-Parse-REST-API-Key: apikey" \ -H "Content-Type: application/json; charset=utf-8" \ -d '{"testString":"é"}' \ https://api.parse.com/1/classes/TestObject

This returns same result as the first attempt.

  • Okay, then I tried manually encode it to UTF-8, i.e.

curl -X POST \ -H "X-Parse-Application-Id: appId" \ -H "X-Parse-REST-API-Key: apikey" \ -H "Content-Type: application/json; charset=utf-8" \ -d '{"testString":"%C3%A9"}' \ https://api.parse.com/1/classes/TestObject

Now this does create the row, however, the value is literally %C3%A9 as opposed to é. I tried taking out the charset value in the header which didn't seem to help either.

  • I noticed everything worked perfect via the data browser. So I monitor the js query to see what db is sending out. It turned out the browser is sending é for é. Then I proceed to change my curl and, tada, I got it, i.e.

curl -X POST \ -H "X-Parse-Application-Id: appId" \ -H "X-Parse-REST-API-Key: apikey" \ -H "Content-Type: application/json; charset=utf-8" \ -d '{"testString":"é"}' \ https://api.parse.com/1/classes/TestObject

Finally gave me what I wanted which is value é.

Now I am puzzled, what kind of encoding converts é into é? I got all sorts of other special foreign characters I need to handle too and I need to find a way to reliably encode them into the expected format...

Thanks in advance!

Jove Kuang
  • 322
  • 2
  • 12
  • My next question would be what kind of encoding library I should use to encode é into é... – Jove Kuang Aug 03 '13 at 07:34
  • I don't understand it well enough to provide you a solution, but for a description of the problem, look at this entry: U+00E9 é é %C3 %A9 in this Web page: http://www.i18nqa.com/debug/utf8-debug.html – ahoffer Jan 15 '14 at 18:15
  • 4
    Have a look at this question and answer: http://stackoverflow.com/questions/649480/curl-import-character-encoding-problem. My *guess* is that your terminal's character encoding is either ISO-8859-1, Windows-1252 and Parse.com expects UTF8. – ahoffer Jan 15 '14 at 20:28

1 Answers1

1

I just tried this in Terminal on OSX, without problems:

curl -X POST \ -H "X-Parse-Application-Id: appID" \ -H "X-Parse-REST-API-Key: restKey" \ -H "Content-Type: application/json;" \ -d '{"testString":"é"}' \ https://api.parse.com/1/classes/TestObject

enter image description here

The character encoding in the terminal was set to UTF-8. However, when changed to ISO-8859-1, I got the same error as you:

{"code":107,"error":"invalid utf-8 string was provided"}

So @ahoffer is probably right that you don't have utf-8 set as your terminal's character encoding.

Tom Erik Støwer
  • 1,399
  • 9
  • 19