title: Nodejs- Set body to Google cloud task queue
body: <p>I have a nodejs server in Google app engine where I want to delegate long running tasks to task queues using the <a href="https://cloud.google.com/appengine/docs/standard/python/taskqueue/" rel="nofollow noreferrer">Google Cloud Task queue</a>.</p>
  
  <p>Task queue not delivering request body but hitting the endpoint:</p>
  
  <p>This is how I add task to task queue:</p>
  
  <p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
  <div class="snippet-code">
  <pre class="snippet-code-js lang-js prettyprint-override"><code>// Imports the Google Cloud Tasks library.
  const cloudTasks = require('@google-cloud/tasks');
  
  // Instantiates a client.
  const client = new cloudTasks.CloudTasksClient();
  const project = 'projectname';
  const queue = 'queuename';
  const location = 'us-central1';
  const parent = client.queuePath(project, location, queue);
  
  // Send create task request.
  exports.sender = async function (options) {
  // Construct the fully qualified queue name.
      let myMap = new Map();
      myMap.set("Content-Type", "application/json");
      const task = {
          appEngineHttpRequest: {
              httpMethod: 'POST',
              relativeUri: '/log_payload',
              headers: myMap,
              body: options/* Buffer.from(JSON.stringify(options)).toString('base64')*/
          },
      };
      
      /* if (options.payload !== undefined) {
           task.appEngineHttpRequest.body = Buffer.from(options.payload).toString(
             'base64'
           );
       }*/
      
      if (options.inSeconds !== undefined) {
          task.scheduleTime = {
              seconds: options.inSeconds + Date.now() / 1000,
          };
      }
      
      const request = {
          parent: parent,
          task: task,
      };
      client.createTask(request)
        .then(response =&gt; {
            const task = response[0].name;
            //console.log(`Created task ${task}`);
            return {'Response': String(response)}
        })
        .catch(err =&gt; {
            //console.error(`Error in createTask: ${err.message || err}`);
            return `Error in createTask: ${err.message || err}`;
        });
  };</code></pre>
  </div>
  </div>
  </p>
  
  <p>And this is the endpoint receiving:</p>
  
  <p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
  <div class="snippet-code">
  <pre class="snippet-code-js lang-js prettyprint-override"><code>app.post('/log_payload', async (req, res) =&gt; {
      let mailOptions = {
          subject: 'Message Delivered',
          from: 'sender@example.com',
          to: "receiver@example.com",
          text: String(JSON.stringify(JSON.stringify(req.body)))
      };
      return await mailer.sendEmail(mailOptions).then(value =&gt; {
          return res.send(`Received task payload: ${value}`).end()
      }).catch(reason =&gt; {
          res.send(`Worker error: ${reason.message}`).end()
      });
  });</code></pre>
  </div>
  </div>
  </p>
  
  <p>When the email is received, both the body is an empty Json objects.
  What am I doing wrong?</p>