phpExt / DHL Express APIs (MyDHL API) / Service to allocate identifiers upfront for DHL Express Breakbulk or Loose Break Bulk shipments
Back to Collection Items
<?php
include("chilkat.php");
// Use "chilkat_9_5_0.php" for versions of Chilkat < 10.0.0
// This example assumes the Chilkat API to have been previously unlocked.
// See Global Unlock Sample for sample code.
$http = new CkHttp();
$http->put_BasicAuth(true);
$http->put_Login('<Basic Auth Username>');
$http->put_Password('<Basic Auth Password>');
$queryParams = new CkJsonObject();
$queryParams->UpdateString('accountNumber','Ut aliqua');
$queryParams->UpdateString('type','SID');
$queryParams->UpdateInt('size',1);
$http->SetRequestHeader('Webstore-Platform-Name','');
$http->SetRequestHeader('Shipping-System-Platform-Name','');
$http->SetRequestHeader('Message-Reference','d0e7832e-5c98-11ea-bc55-0242ac13');
$http->SetRequestHeader('Plugin-Version','');
$http->SetRequestHeader('Plugin-Name','');
$http->SetRequestHeader('Shipping-System-Platform-Version','');
$http->SetRequestHeader('Accept','application/json');
$http->SetRequestHeader('Message-Reference-Date','Wed, 21 Oct 2015 07:28:00 GMT');
$http->SetRequestHeader('Webstore-Platform-Version','');
// resp is a CkHttpResponse
$resp = $http->QuickRequestParams('GET','https://api-mock.dhl.com/mydhlapi/identifiers',$queryParams);
if ($http->get_LastMethodSuccess() == false) {
print $http->lastErrorText() . "\n";
exit;
}
$sbResponseBody = new CkStringBuilder();
$resp->GetBodySb($sbResponseBody);
$jResp = new CkJsonObject();
$jResp->LoadSb($sbResponseBody);
$jResp->put_EmitCompact(false);
print 'Response Body:' . "\n";
print $jResp->emit() . "\n";
$respStatusCode = $resp->get_StatusCode();
print 'Response Status Code = ' . $respStatusCode . "\n";
if ($respStatusCode >= 400) {
print 'Response Header:' . "\n";
print $resp->header() . "\n";
print 'Failed.' . "\n";
exit;
}
// Sample JSON response:
// (Sample code for parsing the JSON response is shown below)
// {
// "warnings": [
// "Warning message if anything goes wrong",
// "Warning message if anything goes wrong"
// ],
// "identifiers": [
// {
// "typeCode": "SID",
// "list": [
// "1234567890"
// ]
// },
// {
// "typeCode": "SID",
// "list": [
// "1234567890"
// ]
// }
// ]
// }
// Sample code for parsing the JSON response...
// Use this online tool to generate parsing code from sample JSON: Generate JSON Parsing Code
$i = 0;
$count_i = $jResp->SizeOfArray('warnings');
while ($i < $count_i) {
$jResp->put_I($i);
$strVal = $jResp->stringOf('warnings[i]');
$i = $i + 1;
}
$i = 0;
$count_i = $jResp->SizeOfArray('identifiers');
while ($i < $count_i) {
$jResp->put_I($i);
$typeCode = $jResp->stringOf('identifiers[i].typeCode');
$j = 0;
$count_j = $jResp->SizeOfArray('identifiers[i].list');
while ($j < $count_j) {
$jResp->put_J($j);
$strVal = $jResp->stringOf('identifiers[i].list[j]');
$j = $j + 1;
}
$i = $i + 1;
}
?>
Curl Command
curl -G -d "accountNumber=Ut%20aliqua"
-d "type=SID"
-d "size=1"
-u '<Basic Auth Username>:<Basic Auth Password>'
-H "Message-Reference: d0e7832e-5c98-11ea-bc55-0242ac13"
-H "Message-Reference-Date: Wed, 21 Oct 2015 07:28:00 GMT"
-H "Plugin-Name: "
-H "Plugin-Version: "
-H "Shipping-System-Platform-Name: "
-H "Shipping-System-Platform-Version: "
-H "Webstore-Platform-Name: "
-H "Webstore-Platform-Version: "
-H "Accept: application/json"
https://api-mock.dhl.com/mydhlapi/identifiers
Postman Collection Item JSON
{
"name": "Service to allocate identifiers upfront for DHL Express Breakbulk or Loose Break Bulk shipments",
"request": {
"method": "GET",
"header": [
{
"description": "Please provide message reference\n",
"key": "Message-Reference",
"value": "d0e7832e-5c98-11ea-bc55-0242ac13"
},
{
"description": "Optional reference date in the HTTP-date format https://tools.ietf.org/html/rfc7231#section-7.1.1.2",
"key": "Message-Reference-Date",
"value": "Wed, 21 Oct 2015 07:28:00 GMT"
},
{
"description": "Please provide name of the plugin (applicable to 3PV only)\n",
"key": "Plugin-Name",
"value": " "
},
{
"description": "Please provide version of the plugin (applicable to 3PV only)\n",
"key": "Plugin-Version",
"value": " "
},
{
"description": "Please provide name of the shipping platform(applicable to 3PV only)\n",
"key": "Shipping-System-Platform-Name",
"value": " "
},
{
"description": "Please provide version of the shipping platform (applicable to 3PV only)\n",
"key": "Shipping-System-Platform-Version",
"value": " "
},
{
"description": "Please provide name of the webstore platform (applicable to 3PV only)\n",
"key": "Webstore-Platform-Name",
"value": " "
},
{
"description": "Please provide version of the webstore platform (applicable to 3PV only)\n",
"key": "Webstore-Platform-Version",
"value": " "
},
{
"key": "Accept",
"value": "application/json"
}
],
"url": {
"raw": "{{baseUrl}}/identifiers?accountNumber=Ut aliqua&type=SID&size=1",
"host": [
"{{baseUrl}}"
],
"path": [
"identifiers"
],
"query": [
{
"key": "accountNumber",
"value": "Ut aliqua",
"description": "(Required) DHL Express customer account number"
},
{
"key": "type",
"value": "SID",
"description": "(Required) Type of DHL Express identifier to retrieve"
},
{
"key": "size",
"value": "1",
"description": "(Required) Number of identifiers to be retrieved"
}
]
},
"description": "Service to allocate identifiers upfront for DHL Express Breakbulk or Loose Break Bulk shipments. Requires authorization to use this service from DHL Express.\n"
},
"response": [
{
"name": "Identifers provided",
"originalRequest": {
"method": "GET",
"header": [
{
"description": "Added as a part of security scheme: basic",
"key": "Authorization",
"value": "Basic <credentials>"
},
{
"description": "Please provide message reference\n",
"key": "Message-Reference",
"value": "d0e7832e-5c98-11ea-bc55-0242ac13"
},
{
"description": "Optional reference date in the HTTP-date format https://tools.ietf.org/html/rfc7231#section-7.1.1.2",
"key": "Message-Reference-Date",
"value": "Wed, 21 Oct 2015 07:28:00 GMT"
},
{
"description": "Please provide name of the plugin (applicable to 3PV only)\n",
"key": "Plugin-Name",
"value": " "
},
{
"description": "Please provide version of the plugin (applicable to 3PV only)\n",
"key": "Plugin-Version",
"value": " "
},
{
"description": "Please provide name of the shipping platform(applicable to 3PV only)\n",
"key": "Shipping-System-Platform-Name",
"value": " "
},
{
"description": "Please provide version of the shipping platform (applicable to 3PV only)\n",
"key": "Shipping-System-Platform-Version",
"value": " "
},
{
"description": "Please provide name of the webstore platform (applicable to 3PV only)\n",
"key": "Webstore-Platform-Name",
"value": " "
},
{
"description": "Please provide version of the webstore platform (applicable to 3PV only)\n",
"key": "Webstore-Platform-Version",
"value": " "
}
],
"url": {
"raw": "{{baseUrl}}/identifiers?accountNumber=Ut aliqua&type=SID&size=1",
"host": [
"{{baseUrl}}"
],
"path": [
"identifiers"
],
"query": [
{
"key": "accountNumber",
"value": "Ut aliqua"
},
{
"key": "type",
"value": "SID"
},
{
"key": "size",
"value": "1"
}
]
}
},
"status": "OK",
"code": 200,
"_postman_previewlanguage": "json",
"header": [
{
"key": "Content-Type",
"value": "application/json"
}
],
"cookie": [
],
"body": "{\n \"warnings\": [\n \"Warning message if anything goes wrong\",\n \"Warning message if anything goes wrong\"\n ],\n \"identifiers\": [\n {\n \"typeCode\": \"SID\",\n \"list\": [\n \"1234567890\"\n ]\n },\n {\n \"typeCode\": \"SID\",\n \"list\": [\n \"1234567890\"\n ]\n }\n ]\n}"
},
{
"name": "Wrong input parameters",
"originalRequest": {
"method": "GET",
"header": [
{
"description": "Added as a part of security scheme: basic",
"key": "Authorization",
"value": "Basic <credentials>"
},
{
"description": "Please provide message reference\n",
"key": "Message-Reference",
"value": "d0e7832e-5c98-11ea-bc55-0242ac13"
},
{
"description": "Optional reference date in the HTTP-date format https://tools.ietf.org/html/rfc7231#section-7.1.1.2",
"key": "Message-Reference-Date",
"value": "Wed, 21 Oct 2015 07:28:00 GMT"
},
{
"description": "Please provide name of the plugin (applicable to 3PV only)\n",
"key": "Plugin-Name",
"value": " "
},
{
"description": "Please provide version of the plugin (applicable to 3PV only)\n",
"key": "Plugin-Version",
"value": " "
},
{
"description": "Please provide name of the shipping platform(applicable to 3PV only)\n",
"key": "Shipping-System-Platform-Name",
"value": " "
},
{
"description": "Please provide version of the shipping platform (applicable to 3PV only)\n",
"key": "Shipping-System-Platform-Version",
"value": " "
},
{
"description": "Please provide name of the webstore platform (applicable to 3PV only)\n",
"key": "Webstore-Platform-Name",
"value": " "
},
{
"description": "Please provide version of the webstore platform (applicable to 3PV only)\n",
"key": "Webstore-Platform-Version",
"value": " "
}
],
"url": {
"raw": "{{baseUrl}}/identifiers?accountNumber=Ut aliqua&type=SID&size=1",
"host": [
"{{baseUrl}}"
],
"path": [
"identifiers"
],
"query": [
{
"key": "accountNumber",
"value": "Ut aliqua"
},
{
"key": "type",
"value": "SID"
},
{
"key": "size",
"value": "1"
}
]
}
},
"status": "Bad Request",
"code": 400,
"_postman_previewlanguage": "json",
"header": [
{
"key": "Content-Type",
"value": "application/json"
}
],
"cookie": [
],
"body": "{\n \"instance\": \"/expressapi/identifiers\",\n \"detail\": \"3501: Request Identifier is not allowed for your username. Please contact your DHL Express representative.\",\n \"title\": \"Bad request\",\n \"message\": \"Bad request\",\n \"status\": \"400\"\n}"
}
]
}