title: Retrieve JSON via PHP REST API
body: <p>I have this cURL function that send json to a REST API:</p>
  
  <pre><code>$url = "https://server.com/api.php";
  $fields = array("method" =&gt; "mymethod", "email" =&gt; "myemail");
  
  $result = sendTrigger($url, $fields);
  
  function sendTrigger($url, $fields){  
      $fields = json_encode($fields);
      $ch = curl_init();
      curl_setopt($ch, CURLOPT_HTTPHEADER, array("Content-Type: application/json; charset=UTF-8"));
      curl_setopt($ch, CURLOPT_URL, $url);
      curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
      curl_setopt($ch, CURLOPT_POSTFIELDS, $fields);
      curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
      $curlResult["msg"] = curl_exec($ch);
      $curlResult["http"] = curl_getinfo($ch, CURLINFO_HTTP_CODE);
      curl_close($ch);
      return $curlResult;
  }
  </code></pre>
  
  <p>On the server, I have this code:</p>
  
  <pre><code>$data = json_decode($_REQUEST);
  var_dump($data);
  exit();
  </code></pre>
  
  <p>When I execute the cURL command it returns me this:</p>
  
  <pre><code>Warning:  json_decode() expects parameter 1 to be string, array given in
  </code></pre>
  
  <p>How's that?</p>
  
  <p>Thanks.</p>