I am new to Google API and currently working on adding forwarding email address using code. The code is as below.
credentials = get_credentials(request.data['code'], request.data['state'])
service = build_gmail_service(credentials)
address = {'forwardingEmail': 'abcd1234@mydomain.com'}
result = service.users().settings().forwardingAddresses().create(userId='me', body=address).execute()
I am able to build google service using the above code but when executing the last line which setting forwarding email address I am getting below error.
googleapiclient.errors.HttpError: <HttpError 403 when requesting https://www.googleapis.com/gmail/v1/users/me/settings/forwardingAddresses?alt=json returned "Access restricted to service accounts that have been delegated domain-wide authority">
I have searching for a solution for a day but not able to solve it so please let me know if any other have faced same issue and solved it.
Gsuite domain wise delegation image:
Thanks.