Search code examples
pythongmail-apigoogle-apis-explorer

Modify message label Python GMAIL API


I'm trying to send a post request using the Gmail API. However, I could not find in the documentation the name of the parameter I have to use to send the data.

For example, below is a sample of the code I'm using:

post_data = {
  "addLabelIds": [
    "123456789"
  ]
}

service = build('gmail', 'v1', credentials=credentials)
result = service.users().messages().modify(userId=user_id, id=message_id).execute()

Any guidance would be appreciated, thank you


Solution

  • You need to add the request body as a parameter when calling modify, like this:

    result = service.users().messages().modify(userId=user_id, id=message_id, body=post_data).execute()
    

    Reference: