Use the Cloud Firestore REST API

While the easiest way to use Cloud Firestore is to use one of the native client libraries, there are some situations when it is useful to call the REST API directly.

The REST API can be helpful for the following use cases:

  • Accessing Cloud Firestore from a resource-constrained environment, such as an internet of things (IoT) device, where running a complete client library is not possible.
  • Automating database administration or retrieving detailed database metadata.

If you are using a gRPC-supported language, consider using the RPC API rather than the REST API.

Authorization

You can generate an access_token for the Cloud Firestore REST API by using a service account with a Google API Client Library or by manually following the steps in Using OAuth 2.0 for Server to Server Applications.

This token must have the following scope, which will grant it full read/write access to Cloud Firestore:

  • https://www.googleapis.com/auth/datastore

After you obtain this token, pass it to the Cloud Firestore endpoints as an Authorization header set to Bearer {YOUR_TOKEN}.

Making REST calls

All REST API endpoints exist under the base URL https://firestore.googleapis.com/v1beta1/.

To create a path to a document with the ID LA in the collection cities under the project YOUR_PROJECT_ID you would use the following structure.

/projects/YOUR_PROJECT_ID/databases/(default)/documents/cities/LA

To interact with this path, combine it with the base API URL.

https://firestore.googleapis.com/v1beta1/projects/YOUR_PROJECT_ID/databases/(default)/documents/cities/LA

The best way to begin experimenting with the REST API is to use the API Explorer, which will automatically generate tokens and allow you to easily examine the API.

Methods

Below are brief descriptions of the two most important method groups. For a complete list, see the REST API reference or use the API Explorer.

v1beta1.projects.databases.documents

Perform CRUD operations on documents, similar to those outlined in the add data or get data guides.

v1beta1.projects.databases.indexes

Perform actions on indexes such as creating new indexes, disabling an existing index, or listing all current indexes. Useful for automating data structure migrations or synchronizing indexes between projects.

Also enables retrieval of document metadata, such as the list of all fields and subcollections for a given document.

Send feedback about...

Need help? Visit our support page.