Reputation: 5557
I'm trying to submit a POST
reqeust to Firebase using the REST API
. Following the API, I created the following JSON which I submit as the body of my request:
"'{\"senderId\":\"CBPA9tdrNyc1Y3AxSb8rkZjDJxh2\",\"senderName\":\"John\",\"text\":\"Hello its me\"}'"
This is how my data structure looks:
However, after submitting my request, instead of creating an entry similar to the one above, the whole string gets added as a single entry as seen below:
How can I fix this?
This is the curl request suggested by the Firebase Documentation:
curl -X POST -d '{"user_id" : "jack", "text" : "Ahoy!"}' \
'https://[PROJECT_ID].firebaseio.com/message_list.json'
I am currently testing this using https://www.hurl.it/ with the following request:
Upvotes: 1
Views: 9664
Reputation: 599541
If you carefully compare your JSON to the one from the documentation, you have an extra "
before and after the data. This means that you're posting one big string, instead of a JSON object.
The solution is to remove the extra double quotes from start and end. That also means that you no longer needs to escape the double quotes inside the JSON:
'{"senderId":"CBPA9tdrNyc1Y3AxSb8rkZjDJxh2","senderName":"John","text":"Hello its me"}'
The single quotes are needed if the tool you use to post tries to parse the JSON as a single string. If it doesn't (hint: hurl.it doesn't), you should post the body without the surrounding '
too.
Request:
Response:
Upvotes: 3