How to create a draft message in existing thread with gmail API












0















Using the python google client I able to create new messages within an existing thread with id threadId as follows:



message = (service.users().messages().send(userId='me', body={'threadId': <threadId>}, media_body=message['media_body'])
.execute())


(here I'm using media_body as it supports the /upload endpoint for large attachments)



This works fine for messages, and the threadId optional parameter is documented at https://developers.google.com/gmail/api/v1/reference/users/messages/send



However I have been unsuccessful doing the same when creating new draft messages, and don't see any docs about it at https://developers.google.com/gmail/api/v1/reference/users/drafts/create



I tried adding threadId to the draft body when doing draft = service.users().drafts().create(userId=user_id, body={'threadId': <threadId>}, media_body=message_body['media_body']).execute() at the create draft stage and it simply is ignored.



I also tried adding threadId to the body at the send draft stage: message = service.users().drafts().send( userId='me', body={'id': draft_id, threadId': <threadId>}).execute() and this was also ignored.



Either way the draft message just gets created in its own, new thread.



How can I create a new draft message within an existing thread with the gmail API (and specifically with Python client)?










share|improve this question



























    0















    Using the python google client I able to create new messages within an existing thread with id threadId as follows:



    message = (service.users().messages().send(userId='me', body={'threadId': <threadId>}, media_body=message['media_body'])
    .execute())


    (here I'm using media_body as it supports the /upload endpoint for large attachments)



    This works fine for messages, and the threadId optional parameter is documented at https://developers.google.com/gmail/api/v1/reference/users/messages/send



    However I have been unsuccessful doing the same when creating new draft messages, and don't see any docs about it at https://developers.google.com/gmail/api/v1/reference/users/drafts/create



    I tried adding threadId to the draft body when doing draft = service.users().drafts().create(userId=user_id, body={'threadId': <threadId>}, media_body=message_body['media_body']).execute() at the create draft stage and it simply is ignored.



    I also tried adding threadId to the body at the send draft stage: message = service.users().drafts().send( userId='me', body={'id': draft_id, threadId': <threadId>}).execute() and this was also ignored.



    Either way the draft message just gets created in its own, new thread.



    How can I create a new draft message within an existing thread with the gmail API (and specifically with Python client)?










    share|improve this question

























      0












      0








      0








      Using the python google client I able to create new messages within an existing thread with id threadId as follows:



      message = (service.users().messages().send(userId='me', body={'threadId': <threadId>}, media_body=message['media_body'])
      .execute())


      (here I'm using media_body as it supports the /upload endpoint for large attachments)



      This works fine for messages, and the threadId optional parameter is documented at https://developers.google.com/gmail/api/v1/reference/users/messages/send



      However I have been unsuccessful doing the same when creating new draft messages, and don't see any docs about it at https://developers.google.com/gmail/api/v1/reference/users/drafts/create



      I tried adding threadId to the draft body when doing draft = service.users().drafts().create(userId=user_id, body={'threadId': <threadId>}, media_body=message_body['media_body']).execute() at the create draft stage and it simply is ignored.



      I also tried adding threadId to the body at the send draft stage: message = service.users().drafts().send( userId='me', body={'id': draft_id, threadId': <threadId>}).execute() and this was also ignored.



      Either way the draft message just gets created in its own, new thread.



      How can I create a new draft message within an existing thread with the gmail API (and specifically with Python client)?










      share|improve this question














      Using the python google client I able to create new messages within an existing thread with id threadId as follows:



      message = (service.users().messages().send(userId='me', body={'threadId': <threadId>}, media_body=message['media_body'])
      .execute())


      (here I'm using media_body as it supports the /upload endpoint for large attachments)



      This works fine for messages, and the threadId optional parameter is documented at https://developers.google.com/gmail/api/v1/reference/users/messages/send



      However I have been unsuccessful doing the same when creating new draft messages, and don't see any docs about it at https://developers.google.com/gmail/api/v1/reference/users/drafts/create



      I tried adding threadId to the draft body when doing draft = service.users().drafts().create(userId=user_id, body={'threadId': <threadId>}, media_body=message_body['media_body']).execute() at the create draft stage and it simply is ignored.



      I also tried adding threadId to the body at the send draft stage: message = service.users().drafts().send( userId='me', body={'id': draft_id, threadId': <threadId>}).execute() and this was also ignored.



      Either way the draft message just gets created in its own, new thread.



      How can I create a new draft message within an existing thread with the gmail API (and specifically with Python client)?







      python gmail-api






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      asked Nov 22 '18 at 12:28









      fpghostfpghost

      1,01711336




      1,01711336
























          1 Answer
          1






          active

          oldest

          votes


















          0














          As per documentation, a draft can be added to a thread as part of creating, updating, or sending a draft message.




          In order to be part of a thread, a message or draft must meet the following criteria:




          1. The requested threadId must be specified on the Message or
            Draft.Message you supply with your request.

          2. The References and In-Reply-To headers must be set in compliance
            with the RFC 2822 standard.

          3. The Subject headers must match.




          The documentation also states that in both examples for creating a draft and sending a message, you would simply add a threadId key paired with a thread ID to a message's metadata, the message object.






          share|improve this answer
























          • Could you add a code snippet using the python client, since as I mentioned in my post I tried adding threadId and for drafts it was simply ignored and the draft was created in a new thread (even though this worked for adding non-draft messages to threads)

            – fpghost
            Nov 24 '18 at 10:20











          Your Answer






          StackExchange.ifUsing("editor", function () {
          StackExchange.using("externalEditor", function () {
          StackExchange.using("snippets", function () {
          StackExchange.snippets.init();
          });
          });
          }, "code-snippets");

          StackExchange.ready(function() {
          var channelOptions = {
          tags: "".split(" "),
          id: "1"
          };
          initTagRenderer("".split(" "), "".split(" "), channelOptions);

          StackExchange.using("externalEditor", function() {
          // Have to fire editor after snippets, if snippets enabled
          if (StackExchange.settings.snippets.snippetsEnabled) {
          StackExchange.using("snippets", function() {
          createEditor();
          });
          }
          else {
          createEditor();
          }
          });

          function createEditor() {
          StackExchange.prepareEditor({
          heartbeatType: 'answer',
          autoActivateHeartbeat: false,
          convertImagesToLinks: true,
          noModals: true,
          showLowRepImageUploadWarning: true,
          reputationToPostImages: 10,
          bindNavPrevention: true,
          postfix: "",
          imageUploader: {
          brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
          contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
          allowUrls: true
          },
          onDemand: true,
          discardSelector: ".discard-answer"
          ,immediatelyShowMarkdownHelp:true
          });


          }
          });














          draft saved

          draft discarded


















          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53431048%2fhow-to-create-a-draft-message-in-existing-thread-with-gmail-api%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown

























          1 Answer
          1






          active

          oldest

          votes








          1 Answer
          1






          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes









          0














          As per documentation, a draft can be added to a thread as part of creating, updating, or sending a draft message.




          In order to be part of a thread, a message or draft must meet the following criteria:




          1. The requested threadId must be specified on the Message or
            Draft.Message you supply with your request.

          2. The References and In-Reply-To headers must be set in compliance
            with the RFC 2822 standard.

          3. The Subject headers must match.




          The documentation also states that in both examples for creating a draft and sending a message, you would simply add a threadId key paired with a thread ID to a message's metadata, the message object.






          share|improve this answer
























          • Could you add a code snippet using the python client, since as I mentioned in my post I tried adding threadId and for drafts it was simply ignored and the draft was created in a new thread (even though this worked for adding non-draft messages to threads)

            – fpghost
            Nov 24 '18 at 10:20
















          0














          As per documentation, a draft can be added to a thread as part of creating, updating, or sending a draft message.




          In order to be part of a thread, a message or draft must meet the following criteria:




          1. The requested threadId must be specified on the Message or
            Draft.Message you supply with your request.

          2. The References and In-Reply-To headers must be set in compliance
            with the RFC 2822 standard.

          3. The Subject headers must match.




          The documentation also states that in both examples for creating a draft and sending a message, you would simply add a threadId key paired with a thread ID to a message's metadata, the message object.






          share|improve this answer
























          • Could you add a code snippet using the python client, since as I mentioned in my post I tried adding threadId and for drafts it was simply ignored and the draft was created in a new thread (even though this worked for adding non-draft messages to threads)

            – fpghost
            Nov 24 '18 at 10:20














          0












          0








          0







          As per documentation, a draft can be added to a thread as part of creating, updating, or sending a draft message.




          In order to be part of a thread, a message or draft must meet the following criteria:




          1. The requested threadId must be specified on the Message or
            Draft.Message you supply with your request.

          2. The References and In-Reply-To headers must be set in compliance
            with the RFC 2822 standard.

          3. The Subject headers must match.




          The documentation also states that in both examples for creating a draft and sending a message, you would simply add a threadId key paired with a thread ID to a message's metadata, the message object.






          share|improve this answer













          As per documentation, a draft can be added to a thread as part of creating, updating, or sending a draft message.




          In order to be part of a thread, a message or draft must meet the following criteria:




          1. The requested threadId must be specified on the Message or
            Draft.Message you supply with your request.

          2. The References and In-Reply-To headers must be set in compliance
            with the RFC 2822 standard.

          3. The Subject headers must match.




          The documentation also states that in both examples for creating a draft and sending a message, you would simply add a threadId key paired with a thread ID to a message's metadata, the message object.







          share|improve this answer












          share|improve this answer



          share|improve this answer










          answered Nov 23 '18 at 4:07









          JacqueJacque

          3636




          3636













          • Could you add a code snippet using the python client, since as I mentioned in my post I tried adding threadId and for drafts it was simply ignored and the draft was created in a new thread (even though this worked for adding non-draft messages to threads)

            – fpghost
            Nov 24 '18 at 10:20



















          • Could you add a code snippet using the python client, since as I mentioned in my post I tried adding threadId and for drafts it was simply ignored and the draft was created in a new thread (even though this worked for adding non-draft messages to threads)

            – fpghost
            Nov 24 '18 at 10:20

















          Could you add a code snippet using the python client, since as I mentioned in my post I tried adding threadId and for drafts it was simply ignored and the draft was created in a new thread (even though this worked for adding non-draft messages to threads)

          – fpghost
          Nov 24 '18 at 10:20





          Could you add a code snippet using the python client, since as I mentioned in my post I tried adding threadId and for drafts it was simply ignored and the draft was created in a new thread (even though this worked for adding non-draft messages to threads)

          – fpghost
          Nov 24 '18 at 10:20




















          draft saved

          draft discarded




















































          Thanks for contributing an answer to Stack Overflow!


          • Please be sure to answer the question. Provide details and share your research!

          But avoid



          • Asking for help, clarification, or responding to other answers.

          • Making statements based on opinion; back them up with references or personal experience.


          To learn more, see our tips on writing great answers.




          draft saved


          draft discarded














          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53431048%2fhow-to-create-a-draft-message-in-existing-thread-with-gmail-api%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown





















































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown

































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown







          Popular posts from this blog

          MongoDB - Not Authorized To Execute Command

          How to fix TextFormField cause rebuild widget in Flutter

          Npm cannot find a required file even through it is in the searched directory