Professional Documents
Culture Documents
There’s a single ‘ embedded into single quotes in the values of the company key
The cURL API call generated for the above query is as follows:
curl -X 'POST'
'https://api-gdn.paas.macrometa.io/_fabric/_system/_api/query'
-H 'accept: application/json'
-H 'Content-Type: application/json'
-H 'Authorization: bearer xxxx'
-d '{
"query": "INSERT{'\''name'\'' : '\''Julie'\'', '\''company'\'' : '\''Julie'\''s pizza'\'', '\''_key'\'' : '\''Julie'\''}
INTO testcollection"
}'
{
"code": 400,
"error": true,
"errorMessage": "syntax error, unexpected identifier, expecting } near 's pizza', '_key' : 'Julie'}
INTO...' at position 1:45",
"errorNum": 1501
}
The error message explains the error encountered by the compiler while trying to execute the
query.
As iterated before, the error is caused by the single quotation mark embedded into single
quotation marks.
Therefore, it is recommended to use normalization , let’s take a look at the corrected query :
Assuming the value to enter is as follows : “I'm planning to write a book someday.”
Normalized string would be : \"I'm planning to write a book someday.\"
-----------------------------------------------------------------------------------------------------------------------------
Now let’s execute the new normalized query, which will require the following API call:
curl -X 'POST' \
'https://api-gdn.paas.macrometa.io/_fabric/_system/_api/query'
-H 'accept: application/json'
-H 'Content-Type: application/json'
-H 'Authorization: bearer xxxx' \
-d '{
"query": " INSERT{'\''name'\'' : '\''Julie'\'', '\''company'\'' : \"Julie'\''s Pizza\", '\''_key'\'' : '\''Julie'\''}
INTO testcollection "
}'
"value": "Julie's Pizza" in the response body means the apostrophe was added correctly.
Alternatively, you can also replace a single quotation mark with <\u0027> also known as “by
unicode encoded”:
API call:
The “value” recorded in the response body is "Julie's Pizza" which is the correct
representation.