title: Using PHP cURL to POST data on /oauth2/access_token and GET data as jSON
body: <p>I has follow step on <a href="https://path.com/developers/docs" rel="nofollow">Path API</a> about how to Authentication User. In the tutorial auth process, user is begin to redirect to the following URL and prompt to grant access:</p>
  
  <p><a href="https://partner.path.com/oauth2/authenticate?response_type=code&amp;client_id=THE_CLIENT_ID" rel="nofollow">https://partner.path.com/oauth2/authenticate?response_type=code&amp;client_id=THE_CLIENT_ID</a></p>
  
  <p>And after that, server will give response as authorization <strong>code</strong> via URL Address (i have complete this step and got the <strong>code</strong>). </p>
  
  <p>As from docs explain, Code is should be exchanged for an access token using <strong>/oauth2/access_token</strong> as long with Client ID and Client Secret (get access_token)</p>
  
  <p>But i don't have any clue how to POST data via cURL to the server, i has try so many <strong>curl_setopt()</strong> option and combination, but it still give me a nothing.</p>
  
  <p>From the Docs, Request is look like this:</p>
  
  <pre><code>POST /oauth2/access_token HTTP/1.1
  Host: partner.path.com
  Content-Type: application/x-www-form-urlencoded
  Content-Length: &lt;LENGTH&gt;
  
  grant_type=authorization_code&amp;client_id=CLIENT&amp;client_secret=SECRET&amp;code=CODE
  </code></pre>
  
  <p>And cURL format like this:</p>
  
  <pre><code>curl -X POST \
       -F 'grant_type=authorization_code' \
       -F 'client_id=CLIENT_ID' \
       -F 'client_secret=CLIENT_SECRET' \
       -F 'code=CODE' \
       https://partner.path.com/oauth2/access_token
  </code></pre>
  
  <p>And server will give response like this:</p>
  
  <pre><code>HTTP/1.1 201 CREATED
  Content-Type: application/json
  Content-Length: &lt;LENGTH&gt;
  
  {
      "code": 201,
      "type": "CREATED"
      "reason": "Created",
      "access_token": &lt;ACCESS_TOKEN&gt;,
      "user_id": &lt;USER_ID&gt;,
  }
  </code></pre>