DataFlex / DHL Express APIs (MyDHL API) / Service to allocate identifiers upfront for DHL Express Breakbulk or Loose Break Bulk shipments
Back to Collection Items
Use ChilkatAx-win32.pkg
Procedure Test
Handle hoHttp
Boolean iSuccess
Variant vQueryParams
Handle hoQueryParams
Variant vResp
Handle hoResp
Variant vSbResponseBody
Handle hoSbResponseBody
Handle hoJResp
Integer iRespStatusCode
String sStrVal
String sTypeCode
Integer j
Integer iCount_j
Integer i
Integer iCount_i
String sTemp1
Boolean bTemp1
// This example assumes the Chilkat API to have been previously unlocked.
// See Global Unlock Sample for sample code.
Get Create (RefClass(cComChilkatHttp)) To hoHttp
If (Not(IsComObjectCreated(hoHttp))) Begin
Send CreateComObject of hoHttp
End
Set ComBasicAuth Of hoHttp To True
Set ComLogin Of hoHttp To "<Basic Auth Username>"
Set ComPassword Of hoHttp To "<Basic Auth Password>"
Get Create (RefClass(cComChilkatJsonObject)) To hoQueryParams
If (Not(IsComObjectCreated(hoQueryParams))) Begin
Send CreateComObject of hoQueryParams
End
Get ComUpdateString Of hoQueryParams "accountNumber" "Ut aliqua" To iSuccess
Get ComUpdateString Of hoQueryParams "type" "SID" To iSuccess
Get ComUpdateInt Of hoQueryParams "size" 1 To iSuccess
Send ComSetRequestHeader To hoHttp "Webstore-Platform-Name" ""
Send ComSetRequestHeader To hoHttp "Shipping-System-Platform-Name" ""
Send ComSetRequestHeader To hoHttp "Message-Reference" "d0e7832e-5c98-11ea-bc55-0242ac13"
Send ComSetRequestHeader To hoHttp "Plugin-Version" ""
Send ComSetRequestHeader To hoHttp "Plugin-Name" ""
Send ComSetRequestHeader To hoHttp "Shipping-System-Platform-Version" ""
Send ComSetRequestHeader To hoHttp "Accept" "application/json"
Send ComSetRequestHeader To hoHttp "Message-Reference-Date" "Wed, 21 Oct 2015 07:28:00 GMT"
Send ComSetRequestHeader To hoHttp "Webstore-Platform-Version" ""
Get pvComObject of hoQueryParams to vQueryParams
Get ComQuickRequestParams Of hoHttp "GET" "https://api-mock.dhl.com/mydhlapi/identifiers" vQueryParams To vResp
If (IsComObject(vResp)) Begin
Get Create (RefClass(cComChilkatHttpResponse)) To hoResp
Set pvComObject Of hoResp To vResp
End
Get ComLastMethodSuccess Of hoHttp To bTemp1
If (bTemp1 = False) Begin
Get ComLastErrorText Of hoHttp To sTemp1
Showln sTemp1
Procedure_Return
End
Get Create (RefClass(cComChilkatStringBuilder)) To hoSbResponseBody
If (Not(IsComObjectCreated(hoSbResponseBody))) Begin
Send CreateComObject of hoSbResponseBody
End
Get pvComObject of hoSbResponseBody to vSbResponseBody
Get ComGetBodySb Of hoResp vSbResponseBody To iSuccess
Get Create (RefClass(cComChilkatJsonObject)) To hoJResp
If (Not(IsComObjectCreated(hoJResp))) Begin
Send CreateComObject of hoJResp
End
Get pvComObject of hoSbResponseBody to vSbResponseBody
Get ComLoadSb Of hoJResp vSbResponseBody To iSuccess
Set ComEmitCompact Of hoJResp To False
Showln "Response Body:"
Get ComEmit Of hoJResp To sTemp1
Showln sTemp1
Get ComStatusCode Of hoResp To iRespStatusCode
Showln "Response Status Code = " iRespStatusCode
If (iRespStatusCode >= 400) Begin
Showln "Response Header:"
Get ComHeader Of hoResp To sTemp1
Showln sTemp1
Showln "Failed."
Send Destroy of hoResp
Procedure_Return
End
Send Destroy of hoResp
// 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
Move 0 To i
Get ComSizeOfArray Of hoJResp "warnings" To iCount_i
While (i < iCount_i)
Set ComI Of hoJResp To i
Get ComStringOf Of hoJResp "warnings[i]" To sStrVal
Move (i + 1) To i
Loop
Move 0 To i
Get ComSizeOfArray Of hoJResp "identifiers" To iCount_i
While (i < iCount_i)
Set ComI Of hoJResp To i
Get ComStringOf Of hoJResp "identifiers[i].typeCode" To sTypeCode
Move 0 To j
Get ComSizeOfArray Of hoJResp "identifiers[i].list" To iCount_j
While (j < iCount_j)
Set ComJ Of hoJResp To j
Get ComStringOf Of hoJResp "identifiers[i].list[j]" To sStrVal
Move (j + 1) To j
Loop
Move (i + 1) To i
Loop
End_Procedure
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}"
}
]
}