It is possible that your site is running on a hosting that does not meet the requirements of PHP-client for interacting with API:
-
old PHP version installed (5.2 and below)
-
missing PHP cURL extension
In this case, you can refer to API using the normal function file_get_contents
. Below are examples of its use.
Do not use the examples below if your hosting allows you to work with the official API client for PHP. These examples do not include error handling and network problems.
Examples
Creating order
<?php
$crmDomain = 'https://some-crm.retailcrm.pro';
$crmKey = '4325fd34e1kVkahXL8XA3g3DEWIsQnwY';
$postData = http_build_query(array(
'order' =>json_encode(array(
'firstName' => 'Name',
'phone' => 'Phone',
'email' => 'Email',
'items' => array (
array (
'productName' => 'Product name',
'offer' => array (
'id' => 'Internal id of the trade offer',
'externalId' => 'External id of a trade offer',
'xmlId' => 'id of the trade offer in the warehouse system',
)),
array(
'productName' => 'Product name',
'offer' => array (
'id' => 'Internal id of the trade offer',
'externalId' => 'External id of a trade offer',
'xmlId' => 'id of the trade offer in the warehouse system',
)))
'...'
)),
'apiKey' =>$crmKey,
));
$opts = array('http' =>
array(
'method' =>'POST',
'header' =>'Content-type: application/x-www-form-urlencoded',
'content' =>$postData
)
);
$context = stream_context_create($opts);
$result = json_decode(
file_get_contents(
$crmDomain . '/api/v4/orders/create',
false,
$context
),
true
);
echo "ID of the created order = " . $result['id'];
Getting information on order
<?php
$crmDomain = 'https://some-crm.retailcrm.pro';
$crmKey = '4325fd34e1kVkahXL8XA3g3DEWIsQnwY';
// example
$orderId = 5;
$params = array(
'by' =>'id',
'apiKey' =>$crmKey,
);
$result = json_decode(
file_get_contents($crmDomain . '/api/v4/orders/' . $orderId . '?' . http_build_query($params)),
true
);
if (isset($result['order'])) {
// order information
print_r($result['order']);
}
Getting order statuses
<?php
$crmDomain = 'https://some-crm.retailcrm.pro';
$crmKey = '4325fd34e1kVkahXL8XA3g3DEWIsQnwY';
// example
$orderIds = array(1, 2, 3);
$params = array(
'ids' =>$orderIds,
'apiKey' =>$crmKey,
);
$result = json_decode(
file_get_contents($crmDomain . '/api/v4/orders/statuses' . http_build_query($params)),
true
);
if (isset($result['orders'])) {
foreach ($result['orders'] as $order) {
echo $order['id'];
echo $order['status'];
}
}