How to turn this Curl / PUT command into php?

2

How do I transpose this curl code to send it in a PHP file?

curl -X PUT -H "Content-Type: application/json" -H "Accept: application/json" -d
{
  "status":"paused"
}
https://api.mercadolibre.com/items/ITEM_ID?access_token=YOUR_ACCESS_TOKEN
    
asked by anonymous 07.09.2016 / 22:59

2 answers

2
$url       = 'https://api.mercadolibre.com/items/ITEM_ID?access_token=YOUR_ACCESS_TOKEN';
$cabecalho = array('Content-Type: application/json', 'Accept: application/json');
$campos    = json_encode(array('status' => 'paused'));

$ch = curl_init();

curl_setopt($ch, CURLOPT_URL,            $url);
curl_setopt($ch, CURLOPT_HTTPHEADER,     $cabecalho);
curl_setopt($ch, CURLOPT_POSTFIELDS,     $campos);
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 10);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_POST,           true);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST,  'PUT');

$resposta = curl_exec($ch);

curl_close($ch);
    
11.11.2016 / 20:48
-1

Perfect solution works perfectly just forgot the semicolon

$url       = 'https://api.mercadolibre.com/items/ITEM_ID?access_token=YOUR_ACCESS_TOKEN';
$cabecalho = array('Content-Type: application/json', 'Accept: application/json')    <<<<--------   adicionar o   ";"
$campos    = json_encode(array('status' => 'paused'));

$ch = curl_init();

curl_setopt($ch, CURLOPT_URL,            $url);
curl_setopt($ch, CURLOPT_HTTPHEADER,     $cabecalho);
curl_setopt($ch, CURLOPT_POSTFIELDS,     $campos);
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 10);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_POST,           true);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST,  'PUT');

$resposta = curl_exec($ch);

curl_close($ch);
    
08.07.2018 / 22:04