Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to Query Drafts by Message ID?

Tags:

gmail-api

We have a use case where we have the message ID of a draft and want to get the immutable draft ID. Currently the only way to do this is to list all the drafts and iterate through them until we find a matching message id.

Would it be possible to add functionality to query the drafts by message ID? Alternatively, if the draft ID could be included with a Get message by ID call then that could work to.

like image 998
aloo Avatar asked Oct 19 '25 02:10

aloo


1 Answers

This isn't possible now and seems like an odd edge case. What's the downside of iterating all drafts.list? I imagine 99% there's < 50 drafts so it should be relatively cheap/efficient.

If there are a lot of drafts or some other reason you don't want to look at all of the drafts the best workaround I'd say is:

  • messages.get(msgid_of_draft) to get the rfc822 "Message-Id" header
  • drafts.list(q="rfc822msgid:") to get a draft id, this is an indexed search should be fast and only return one thing
  • drafts.get(draft_id)
  • like image 162
    Eric D Avatar answered Oct 21 '25 23:10

    Eric D