I'm trying to set a user's signature via Python through the Gmail API. When doing it with my own admin user it works fine but when trying it with a different email address I'm getting this error:
googleapiclient.errors.HttpError: <HttpError 404 when requesting https://gmail.googleapis.com/gmail/v1/users/me/settings/sendAs/test_email@example.com?alt=json returned "Requested entity was not found.". Details: "[{'message': 'Requested entity was not found.', 'domain': 'global', 'reason': 'notFound'}]">
This is my Python code:
def main():
SCOPES = 'https://www.googleapis.com/auth/gmail.settings.basic'
# Check if token.pickle exists
if os.path.exists(client_token_pickle):
creds = Credentials.from_authorized_user_file(client_token_pickle, SCOPES)
# If there are no (valid) credentials available, let the user log in.
if not creds or not creds.valid:
if creds and creds.expired and creds.refresh_token:
creds.refresh(Request())
else:
flow = InstalledAppFlow.from_client_secrets_file(client_oauth_file, scopes)
creds = flow.run_local_server(port=8080)
# Save the credentials for the next run
with open(client_token_pickle, "w") as token:
token.write(creds.to_json())
service = build('gmail', 'v1', credentials=creds)
signature = {'signature': 'lalala'}
service.users().settings().sendAs().patch(userId='me',sendAsEmail="test_email@smava.de", body=signature).execute()
With GAM it works fine so it should be possible somehow, but how? Thanks a lot for any input!