title: Creating a task in Asana with JS (fail) and CURL (work)
body: <p>I am writing a quotation system for myself.</p>
  <p>I have this web page for quotations, which does:<br />
  a) send an email to the customer (done) with the quoted items<br />
  b) create a record inside a google spreadsheet (done)<br />
  c) create a task in asana (fail)</p>
  <p>For the last 2 days I have been surfing and reading all I can find, but the solution skips from my mind.</p>
  <p>This is the <em>CURL</em> code, which <strong>works just fine</strong>:</p>
  <pre><code>curl -H &quot;Authorization: Bearer 0/7alotofnumbers&quot; \
     https://app.asana.com/api/1.0/tasks \
     -d &quot;projects=83694179XXXXXX&quot; \
     -d &quot;tags[0]=269280227XXXXXX&quot; \
     -d &quot;assignee=sales@atmysite.com.mx&quot; \
     -d &quot;due_on=2017-02-09&quot; \
     -d &quot;name=testing with curl&quot; \
     -d &quot;notes=it works just as expected&quot; \
     -d &quot;followers[0]=myself@atmysite.com.mx&quot;
  </code></pre>
  <p>Now, I translated the CURL command that WORKS into asanataskcreate.coffee:</p>
  <pre><code>$.ajax
    url: 'https://app.asana.com/api/1.0/tasks'
    beforeSend: (xhr) -&gt;
      xhr.setRequestHeader 'Authorization', 'Bearer 0/7alotofnumbers'
      return
    contentType: 'application/json'
    method: 'get'
    data:
      projects: [ 83694179XXXXXX ]
      tags: [ 269280227XXXXXX ]
      assignee: 'sales@atmysite.com.mx'
      due_on: '2017-02-09'
      name: 'testing with js ajax'
      notes: 'it does not work'
      followers: [ 'myself@atmysite.com.mx' ]
  </code></pre>
  <p>which turns into asanataskcreate.js:</p>
  <pre><code>$.ajax({
    url: 'https://app.asana.com/api/1.0/tasks',
    beforeSend: function(xhr) {
      xhr.setRequestHeader('Authorization', 'Bearer 0/7alotofnumbers');
    },
    contentType: 'application/json',
    method: 'get',
    data: {
      projects: [83694179XXXXXX],
      tags: [269280227XXXXXX],
      assignee: 'sales@atmysite.com.mx',
      due_on: '2017-02-28',
      name: 'testing with js ajax',
      notes: 'it does not work',
      followers: ['myself@atmysite.com.mx']
    }
  });
  </code></pre>
  <p>And, <em><strong>FAILS</strong></em> :(</p>
  <p>Ok, I have tried:<br />
  <strong>a)</strong> method: 'post' and 'get'<br />
  <strong>b)</strong> place, remove the '[]' at projects, tags and followers</p>
  <p>With the assistance of Chrome devtools in the 'console' I get the following message:</p>
  <blockquote>
  <p>Failed to load resource: the server responded with a status of 400 (Bad Request)</p>
  </blockquote>
  <p>and</p>
  <blockquote>
  <p>XMLHttpRequest cannot load <a href="https://app.asana.com/api/1.0/tasks?projects%5B%5D=836941797XXXXXX&amp;tags%5B%5%E2%80%A6&amp;notes=it+does+not+work&amp;followers%5B%5D=myself%40atmysite.com.mx" rel="nofollow noreferrer">https://app.asana.com/api/1.0/tasks?projects%5B%5D=836941797XXXXXX&amp;tags%5B%5…&amp;notes=it+does+not+work&amp;followers%5B%5D=myself%40atmysite.com.mx</a>. No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://atmysite.com.mx' is therefore not allowed access. The response had HTTP status code 400.</p>
  </blockquote>
  <p>Now, in DevTools, when checking the XHR response from asana, this is what I get:</p>
  <blockquote>
  <p>message: &quot;You should specify one of workspace, project, tag, section&quot;</p>
  </blockquote>
  <p>As you can see from the code, there is a project id defined, but in JS fails and in curl works.</p>
  <p>Analyzing why 'projects' in curl works and in ajax fails, the difference is:</p>
  <pre><code>curl: projects=83694179XXXXXX
  js ajax: projects%5B%5D=836941797XXXXXX ==&gt; projects[]=836941797XXXXXX
  </code></pre>
  <p>What I am doing wrong?</p>