Need curl command to get Spanner list of databases

I am using the Google Spanner emulator within a Docker container using ports 9010 (GRpc)/9020 (REST API).

I need assistance translating the REST API URLs into actual URLs I can test with curl.

My simple question at this time is how to use the following documented URL to get a list of databases:

Method: projects.instances.databases.operations.list
HTTP request
GET https://spanner.googleapis.com/v1/{name=projects/*/instances/*/databases/*/operations}

As shown on this documentation page:
https://cloud.google.com/spanner/docs/reference/rest/v1/projects.instances.databases.operations/list

I have tried the following curl command:
curl -X GET http://localhost:9020/v1/projects/test-project1/instances/test-instance1/databases/list

And I consistently get the error:
Error: {"code": 13, "message": "failed to marshal error message"}%

I have also tried using the -H curl option to send headers - with the same result.

Once I understand how to translate the documented URL into a working curl command, I can then use the REST API in my Test Harness GUI application.

I know that the Emulator instance is working, based upon using the gcloud commands:

gcloud spanner databases list --instance test-instance1
Result:
NAME STATE VERSION_RETENTION_PERIOD EARLIEST_VERSION_TIME KMS_KEY_NAME
test-database1 READY

1 2 495
2 REPLIES 2

Hi @dsimpson_dcsi,

Welcome to Google Cloud Community!

The URL you're using in your curl command is incorrect. The correct URL to get a list of databases is:

GET https://spanner.googleapis.com/v1/projects/<project-id>/instances/<instance-id>/databases

In your case, you should use the project ID and instance ID you're using in your gcloud command:

curl -X GET https://spanner.googleapis.com/v1/projects/test-project1/instances/test-instance1/databases

You'll also need to provide authentication credentials in order to use the Google Spanner API. The easiest way to do this is to use a JSON key file for a service account that has the necessary permissions to access the API. You can then use the -H option in curl to set the authorization header to use this key file:

curl -X GET -H "Authorization: Bearer $(gcloud auth application-default print-access-token)" https://spanner.googleapis.com/v1/projects/test-project1/instances/test-instance1/databases

Also since you are using emulator the url should be curl -X GET http://localhost:9020/v1/projects/test-project1/instances/test-instance1/databases

In this case you don't need to pass the authorization header as emulator doesn't require it.

Thank you!

Thanks for the reply, but when using the emulator with that last example you listed, I still get the same error:

Result: {"code": 13, "message": "failed to marshal error message"}%

The gcloud commands still work perfectly.

Any additional ideas?