Error while creating service account in GCP via SDK

Viewed 4437

I have been using Google's SDKs to perform API calls such as creating a service account, creating service account keys, get the storage buckets, etc.. Recently I'm unable to create a service account due to the below error.

Request:

curl --location --request POST 'https://iam.googleapis.com/v1/projects/myproject/serviceAccounts' \
--header 'Authorization: Bearer <<token>>' \
--header 'Accept-Encoding: gzip' \
--header 'User-Agent: my test Google-API-Java-Client'
   c.g.a.c.g.j.GoogleJsonResponseException: 404 Not Found
   {
     "code" : 404,
     "errors" : [ {
     "domain" : "global",
     "message" : "Not found; Gaia id not found for email xxxxx@myproject.iam.gserviceaccount.com",
    "reason" : "notFound"
  } ],
  "message" : "Not found; Gaia id not found for email xxxxx@myproject.iam.gserviceaccount.com",
  "status" : "NOT_FOUND"
}

Why would I require Gaia id while creating service account? Where can I find this id? Any help is appreciated!!

2 Answers

Did you ever remove the service account 'xxxxx@myproject.iam.gserviceaccount.com' which should be the default service account for IAM API, you can recover it within the 30days after the deletion. or just disable it and re-enable it , will recreate the default service account for you. Let me know if it resolved the issue.

It seems that your request needs to have a body

The request body contains data with the following structure:

{
  "accountId": string,
  "serviceAccount": {
    object (ServiceAccount)
  }
}

And it is missing in your command.

You can obtain more information in this documentation.

In your case it should be something like:

curl --request POST \
  'https://iam.googleapis.com/v1/projects/my-little-project/serviceAccounts?key=[YOUR_API_KEY]' \
  --header 'Authorization: Bearer [YOUR_ACCESS_TOKEN]' \
  --header 'Accept: application/json' \
  --header 'Content-Type: application/json' \
  --data '{"accountId":"sa-test","serviceAccount":{"description":"sa-description-test","displayName":"sa-display-testonly"}}' \
  --compressed

You can test this API directly in the following link

enter image description here

Also, I have found a similar error, in this stackoverflow case according to this answer this error could be generated if the APIs are not enabled.

Related