user3451476
user3451476

Reputation: 307

Google Pubsub API - 401 Error (The request does not have valid authentication credentials)

I am trying to connect to the Google Pubsub API with the API_KEY and I get 401 Error - Unauthorised.

The command I am using is

curl -i -H "Accept: application/json" -H "Content-Type: application/json" -H    "Content-Length: 0" -X PUT "https://pubsub.googleapis.com/v1/projects/{project}/topics/{topicName}?key={api-key}"

RESPONSE

{
"error": {
"code": 401,
"message": "The request does not have valid authentication credentials.",
"status": "UNAUTHENTICATED"
 }
}

If I do the same request using OAuth token, it succeeds

curl -i -H "Accept: application/json" -H "Content-Type: application/json" -H   "Content-Length: 0"-H "Authorization: Bearer <access_token>" -X PUT "https://pubsub.googleapis.com/v1/projects/{project}/topics/{topicName}"

RESPONSE

200 OK

{
  "name": "projects/{project}/topics/{topicName}"
}

Why is the request not working with the API key

Upvotes: 1

Views: 3700

Answers (1)

Takashi Matsuo
Takashi Matsuo

Reputation: 3436

All the Cloud Pub/Sub API calls need authentication. The API key is just for attaching the project info on the requests, not providing any authentications. That's why it's not sufficient to add the API key.

Upvotes: 3

Related Questions