0

I'm trying now to execute PUT request using cURL PHP.

Unfortunately, I receive an error "HTTP Status 415 - Unsupported Media Type". Here is my code :

$ch = curl_init();

$proxy = 'api.test.sandbox.mobile.de';
$proxy_port = "8080";

$loginpassw = 'XXX:YYY';

$url='https://services.mobile.de/seller-api/sellers/1086/ads/509939';

$headers = array();
$headers[] = "Content-type: application/json";

$data = array(
    'mileage' => '10000',
);

curl_setopt($ch, CURLOPT_PROXY, $proxy);
curl_setopt($ch, CURLOPT_PROXYPORT, $proxy_port);
curl_setopt($ch, CURLOPT_PROXYTYPE, CURLPROXY_HTTP);

curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_USERPWD, $loginpassw);

curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "PUT");
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($data));
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);

curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);

$data = curl_exec($ch);
if (curl_errno($ch)) {
    echo 'Error:' . curl_error($ch);
}
echo $data;

curl_close($ch);

What is wrong with py request ?

1 Answer 1

1

According to their API, you need to send data in either JSON or XML format and specify Content-Type header https://services.mobile.de/docs/seller-api.html#_media_types

So set the header for writing:

 curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: application/vnd.de.mobile.api+json');  

And change POSTFIELDS to

  curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($data));
Sign up to request clarification or add additional context in comments.

3 Comments

yes you're right. I've modified $headers with "Content-type:application/vnd.de.mobile.api+json", and I don't have 415 code anymore. Good point. Now, I get
Get what? Did you also convert the data to JSON?
Eveything is OK now, you were right that was a pb of json. Moreover, I couldn't update only one field of the ad, I have to send the complete content of the ad. Thanks a lot for your help.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.