title: How to authorize post request in REST API?
body: <p>I'm sitting here working on making a post request in a rest api in php using curl. For this purpose I have the api key and an auth key, which I am currently including as post values in the request. But I keep getting HTML back in my response instead of JSON data (which its supposed to be) giving me a 401 unauthorized error.</p>
  
  <p>I've noticed often you need to make custom headers to authorize yourself in these cases (I'm guessing I need to use my auth key for that, in the header somehow).</p>
  
  <p>This is my code: </p>
  
  <pre><code>$post = [
      'apikey' =&gt; $apiKey,
      'authkey' =&gt; $authKey,
      'name' =&gt; $reknr,
      'description' =&gt; $opgave,
      'clientId'   =&gt; $clientId,
      'orderTypeId' =&gt; $typeId,
      'contactAddressId' =&gt; $addressId,
      'theirref' =&gt; $ref,
      'reqno' =&gt; $reknr
  ];
  
  // Set api link
  $ch = curl_init('https://app.minuba.dk/api/1/Order');
  
  // Set return value to true
  curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
  
  // Configure header
  curl_setopt($curl, CURLOPT_HTTPHEADER, array(
          'Authorization: Basic '.$authKey,
          'Content-Type: application/json')
  );
  
  // Add post fields
  curl_setopt($ch, CURLOPT_POSTFIELDS, $post);
  
  // execute!
  $response = curl_exec($ch);
  
  // close the connection, release resources used
  curl_close($ch);
  </code></pre>
  
  <p>The API docs doesn't say anything about how you authorize yourself when making post request, during get requests its fairly easy you just include the apikey and authkey as normal parameters and it works fine.</p>
  
  <p>My question is, how do I know how to configure my header so the API authorizes me? The docs say nothing about it or offers any explanation as to how except mentioning you need both the apikey and authkey to gain access.</p>
  
  <p>I admit my understand of the http headers are limited, but how do I know how to configure it for this particular api?</p>
  
  <p>UPDATE: </p>
  
  <p>Found out the header response gives me this line:
  WWW-Authenticate: Basic realm="Minuba REST API"</p>
  
  <p>This tells me that the method I'm using to authenticate should be correct right? So why am I still getting a 401?</p>