App Logo
mail.google.com

Update a Gmail draft

Change the subject and/or body of an existing Gmail draft, identified by the id the drafts listing gives you. Whichever field you leave out keeps its current value; a field you pass replaces what was there rather than appending to it. The draft's current contents are read first, so asking for what it already says makes no change and says so. Gmail issues a draft a new id every time it is saved, so the id you passed in stops existing and the new one is returned — use that for any follow-up. The conversation id stays the same and is returned as the stable handle. Recipients are not touched by this script.

Input

draftId required

The draft's current id, as returned by the drafts listing. Note Gmail replaces this id on every save, so use a freshly listed one.

body optional

Replacement body text. This replaces the whole body rather than adding to it. Pass an empty string to clear it. Omit to leave the body as it is.

subject optional

Replacement subject line. Pass an empty string to clear it. Omit to leave the subject as it is.

Output

after required

What the draft said after the edit, read back from the composer.

before required

What the draft said before the edit.

changed required

Which fields were actually written. Empty when nothing needed changing.

draftId required

The draft's id AFTER the edit. Gmail mints a new one on every save, so this differs from the id passed in whenever something was written. Use this for follow-up calls.

account_used required

The Gmail account the draft was edited in, read from the session rather than assumed.

already_present required

True when the draft already said exactly what was asked for, so nothing was written.

verified_on_page required

True when the drafts listing showed the draft with the new subject — and, when the body changed, with the new body in its preview — after Gmail saved it.

threadId optional

Id of the conversation holding the draft. Unlike the draft id this survives a save, which makes it the durable handle for the same draft over time.

previousDraftId optional

The id that was passed in, which Gmail has now retired.

Start building not clicking