firebasegoogle-cloud-firestoregoogle-cloud-endpoints

Making a Cloud Firestore REST API call through Cloud Endpoints?


Is it possible to create a Cloud Endpoint in order to make HTTP calls to the Firestore REST API service?

The reason being to use a custom URL for the call - e.g. "https://whatever.com/api/things", instead of "https://firestore.googleapis.com/v1/projects/YOUR_PROJECT_ID/databases/(default)/documents/things".

I tried creating an Open API yaml file for this, but got an error:

User does not have permission to access services instance [firestore.googleapis.com] (or it may not exist): Caller does not have permission 'servicemanagement.services.update' on service 'firestore.googleapis.com'.

Is it even possible, or would I have to create a Cloud Function to achieve this instead?

UPDATE

Here is my yaml file:

swagger: '2.0'
info:
  title: "My API"
  description: "Returns something"
  version: 1.0.0
host: "firestore.googleapis.com"
basePath: "v1/projects/app-emojise-com/databases/(default)/documents"
schemes:
  - "https"
produces:
  - application/json
paths:
  "/foo/{fooId}":
    get:
      summary: "Returns foo"
      operationId: "foo"
      parameters:
        -
          name: fooId
          in: path
          required: true
          type: string
      responses:
        200:
          description: "OK"
          type: string
        404:
          description: "Error"
          type: string
        403:
          description: "Forbidden"
          type: string

I've tried following the example given here


Solution

  • The error you're seeing is because you're trying to upload a configuration to firestore.googleapis.com, which you do not own. This is specified in your yaml file in the "host" field. Instead, you must use a different domain name of your own.

    Endpoints is an API "control plane", it doesn't actually handle proxying requests. The operation the you're performing will only upload an API configuration to our server. You will need to actually set up some kind of service to listen for requests and forward them on to Firestore itself. We do provide an open source solution to do this, called the ESP, but this still needs to be hosted somewhere.

    In theory, Endpoints is designed to protect your own API, not run as a proxy to someone else's. As a result, It's likely that it won't work the way you want.

    I'd suggest to just build a proper API, and host this on something like Cloud Run. You might still want to use Endpoints with it.