title: How to make a POST api call in php
body: <p>I have been stuck on this for 2 day now. I looked all over the internet for the answer and could not find it.</p>
  
  <p>I need to make a POST request to an api to register users. This is the info I was given. </p>
  
  <pre><code>url: https://webbsite.com/api/register
  
  HEADERS
  ..........................................................
  Content-Type:application/json
  Access-Token: randomaccesstoken
  
  Body
  ..........................................................
  {
    'email' =&gt; 'John.doe@gmail.com',
    'firstName' =&gt; 'John',
    'lastName' =&gt; 'Doe',
    'password' =&gt; "mypassword1"
  }
  
  Response
  ..........................................................
  201
  ..........................................................
  HEADERS
  ..........................................................
  Content-Type:application/json
  
  BODY
  ..........................................................
  {
    "success": ture,
    "data": {
         "user_id": 1,
         "token": "randomusertoken"
    }
  }
  </code></pre>
  
  <p>This is what I have so far. No matter what I do it results in an error. I feel it might have something to do with the Access-Token placement. It was hard to find an example that uses a access token. Is this the correct way to make a POST request to an api in php?</p>
  
  <pre><code>$authToken = 'randomaccesstoken';
  $postData = array(
     'email' =&gt; 'John.doe@gmail.com',
     'firstName' =&gt; 'John',
     'lastName' =&gt; 'Doe',
     'password' =&gt; "mypassword1"
  
  );
  
  // Create the context for the request
  $context = stream_context_create(array(
      'http' =&gt; array(
          'method' =&gt; 'POST',
          'header' =&gt; "Authorization: {$authToken}\r\n".
                      "Content-Type: application/json\r\n",
          'content' =&gt; json_encode($postData)
      )
  ));
  
  
      $response = file_get_contents('https://webbsite.com/api/register', FALSE, $context);
  
      if($response === FALSE){
          die('Error');
      }
  
  
      $responseData = json_decode($response, TRUE);
  
  
      print_r($responseData);
  </code></pre>