Karthik S
Karthik S

Reputation: 13

Google Cloud Platform Cloud Run: Get Services Using the REST API

I am trying to list all Google Cloud Platform (GCP) Run services for a project $GCP_PROJECT_NAME using the namespaces.services.list REST method (more on that method here).

However, when I replace {endpoint} with asia-east1-run.googleapis.com and {parent} with $GCP_PROJECT_NAME:

curl \
--request GET "https://asia-east1-run.googleapis.com/apis/serving.knative.dev/v1/$GCP_PROJECT_NAME/services" \
--header "Authorization: Bearer $(gcloud auth print-access-token)"

#=>

<!DOCTYPE html>
<html lang=en>
  . . .
  <title>Error 404 (Not Found)!!1</title>
  . . .
  <p><b>404.</b> <ins>That’s an error.</ins>
  <p>The requested URL <code>/apis/serving.knative.dev/v1/$GCP_PROJECT_NAME/services</code> was not found on this server.  <ins>That’s all we know.</ins>

I get a 404. I have also tried the GCP project number instead of the project name with no luck.

Upvotes: 1

Views: 1055

Answers (1)

Rafael Lemos
Rafael Lemos

Reputation: 5819

If you check the documentation that you share on the question you will see that the {parent} is:

The namespace from which the services should be listed. For Cloud Run (fully managed), replace {namespace_id} with the project ID or number. It takes the form namespaces/{namespace_id}.

So the problem in your URL is that you are replacing {parent} for you {projectID} when in fact you should be replacing by namespace/{projectID}.

Also, an obvious thing but might as well say it, do not copy https:// while adding the https://asia-east1-run.googleapis.com endpoint since the https:// is already contained in the URL template.

Try it out and let me know if this solves the issue.

Upvotes: 1

Related Questions