title: Get XERO API Access code error: unsupported_grant_type
body: <p>I'm trying to get accessToken from Xero</p>
  <p>This is their instruction:
  <a href="https://developer.xero.com/documentation/guides/oauth2/auth-flow/#3-exchange-the-code" rel="nofollow noreferrer">https://developer.xero.com/documentation/guides/oauth2/auth-flow/#3-exchange-the-code</a></p>
  <pre><code>POST https://identity.xero.com/connect/token
  authorization: &quot;Basic &quot; + base64encode(client_id + &quot;:&quot; + client_secret)
  Content-Type: application/x-www-form-urlencoded
  
  grant_type=authorization_code
  &amp;code=xxxxxx
  &amp;redirect_uri=https://myapp.com/redirect
  </code></pre>
  <p>This is how I do it:</p>
  <pre><code>tokenb4 = &quot;{0}:{1}&quot;.format(CLIENT_ID, CLIENT_SECRET)
  basic_token = base64.urlsafe_b64encode(tokenb4.encode()).decode()
  response = requests.post(
      &quot;https://identity.xero.com/connect/token&quot;,
      headers={
          &quot;Authorization&quot;: &quot;Basic {0}&quot;.format(basic_token),
          &quot;Content-Type&quot;: &quot;application/x-www-form-urlencoded&quot;
      },
      params=&quot;grant_type=authorization_code \
              &amp;code=MYCODE \
              &amp;redirect_uri=https://developer.xero.com/&quot;
  )
  </code></pre>
  <p>Now I keep getting error 400
  {&quot;error&quot;:&quot;unsupported_grant_type&quot;}</p>
  <p>redirect_uri is the same with the one I leave in the App in Xero demo company.
  I've googled some, seems like it's a format issue but I can't see what's wrong with my code.</p>
  <p>Much appreciation if anyone could help</p>