1

I am using the Gmail API to import messages, and I have noticed the following issue. Currently I am doing a POST to this url:

https://www.googleapis.com/gmail/v1/users/me/messages?uploadType=multipart

The following http headers are set:

Content-Length: <n>
Content-Type: application/json

The posted json data looks like this:

{
"labelIds": ["Label_154"],
"raw": "RnJvbTo..."
}

(the raw data of course is a much larger based64 encoded RFC-822 message)

This works but for one customer they are getting http 413 errors on some messages, which I believe means that the message is too large. I have not yet found out how big the actual message is. I have seen some documentation that says I should use this url instead:

https://www.googleapis.com/upload/gmail/v1/users/me/messages?uploadType=multipart

But then the API complains that json is not supported, I should use Content-Type message/rfc822. I was hoping to continue to use json and raw encoded data so I don't have to make substantial changes to my code. Can you tell me what the actual message size limit is for this method, and is there a way I can go up to the full 35mb limit using a different endpoint?

Jeff McKay
  • 295
  • 1
  • 3
  • 11

1 Answers1

1

For anything larger than a few MB it's best to use the media (/upload) path. Yes, that only accepts email messages (message/rfc822 payload). Hopefully shouldn't be too difficult to change code. Since you already have to have a base64(message/rfc822) to send to the existing JSON endpoint, you can just stop doing the base64 of the message and then wrapping it in JSON.

If you use the /upload endpoint you'll be able to send messages all the way up to the max gmail message size (25MB, which after base64 encoding may be as much as 34MB).

Eric D
  • 6,901
  • 1
  • 15
  • 26
  • Thanks. How would I specify which label to assign the message to, as I do now with the json "LabelIds" field? – Jeff McKay Jul 21 '15 at 17:43
  • 2
    I believe I have this working now...I set the top level Content-Type to multipart/related, then include a single message part, of Content-Type application/json, and set its value to the json part I already created. – Jeff McKay Jul 21 '15 at 18:56