title: M Language - How to get JSON in HTTP Request Body? (Vimeo API Unsupported Grant Type Error)
body: <p>I am attempting to create my first PowerBI Custom Connecter to connect to the Vimeo API. I am stuck on the final step of the authorization flow - getting back an access token. When trying out the Connecter in PowerBI, it seems to authenticate properly when I hit the access token endpoint, but I get back a warning &quot;[unsupported_grant_type] Unsupported grant type&quot;</p>
  <p>It appears I am not sending the grant_type properly in the request. Here are Vimeo's requirements of what is sent along in the header and body of the request:</p>
  <hr />
  <div class="s-table-container">
  <table class="s-table">
  <thead>
  <tr>
  <th>Header</th>
  <th>Set value to</th>
  </tr>
  </thead>
  <tbody>
  <tr>
  <td>Authorization</td>
  <td>basic base64_encode(x:y), where x is the client identifier and y is the client secret</td>
  </tr>
  <tr>
  <td>Content-Type</td>
  <td>application/json</td>
  </tr>
  <tr>
  <td>Accept</td>
  <td>application/vnd.vimeo.*+json;version=3.4</td>
  </tr>
  </tbody>
  </table>
  </div>
  <p>&quot;In the request body, send the grant_type field with the value authorization_code. You must also set code to the authorization code string that you just received and redirect_uri to the redirect URI that you specified previously — don't use a different redirect URI.&quot;</p>
  <pre><code>{
    &quot;grant_type&quot;: &quot;authorization_code&quot;,
    &quot;code&quot;: &quot;{code}&quot;,
    &quot;redirect_uri&quot;: &quot;{redirect_uri}&quot;
  }
  </code></pre>
  <hr />
  <p>Here is a snippet of code from the Customer Connector I am building. It is within this TokenMethod function that I am trying to fulfill the requirements of the table above. I am getting the sense I am not correctly placing the JSON in the body of the request, but I am stuck on what to try next:</p>
  <pre><code>
  TokenMethod = (grantType, tokenField, code) =&gt;
     let
         queryString = [
             grant_type = &quot;authorization_code&quot;,
             redirect_uri = redirect_uri,
             client_id = client_id,
             client_secret = client_secret
         ],
         queryWithCode = Record.AddField(queryString, tokenField, code),
  
         authKey = &quot;Basic &quot; &amp; Binary.ToText(Text.ToBinary(&quot;client_id:client_secret&quot;),BinaryEncoding.Base64),
  
         tokenResponse = Web.Contents(token_uri, [
             Content = Text.ToBinary(Uri.BuildQueryString(queryWithCode)),
             Headers = [
                 #&quot;Authorization&quot; = authKey,
                 #&quot;Content-type&quot; = &quot;application/json&quot;,
                 #&quot;Accept&quot; = &quot;application/vnd.vimeo.*+json;version=3.4&quot;
             ],
             ManualStatusHandling = {400} 
         ]),
         body = Json.Document(tokenResponse),
         result = if (Record.HasFields(body, {&quot;error&quot;, &quot;error_description&quot;})) then 
                     error Error.Record(body[error], body[error_description], body)
                  else
                     body
     in
         result;
  </code></pre>
  <p>I'm wondering if someone could please point out where I might be going astray in the code and why I am receiving the [unsupported_grant_type] error.</p>
  <p>Many thanks for your time!</p>