I try to make a PUT request with curl. I need to send a csv file with stock update. When I execute my script I get the response code 200 but the file is not sending. The csv file is in the same directory.
<?php
try {
$file_name= "file_test.csv";
$api_key= "my-key";
$Client_id= "my-id";
$ch = curl_init("https://merchants-connector-importer.zalandoapis.com/".$Client_id."/".$file_name);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
curl_setopt($ch, CURLOPT_PUT, 1);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$data = array('file' =>curl_file_create($file_name, 'text/csv'));
curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
curl_setopt($ch,CURLOPT_HTTPHEADER, array(
"x-api-key: ".$api_key,
"Content-Type: application/csv",
"cache-control: no-cache"));
$content = curl_exec($ch);
if ($content === false) {
echo "ERROR";
throw new Exception(curl_error($ch), curl_errno($ch));
}else{
var_dump($content);
$decodedJson = json_decode($content, true);
var_dump(http_response_code());
}
} catch (Exception $e) {
trigger_error(
sprintf(
'Curl failed with error #%d: %s',
$e->getCode(),
$e->getMessage()
),
E_USER_ERROR
);
}