4

I'm trying to connect API with PHP. But all I get is "Command parameters are required". In order to work I need to send RAW Body data with it and it needs to be in PUT method.

Json data needs to look like

{
"OutputID":"Some key",
"Activate":true,
}

Here is my code

    $curl = curl_init($URL);

curl_setopt($curl, CURLOPT_CUSTOMREQUEST, "PUT");  

curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, false);

$jsonData = array(
    'OutputID' => 'Some key',
    'Activate' => true,
);

$jsonDataEncoded = json_encode($jsonData);
curl_setopt($curl, CURLOPT_POST, true);
curl_setopt($curl, CURLOPT_POSTFIELDS, $jsonDataEncoded);

curl_setopt($curl, CURLOPT_HTTPHEADER, array(   
    'Content-Type: application/json',
    'Content-Length: 0',
    $Authorization_Token_Key));


if(curl_exec($curl) === false)
{
    echo 'Curl error: ' . curl_error($curl);
}
else
{
    echo '';
}

If I try it with Postman it works but not in PHP Script.

Mike
  • 23,542
  • 14
  • 76
  • 87
Nexar
  • 81
  • 1
  • 4

1 Answers1

4

@Patrick

You where right :)

I removed

curl_setopt($curl, CURLOPT_POST, true);

And it works like a charm

Thanks

Nexar
  • 81
  • 1
  • 4
  • Instead try using `curl_setopt($curl, CURLOPT_PUT, true);`. See https://stackoverflow.com/questions/19257295/send-put-request-with-php-curl – Mike Aug 24 '17 at 20:43