Answer the question
In order to leave comments, you need to log in
Why does it give a 400 error when sending XML to cdek?
I'm trying to send an XML POST request via API to CDEK, it gives an error: 400 Bad Request, the support service did not want to help, they just said that the xml was compiled correctly
$request = <<<XML
<?xml version="1.0" encoding="UTF-8" ?>
<DeliveryRequest
Number="0000033876WO"
Date="2019-04-05T10:01:15+00:00"
Account="2JewP7QZL****3a3qT1z8NCbIIbKAw2"
Secure="f6b6059bb333ec****f5446457f2"
OrderCount="1">
<Order Number="12345" SendCityPostCode="350000" RecCityPostCode="350000" RecipientName="Герусов Александр Валерьевич" RecipientEmail="[email protected]" Phone="89615096005" TariffTypeCode="136" DeliveryRecipientCost="137" DeliveryRecipientVATRate="VATX" DeliveryRecipientVATSum="0" SellerName="ИП Волженин Е.Г." SellerAddress="Ленинградская обл, Всеволожский р-н, Пос. Лесное, дом № 18, кв.6">
<Address PvzCode="KSD5"/>
<Package Number="1" BarCode="krd61927-1" Weight="1000">
<Item WareKey="158308" Cost="790" Payment="790" PaymentVATRate="VATX" PaymentVATSum="0" Weight="1000" Amount="1" Comment="Кронштейн для телевизора Ultramounts UM 814F черный"/>
</Package>
</Order>
</DeliveryRequest>
XML;
$host_api = 'https://integration.cdek.ru/new_orders.php';
$curl = curl_init();
curl_setopt($curl, CURLOPT_URL, $host_api);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($curl, CURLOPT_HTTPHEADER,
array('Content-Type: text/xml; charset=utf-8',
'Content-Length: '. strlen($request)));
curl_setopt($curl, CURLOPT_POST, 1);
curl_setopt($curl, CURLOPT_POSTFIELDS, [
'xml_request' => $request
]);
$response = curl_exec($curl);
if ($response === false) {
echo "cURL Error: " . curl_error($curl);
}
curl_close($curl);
echo "<pre>";
print_r($response);
echo "</pre>";
Answer the question
In order to leave comments, you need to log in
In requests to API 1.5, the request body is passed in the xml_request parameter and the Content-Type should be set to application/x-www-form-urlencoded
May need to be changed to:
'xml_request' => urlencode ($request)
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question