Upload an attachment
POST
/drafts/{id}/attachmentsAdds a file to a draft. This call reserves its place and returns a URL to upload it to; the file goes straight to storage, never through the API.
Needs the permissionattachments:create
An upload takes three steps: this call; a PUT of the file to uploadUrl, with the same Content-Type as the mimeType you gave; then Confirm an upload. The URL works for ten minutes.
size is checked before you upload anything, so a file that’s too big is refused now rather than after it has gone up. A file can be up to 25 MB, and a message can have 25 of them.
Confirm every upload
Until it’s confirmed, the file is only a reservation. A draft sent with an unconfirmed file doesn’t go without it: the send fails, and Get a message says which file never arrived.
Path parameters
idstringrequired- The draft.
Body
filenamestringrequired- The name recipients will see.
sizenumberrequired- Its size in bytes.
mimeTypestringoptional- Such as
application/pdf.
Returns
attachmentIdstring- The file. Confirm it with this id once it’s uploaded.
uploadUrlstring- Where to
PUTthe file.
Errors
400filename_required- There’s no
filename. 400size_requiredsizeisn’t a number of bytes above zero.400attachment_rejected- The file is too big, the draft has 25 already, or it was refused for a reason the message gives.
401invalid_key- The key is wrong, expired or revoked. With no Authorization header at all, the code is
missing_credentials. 403missing_scope- The key doesn’t have
attachments:create. TheX-Required-Scopeheader names what’s missing. 404not_found- There’s no such draft, or the key’s owner can’t see it.
429rate_limited- More than 120 requests a minute from this key. Wait for
Retry-Afterseconds.