5
votes

Per this SO thread I should be able to go directly to a Gmail draft message, created using the Gmail REST API, using a hyperlink formatted like:

https://mail.google.com/mail/#drafts?compose={ThreadId}

However, it's not working. The thread ID I get as a response to my Gmail API call does not open the draft message created. What's really strange is when I open the draft from Gmail (that I created using the API) the thread ID DOES match for a split second in the URL then changes.

How does one open directly to a draft message utilizing the message.threadId? I'd like it to be a pop out message as well and should be possible per this thread but getting the draft to show at all is my first priority.

Gmail id hyperlink to draft

2
Gmail devs: Is there no way to open a draft message in a browser? Per the API documentation: developers.google.com/gmail/api/v1/reference/users/drafts/send I should be able to use the "immutable ID of the draft" but how can I do that if it changes? Is this a bug in the API?michaelf
I haven't received an answer to my initial question, so I'll rephrase it: What is the purpose of returning the draft's Thread ID if it can't be used? It's returned from the API call in JSON format. Is there a use for it? If not, seems like unnecessary overhead. Even if the thread ID change every time a draft is open/edited, I'm just looking for a way to open it initially, immediately after I create it using the Gmail API. Thanks in advance for a solution or explanation.michaelf
This works: "https://mail.google.com/mail/ca/u/0/#drafts/" + draftResponse.getMessage().getThreadId() Credits: @Chris Wood from this SO question stackoverflow.com/q/50124112/455449 (see comment below)Petr Kozelka
... and, the purpose of threadId is quite different - it binds together all individual messages that are related in a thread (supported by the UI); by observation, it seems to equal messageId of the first message in a thread.Petr Kozelka

2 Answers

2
votes

The thread id/message id of a draft are not stable. That is, they change everytime the draft is edited/saved. The only thing that is stable is the draft id, however, this is not available in the gmail ui.

2
votes

The Users.drafts.create API call returns a User.drafts resource containing the draft ID. The draft ID is not the same thing as a message or thread ID, but you can then call Users.drafts.get or Users.drafts.list, both of which will let you correlate the draft ID to a thread ID and message ID.