Code:
Hi, would like to enquire how to create and print shipment label from own website using rest api. Have change the code
below based on https://docs.postmen.com/dhl-global-mail-asia.html?sdk=php#labels-create-a-label. Please advise. Thanks.
POST
<?php
$url = 'https://sandbox.api.com/v3/labels';
$method = 'POST';
$headers = array(
"content-type: application/json",
"api-key: secretkey"
);
$body = '{"labelreq":{
"accesstoken":""
},
"shipperaddr":{
"company":"",
},
"consigneeaddr":{
"address":""
},
}';
$curl = curl_init();
curl_setopt_array($curl, array(
CURLOPT_RETURNTRANSFER => true,
CURLOPT_URL => $url,
CURLOPT_CUSTOMREQUEST => $method,
CURLOPT_HTTPHEADER => $headers,
CURLOPT_POSTFIELDS => $body
));
$response = curl_exec($curl);
$err = curl_error($curl);
curl_close($curl);
if ($err) {
echo "cURL Error #:" . $err;
} else {
echo $response;
}
?>
GET
<?php
$url = 'https://sandbox.api.com/v3/labels/accesstokenkey';
$method = 'GET';
$headers = array(
"content-type: application/json",
"api-key: secretkey"
);
$curl = curl_init();
curl_setopt_array($curl, array(
CURLOPT_RETURNTRANSFER => true,
CURLOPT_URL => $url,
CURLOPT_CUSTOMREQUEST => $method,
CURLOPT_HTTPHEADER => $headers,
));
$response = curl_exec($curl);
$err = curl_error($curl);
curl_close($curl);
if ($err) {
echo "cURL Error #:" . $err;
} else {
echo $response;
}
?>