title: Bearer Authorization denied in api using cURL
body: <p>I want to make a simple post request to an API server. I know, there are lot of information about cURL in web, but I can't figure out, why am I getting:</p>
  
  <p><code>[message] =&gt; Authorization has been denied for this request.</code></p>
  
  <p>So the API uses standard bearer token(in the header <code>Authorization: Bearer {tokenID}</code>)</p>
  
  <p>my php code:</p>
  
  <pre><code>$body = array(
          "id" =&gt; $uuid,
          "userAccountId" =&gt; $userAccountId,
          "email" =&gt; $email,
          "first_name" =&gt; $first_name,
          "last_name" =&gt; $last_name,
          "phone" =&gt; $phone,
        );
  
        $ch = curl_init();
        curl_setopt($ch, CURLOPT_HTTPHEADER, http_build_query(array(
          'Authorization' =&gt; $token,
        )));
        curl_setopt($ch, CURLOPT_URL, $myurl);
        curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
        curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($body));
        curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
        $result = curl_exec($ch);
        curl_close($ch);
        $result = json_decode($result);
  </code></pre>
  
  <p>The most interesting and weird thing is, that, when I send a Post request to the same url with the same body and the same header(same token) using postman, it works, however it doesn't work with php cURL. Also I tried with <a href="https://www.codepunker.com/tools/http-requests" rel="nofollow noreferrer">https://www.codepunker.com/tools/http-requests</a> and got the same Authorization error. Has anyone any ide what could it be ?</p>