Example PHP Code

<?php

$url = 'https://xc-connect-sit.xpresscover.com/api/courier/list';

$body = '';

$ch = curl_init();

// set option
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_TIMEOUT_MS, 5000);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_POST,           1);
curl_setopt($ch, CURLOPT_POSTFIELDS,     $body);

curl_setopt($ch, CURLOPT_HTTPHEADER, array(
    'Content-Type: application/json',
    
    // auth method: signature
    'api-id: ' . 'test-api-id',
    'api-sign: '. hash('sha256', 'test-api-secret' . $body),
));

// auth method: http basic auth
// curl_setopt($ch, CURLOPT_USERPWD, "test-api-id:test-api-secret");

// get result
$result = curl_exec($ch);

$responseErrorCode = curl_errno($ch);
if ($responseErrorCode == 0){
    // ok
    $responseBody = trim($result);
}else{
    // error
    $responseErrorMessage = curl_error($ch);
}

$responseStatusCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);

//close connection
curl_close($ch);

echo $responseBody;

Last updated

Was this helpful?