php - DHL Curl returning empty
I am doing a DHL ECommerce API integration.
The below request was provided in the documentation but when I try this in code using CURL library in PHP, it is just returning the below error
I tried to get the error code using curl_error($ch).
Any advice?
Thanks.
Getting me this error. HTTP/1.1 100 Continue Connection: Keep-Alive Content-Length: 0
HTTP/1.1 405 Method Not Allowed Connection: close WWW-Authenticate: Basic realm="Integration Server", encoding="UTF-8"
Request:
{
"labelRequest": {
"hdr": {
"messageType": "LABEL",
"messageDateTime": "2021-10-11T19:39:46 GMT+08:00",
"accessToken": "{removed}",
"messageVersion": "1.4",
"messageLanguage": "en"
},
"bd": {
"inlineLabelReturn": "U",
"customerAccountId": null,
"pickupAccountId": "34324324",
"soldToAccountId": "324324324",
"handoverMethod": null,
"pickupDateTime": null,
"pickupAddress": {
"name": "Jerry",
"address1": "DHL Express (M) Sdn. Bhd.",
"address2": "Menara TM .",
"city": "Laksi",
"state": "Laksi",
"district": "Laksi",
"country": "TH",
"postCode": "10010",
"phone": "123456789",
"email": "jerry@dhl.com"
},
"shipperAddress": {
"name": "Jerry",
"address1": "DHL Express (M) Sdn. Bhd.",
"address2": "Menara TM .",
"city": "Laksi",
"state": "Laksi",
"district": "Laksi",
"country": "TH",
"postCode": "10010",
"phone": "123456789",
"email": "jerry@dhl.com"
},
"shipmentItems": [{
"consigneeAddress": {
"name": "Jerry",
"address1": "DHL Express (M) Sdn. Bhd.",
"address2": "Menara TM .",
"city": "Laksi",
"state": "PICKUPstate",
"district": "Laksi",
"country": "TH",
"postCode": "10010",
"phone": "123456789",
"email": "jerry@dhl.com",
"idNumber": " 1023",
"idType": "1"
},
"returnAddress": {
"companyName": "DHL",
"name": "Jerry",
"address1": "DHL Express (M) Sdn. Bhd.",
"address2": "Menara TM .",
"city": "Laksi",
"state": "Laksi",
"district": "Laksi",
"country": "TH",
"postCode": "10010",
"phone": "123456789",
"email": "jerry@dhl.com"
},
"shipmentID": "3242341234324",
"deliveryConfirmationNo": "238643",
"packageDesc": "PKG_desc",
"totalWeight": 250,
"totalWeightUOM": "G",
"dimensionUOM": "cm",
"height": 120.0,
"length": 5.0,
"width": 0.0,
"customerReference1": null,
"customerReference2": null,
"productCode": "PDO",
"incoterm": null,
"contentIndicator": null,
"codValue": null,
"insuranceValue": null,
"freightCharge": null,
"totalValue": null,
"currency": "THB",
"remarks": "remarks to test",
"valueAddedServices": {
"valueAddedService": [{
"vasCode": "PPOD"
}
]
},
"isMult": "true",
"deliveryOption": "P",
"shipmentPieces": [{
"pieceID": 11,
"announcedWeight": {
"weight": null,
"unit": null
},
"codAmount": 5,
"insuranceAmount": null,
"billingReference1": "123",
"billingReference2": "123",
"pieceDescription": "Air Conditioner"
}, {
"pieceID": 12,
"announcedWeight": {
"weight": null,
"unit": null
},
"codAmount": 0.01,
"insuranceAmount": null,
"billingReference1": "123",
"billingReference2": "123",
"pieceDescription": "Device"
}
]
}
],
"label": {
"pageSize": "400x600",
"format": "PNG",
"layout": "1x1"
}
}
}
}
function httpPost($url, $strRequest,$userId, $password)
{
$ch = curl_init();
$url = "https://sandbox.dhlecommerce.asia/rest/v2/label";
$headers = array(
'Accept: application/json',
'Content-Type: application/json',
);
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $strRequest);
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
curl_setopt($ch, CURLOPT_HEADER, 1);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
$result = curl_exec($ch);
$this->errorCode = curl_errno($ch);
$this->errorMessage = curl_error($ch);
return $result;
}
Answer
Solution:
The issue was because the letter "l" in the word "label" should have been capital "L"
Source