I am looking for an advice regarding Google Firestore REST API
I am trying to update the document but keep the data that are not updated (https://cloud.google.com/firestore/docs/reference/rest/v1beta1/projects.databases.documents/patch)
I have a document in "message" collection, the document contains following fields: "timestamp", "message" and "user".
If I do the PATCH request to update the "message" field, then the "timestamp" and "user" fields are removed.
There is "Query Parameter" "updateMask" to preven this. The parameter is type of object (DocumentMask). The DocumentMask object looks like this in documentation:
{
"fieldPaths": [
string
],
}
There is no example how such a HTTP request should look like.
If I build to request to look like this
PATCH https://firestore.googleapis.com/v1beta1/projects/{projectId}/databases/{databaseId}/documents/messages/someid?updateMask={"fieldPaths":["message"]}
The request body contains desired Document
This request will fail on 400, that the parameter with name "updateMask" is unabled to bind...
How can I create such a request with PHP (Guzzle HTTP client)?
You can use query parameters to control what data is returned in endpoint responses. The sections below describe query parameters that you can use to control the set of items and properties in responses, and the order of the items returned.
API parameters are the variable parts of a resource. They determine the type of action you want to take on the resource. Each parameter has a name, value type ad optional description. Whenever you want to build a REST API, you have to decide which parameters should be present in the API endpoint.
REFERENCE DATA TYPE IS ONE OF THE MANY DATA TYPES OF CLOUD FIRESTORE . THIS DATA TYPE ACTS LIKE FOREIGNKEY EVEN THOUGH IT IS NOT ACTUALLY A FOREIGNKEY . THE MAIN ADVANTAGE OF USING IT IS TO REFER A CERTAIN DOCUMENT TO ANOTHER DOCUMENT .
Number values are saved as strings in firestore.
Each patched field needs to be included as an individual parameter in the query string.
You can use this format for your url :
https://firestore.googleapis.com/v1beta1/projects/<YOUR PROJECT>/databases/(default)/documents/messages/someid?updateMask.fieldPaths=message&updateMask.fieldPaths=<another_field_to_update>&updateMask.fieldPaths=<and_so_on>
Fields omitted from the field mask are unchanged, regardless if they are included in the request body Document.
You can use the Google REST API explorer to generate pre-defined URL with Query Parameters and Body from us user friendly interface:
https://developers.google.com/apis-explorer/
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