aashrayagarwal
aashrayagarwal

Reputation: 61

Gmail Forwarding api says forbidden

I was going through the api doc for setting forwarding address via gmail Apis https://developers.google.com/gmail/api/reference/rest/v1/users.settings.forwardingAddresses/create

I am getting the following error when trying to access this api.

    {
  "code" : 403,
  "errors" : [ {
    "domain" : "global",
    "message" : "Access restricted to service accounts that have been delegated domain-wide authority",
    "reason" : "forbidden"
  } ],
  "message" : "Access restricted to service accounts that have been delegated domain-wide authority",
  "status" : "PERMISSION_DENIED"
}

If there is a way to access this api? Few other doubts I have:

  1. Can this be used for any personal @gmail.com accounts?
  2. Can this be also used for any gsuite domains like @example.com?

Upvotes: 2

Views: 554

Answers (1)

iansedano
iansedano

Reputation: 6481

This is not possible

At least for accounts outside a domain that you administrate

If I understand correctly, you wish to make an app that will ask for a users permission to allow your app to set up email forwarding for them via the API.

The listing in the docs for the scope: https://www.googleapis.com/auth/gmail.settings.sharing which is required for that endpoint says:

Operations guarded by this scope are restricted to administrative use only. They are only available to Google Workspace customers using a service account with domain-wide delegation.

This is as much as security measure as anything. Which means that what you are trying to do is not possible, unless it was for members of your domain only.

It will not work for gmail accounts or other domains. You need to authorise it properly.

If you wanted to get it working for your domain, your first step needs to be getting a service account working, this is a good starting point.

References

Upvotes: 1

Related Questions