title: Cloud Task Creation : Error: 3 INVALID_ARGUMENT: Request contains an invalid argument
body: <p>I'm following thist tutorial :  <a href="https://cloud.google.com/tasks/docs/tutorial-gcf" rel="nofollow noreferrer">https://cloud.google.com/tasks/docs/tutorial-gcf</a></p>
  <p>To create a Task that would call a cloud function.</p>
  <p>I've done quite some tries and still get this error:</p>
  <p><a href="https://i.stack.imgur.com/YLBek.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/YLBek.png" alt="enter image description here" /></a></p>
  <p>If I change the body encoding to something else, I get another error about serialisation method.</p>
  <p>It's likely not a permission issues, as I got some before and got rid of it.</p>
  <p>The object which is pass to the createTask() is the following :</p>
  <pre><code>task: {
    httpRequest: {
      url: &quot;https://europe-west1-project_id.cloudfunctions.net/FunctionName&quot;
      httpMethod: &quot;POST&quot;
      oidcToken: {
        serviceAccountEmail: &quot;cf-targetFunctionSA@project_id.gserviceaccount.com&quot;
      }
    body: &quot;&quot;
    headers: {
      Content-Type: &quot;application/json&quot;
    }
  }
  </code></pre>
  <p>(or with body: base64 encoded json string.)</p>
  <p>The code I use is the following :</p>
  <pre><code>'use strict';
  const common            = require('./common');
  const {v2beta3}         = require('@google-cloud/tasks');
  const cloudTasksClient  = new v2beta3.CloudTasksClient();
  
  let projectName = common.getProjectName();
  let location    = &quot;europe-west3&quot;;
  let queue       = &quot;compute-stats-on-mysql&quot;;
  const parent    = cloudTasksClient.queuePath(projectName, location, queue);
  
  async function createTask(url, serviceAccount, data)
  {
    const dataBuffer  = Buffer.from(JSON.stringify(data)).toString('base64');
    const task = {
      httpRequest: {
        httpMethod: 'POST',
        url:url,
        oidcToken: {
          serviceAccountEmail: serviceAccount,
        },
        headers: {
          'Content-Type': 'application/json',
        },
        body:dataBuffer,
      },
    };
  
  
    try
    {
      // Send create task request.
      common.logDebug(`Before creating task`, {parent:parent,task:task, data:data});
      const [response] = await cloudTasksClient.createTask({parent, task});
      common.logDebug(`Created task ${response.name}`, {parent:parent,task:task, response:response, data:data});
      return response;
    }
    catch (error)
    {
      // Construct error for Stackdriver Error Reporting
      console.error(&quot;error while creating tasks&quot;,error);
    }
  }
  
  module.exports = {
    createTask : createTask,
    cloudTasksClient:cloudTasksClient
  };
  </code></pre>
  <p>The lack of details in the error makes me hit a wall blind...</p>
  <p>Any suggestions ?</p>