title: How to set the request body in a json format
body: <p>I'm trying to send a request body in a json format to an API. The docs state the body needs to be formatted like so:</p>
  
  <pre><code>//Request body needs to the contain a JSON object in the following format:
  
  {  
    "delete_list":[  
      "8fcd1d68c82dd39d65ef8ea9a7948bbe",
      "8bca1d68c92dd39d65ef8ea9a7948bbe",
      "8bca1d69c82d939d65ef8ea9a7948bbe",
      "8bca1d69c82d939d65ef8ea9a7947bbe"
     ]
  }
  </code></pre>
  
  <p>My attempted code seems to fail and I am not sure why. I've tried quite a few adjustments and nothing seems to work:</p>
  
  <pre><code>    $del = array("delete_list" =&gt; "[8bca1d69c82d939d65ef8ea9a7947bbe]");
      $j = json_encode($del);
  
  
      $apiToken = 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx';
  
      $httpHeadersArray = Array();
      $httpHeadersArray[] = 'Authorization: key='.$apiToken;
      $httpHeadersArray[] = 'Content-Type: application/json';
  
  
      //open connection
      $ch = curl_init();
  
      //set the url, number of POST vars, POST data
      curl_setopt($ch, CURLOPT_URL, $curlUrl);
      #curl_setopt($ch, CURLOPT_POST, true);
      curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
      curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "PUT");
      curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($j));
      curl_setopt($ch, CURLOPT_HTTPHEADER, $httpHeadersArray);
  
  
      $res = curl_exec($ch);
  
  
      echo "&lt;pre&gt;";
      print_r($res);
      echo "&lt;/pre&gt;";
  </code></pre>
  
  <p>My end result that I get back from the API is as follows: </p>
  
  <pre><code>{"status":"failure","message":"JSON malformed"}
  </code></pre>
  
  <p>Any suggestions as to what I am doing wrong with the code? It would be greatly appreciated. Thanks!</p>