Hello I am looking to write a script which uses firebase firestore and writes some json to a specific collection in firestore. I have done this with the realtime db but firestore is a tad different below is my Realtime db snippet that works.
curl -X POST \
-d '{"param1":"'"$1"'", "param2":"'"$2"'"}' \
https://xxxx.firebaseio.com/xxxx.json?
Thanks for the help
After Reading the documentation I got to this
curl -X POST \
-H "Content-Type: application/json" \
-d'{
"fields": {
"Field1": {
"stringValue": "'"$var1"'"
},
"Field2": {
"stringValue": "'"$var2"'"
},
"Field3": {
"stringValue": "$var3"
}
}
}'\"https://firestore.googleapis.com/v1beta1/projects/**PROJECT_ID**/databases/(default)/documents/**COLLECTION_ID**?&key=(YOUR API KEY)"
The accepted answer helped me, but it took me a long time to figure out how can I use data types other than stringValues, so I am adding this answer hoping someone finds this helpful in the future.
curl -X POST \
-H "Content-Type: application/json" \
-d' {
"fields": {
"Field1": {
"arrayValue": {
"values": [{
"mapValue": {
"fields": {
"key1": {
"stringValue": "val1"
},
"key2": {
"stringValue": "val2"
}
}
}
}]
}
},
"Field2": {
"integerValue": <intValue>
},
"Field3": {
"stringValue": "var3"
}
}
}'\"https://firestore.googleapis.com/v1beta1/projects/**PROJECT_ID**/databases/(default)/documents/**COLLECTION_ID**?&key=<YOUR WEB API KEY>"
Use this for reference.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With