I am trying to use curl with an API and post values to it. I'm posting the parameters in an associative array where all the values are either strings, integers or booleans apart from one value which is another array. (So there is an array within another array.)
The problem is: the second array isn't being sent properly and I can't get it to work. Originally the issue was 'array to string conversion' so I then started using http_build_query() around the params array and it stopped that issue but it sill isn't working.
I know it's probably an issue with my code and not the external API as other developers are using the API fine with other languages.
PHP Code:
$url = '{url}';
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT ,0);
curl_setopt($ch, CURLOPT_TIMEOUT, 60);
$headers = array("X-Auth-Token: $json_token");
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
$params = array(
'name' => 'sample_name',
'types' => array('web'),
'limit' => 2,
'auto' => true
);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($params));
$out = curl_exec($ch);
curl_close($ch);