Reputation: 322
Does anyone know how we are supposed to call the REST API to store special characters? I have tried the following methods:
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.
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.
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.
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!
Upvotes: 3
Views: 1378
Reputation: 1409
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
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.
Upvotes: 1