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": "[email protected]"
},
"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": "[email protected]"
},
"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": "[email protected]",
"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": "[email protected]"
},
"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;
}
The issue was because the letter "l" in the word "label" should have been capital "L"
Our community is visited by hundreds of web development professionals every day. Ask your question and get a quick answer for free.
Find the answer in similar questions on our website.
Do you know the answer to this question? Write a quick response to it. With your help, we will make our community stronger.
PHP (from the English Hypertext Preprocessor - hypertext preprocessor) is a scripting programming language for developing web applications. Supported by most hosting providers, it is one of the most popular tools for creating dynamic websites.
The PHP scripting language has gained wide popularity due to its processing speed, simplicity, cross-platform, functionality and distribution of source codes under its own license.
https://www.php.net/
Welcome to the Q&A site for web developers. Here you can ask a question about the problem you are facing and get answers from other experts. We have created a user-friendly interface so that you can quickly and free of charge ask a question about a web programming problem. We also invite other experts to join our community and help other members who ask questions. In addition, you can use our search for questions with a solution.
Ask about the real problem you are facing. Describe in detail what you are doing and what you want to achieve.
Our goal is to create a strong community in which everyone will support each other. If you find a question and know the answer to it, help others with your knowledge.