Answer the question
In order to leave comments, you need to log in
Why isn't JSON sent to the API via a POST request?
I'm trying to send data as a JSON POST request to the RetailCRM service API. However, for some reason, the interaction does not occur.
There is a code:
<?php
$url = 'https://domain.retailcrm.ru/api/v5/orders/create?apiKey=t2SlFkY8o7tLpsGpbzeluCHd5TbFkxfD';
$json = '
{
"site":"ID",
"order":{
"firstName":"Тест 001",
"phone":"00000000000",
"email":"[email protected]",
"delivery":{
"address":"Тестовый адрес..."
},
"customerComment":"Комментарий клиента...",
"number":"Номер_Заказа",
"items":[
{
"offer":{
"externalId":"6005"
},
"quantity":"1"
},
{
"offer":{
"externalId":"6017"
},
"quantity":"5"
}
]
}
}
';
$data = array(
'site' => 'ID',
'order' => array(
'firstName' => 'Тест 001',
'phone' => '00000000000',
'email' => '[email protected]',
'delivery' => array(
'address' => 'Тестовый адрес...'
),
'customerComment' => 'Комментарий клиента...',
'number' => 'Номер_Заказа',
'items' => [
array(
'offer' => array(
'externalId' => '6005'
),
'quantity' => '1'
),
array(
'offer' => array(
'externalId' => '6017'
),
'quantity' => '5'
)
]
)
);
$postdata = http_build_query(json_encode($data));
$opts = array('http' =>
array(
'method' => 'POST',
'header' => 'Content-type: application/json; charset=UTF-8',
'content' => $postdata
)
);
$context = stream_context_create($opts);
return file_get_contents($url, false, $context);
?>
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question