unicodeC / DHL Express APIs (MyDHL API) / Validate DHL Express pickup/delivery capabilities at origin/destination
Back to Collection Items
#include <C_CkHttpW.h>
#include <C_CkJsonObjectW.h>
#include <C_CkHttpResponseW.h>
#include <C_CkStringBuilderW.h>
void ChilkatSample(void)
{
HCkHttpW http;
BOOL success;
HCkJsonObjectW queryParams;
HCkHttpResponseW resp;
HCkStringBuilderW sbResponseBody;
HCkJsonObjectW jResp;
int respStatusCode;
const wchar_t *strVal;
const wchar_t *countryCode;
const wchar_t *postalCode;
const wchar_t *cityName;
const wchar_t *countyName;
const wchar_t *Code;
const wchar_t *Description;
const wchar_t *GMTOffset;
int i;
int count_i;
// This example assumes the Chilkat API to have been previously unlocked.
// See Global Unlock Sample for sample code.
http = CkHttpW_Create();
CkHttpW_putBasicAuth(http,TRUE);
CkHttpW_putLogin(http,L"<Basic Auth Username>");
CkHttpW_putPassword(http,L"<Basic Auth Password>");
queryParams = CkJsonObjectW_Create();
CkJsonObjectW_UpdateString(queryParams,L"type",L"pickup");
CkJsonObjectW_UpdateString(queryParams,L"countryCode",L"CZ");
CkJsonObjectW_UpdateInt(queryParams,L"postalCode",14800);
CkJsonObjectW_UpdateString(queryParams,L"cityName",L"Prague");
CkJsonObjectW_UpdateString(queryParams,L"countyName",L"praha");
CkJsonObjectW_UpdateString(queryParams,L"strictValidation",L"true");
CkHttpW_SetRequestHeader(http,L"Webstore-Platform-Name",L"");
CkHttpW_SetRequestHeader(http,L"Shipping-System-Platform-Name",L"");
CkHttpW_SetRequestHeader(http,L"Message-Reference",L"d0e7832e-5c98-11ea-bc55-0242ac13");
CkHttpW_SetRequestHeader(http,L"Plugin-Version",L"");
CkHttpW_SetRequestHeader(http,L"Plugin-Name",L"");
CkHttpW_SetRequestHeader(http,L"Shipping-System-Platform-Version",L"");
CkHttpW_SetRequestHeader(http,L"Accept",L"application/json");
CkHttpW_SetRequestHeader(http,L"Message-Reference-Date",L"Wed, 21 Oct 2015 07:28:00 GMT");
CkHttpW_SetRequestHeader(http,L"Webstore-Platform-Version",L"");
resp = CkHttpW_QuickRequestParams(http,L"GET",L"https://api-mock.dhl.com/mydhlapi/address-validate",queryParams);
if (CkHttpW_getLastMethodSuccess(http) == FALSE) {
wprintf(L"%s\n",CkHttpW_lastErrorText(http));
CkHttpW_Dispose(http);
CkJsonObjectW_Dispose(queryParams);
return;
}
sbResponseBody = CkStringBuilderW_Create();
CkHttpResponseW_GetBodySb(resp,sbResponseBody);
jResp = CkJsonObjectW_Create();
CkJsonObjectW_LoadSb(jResp,sbResponseBody);
CkJsonObjectW_putEmitCompact(jResp,FALSE);
wprintf(L"Response Body:\n");
wprintf(L"%s\n",CkJsonObjectW_emit(jResp));
respStatusCode = CkHttpResponseW_getStatusCode(resp);
wprintf(L"Response Status Code = %d\n",respStatusCode);
if (respStatusCode >= 400) {
wprintf(L"Response Header:\n");
wprintf(L"%s\n",CkHttpResponseW_header(resp));
wprintf(L"Failed.\n");
CkHttpResponseW_Dispose(resp);
CkHttpW_Dispose(http);
CkJsonObjectW_Dispose(queryParams);
CkStringBuilderW_Dispose(sbResponseBody);
CkJsonObjectW_Dispose(jResp);
return;
}
CkHttpResponseW_Dispose(resp);
// Sample JSON response:
// (Sample code for parsing the JSON response is shown below)
// {
// "warnings": [
// "ea quis cillum ut",
// "amet voluptate dol"
// ],
// "address": [
// {
// "countryCode": "CZ",
// "postalCode": "14800",
// "cityName": "PRAGUE",
// "countyName": "ex id labore aute",
// "serviceArea": {
// "code": "PRG",
// "description": "PRAGUE-CZECH REPUBLIC, THE",
// "GMTOffset": "+01:00"
// }
// },
// {
// "countryCode": "CZ",
// "postalCode": "14800",
// "cityName": "PRAGUE",
// "countyName": "quis ullamco reprehenderit esse in",
// "serviceArea": {
// "code": "PRG",
// "description": "PRAGUE-CZECH REPUBLIC, THE",
// "GMTOffset": "+01:00"
// }
// }
// ]
// }
// Sample code for parsing the JSON response...
// Use this online tool to generate parsing code from sample JSON: Generate JSON Parsing Code
// Chilkat functions returning "const char *" return a pointer to temporary internal memory owned and managed by Chilkat.
i = 0;
count_i = CkJsonObjectW_SizeOfArray(jResp,L"warnings");
while (i < count_i) {
CkJsonObjectW_putI(jResp,i);
strVal = CkJsonObjectW_stringOf(jResp,L"warnings[i]");
i = i + 1;
}
i = 0;
count_i = CkJsonObjectW_SizeOfArray(jResp,L"address");
while (i < count_i) {
CkJsonObjectW_putI(jResp,i);
countryCode = CkJsonObjectW_stringOf(jResp,L"address[i].countryCode");
postalCode = CkJsonObjectW_stringOf(jResp,L"address[i].postalCode");
cityName = CkJsonObjectW_stringOf(jResp,L"address[i].cityName");
countyName = CkJsonObjectW_stringOf(jResp,L"address[i].countyName");
Code = CkJsonObjectW_stringOf(jResp,L"address[i].serviceArea.code");
Description = CkJsonObjectW_stringOf(jResp,L"address[i].serviceArea.description");
GMTOffset = CkJsonObjectW_stringOf(jResp,L"address[i].serviceArea.GMTOffset");
i = i + 1;
}
CkHttpW_Dispose(http);
CkJsonObjectW_Dispose(queryParams);
CkStringBuilderW_Dispose(sbResponseBody);
CkJsonObjectW_Dispose(jResp);
}
Curl Command
curl -G -d "type=pickup"
-d "countryCode=CZ"
-d "postalCode=14800"
-d "cityName=Prague"
-d "countyName=praha"
-d "strictValidation=true"
-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/address-validate
Postman Collection Item JSON
{
"name": "Validate DHL Express pickup/delivery capabilities at origin/destination",
"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}}/address-validate?type=pickup&countryCode=CZ&postalCode=14800&cityName=Prague&countyName=praha&strictValidation=true",
"host": [
"{{baseUrl}}"
],
"path": [
"address-validate"
],
"query": [
{
"key": "type",
"value": "pickup",
"description": "(Required) "
},
{
"key": "countryCode",
"value": "CZ",
"description": "(Required) A short text string code (see values defined in ISO 3166) specifying the shipment origin country. https://gs1.org/voc/Country, Alpha-2 Code"
},
{
"key": "postalCode",
"value": "14800",
"description": "Text specifying the postal code for an address. https://gs1.org/voc/postalCode"
},
{
"key": "cityName",
"value": "Prague",
"description": "Text specifying the city name"
},
{
"key": "countyName",
"value": "praha",
"description": "Text specifying the county name"
},
{
"key": "strictValidation",
"value": "true",
"description": "If set to true service will return no records when exact valid match not found"
}
]
},
"description": "Validates if DHL Express has got pickup/delivery capabilities at origin/destination\n"
},
"response": [
{
"name": "Address validated",
"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}}/address-validate?type=pickup&countryCode=CZ&postalCode=14800&cityName=Prague&countyName=praha&strictValidation=true",
"host": [
"{{baseUrl}}"
],
"path": [
"address-validate"
],
"query": [
{
"key": "type",
"value": "pickup"
},
{
"key": "countryCode",
"value": "CZ"
},
{
"key": "postalCode",
"value": "14800"
},
{
"key": "cityName",
"value": "Prague"
},
{
"key": "countyName",
"value": "praha"
},
{
"key": "strictValidation",
"value": "true"
}
]
}
},
"status": "OK",
"code": 200,
"_postman_previewlanguage": "json",
"header": [
{
"key": "Content-Type",
"value": "application/json"
}
],
"cookie": [
],
"body": "{\n \"warnings\": [\n \"ea quis cillum ut\",\n \"amet voluptate dol\"\n ],\n \"address\": [\n {\n \"countryCode\": \"CZ\",\n \"postalCode\": \"14800\",\n \"cityName\": \"PRAGUE\",\n \"countyName\": \"ex id labore aute\",\n \"serviceArea\": {\n \"code\": \"PRG\",\n \"description\": \"PRAGUE-CZECH REPUBLIC, THE\",\n \"GMTOffset\": \"+01:00\"\n }\n },\n {\n \"countryCode\": \"CZ\",\n \"postalCode\": \"14800\",\n \"cityName\": \"PRAGUE\",\n \"countyName\": \"quis ullamco reprehenderit esse in\",\n \"serviceArea\": {\n \"code\": \"PRG\",\n \"description\": \"PRAGUE-CZECH REPUBLIC, THE\",\n \"GMTOffset\": \"+01:00\"\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}}/address-validate?type=pickup&countryCode=CZ&postalCode=14800&cityName=Prague&countyName=praha&strictValidation=true",
"host": [
"{{baseUrl}}"
],
"path": [
"address-validate"
],
"query": [
{
"key": "type",
"value": "pickup"
},
{
"key": "countryCode",
"value": "CZ"
},
{
"key": "postalCode",
"value": "14800"
},
{
"key": "cityName",
"value": "Prague"
},
{
"key": "countyName",
"value": "praha"
},
{
"key": "strictValidation",
"value": "true"
}
]
}
},
"status": "Bad Request",
"code": 400,
"_postman_previewlanguage": "json",
"header": [
{
"key": "Content-Type",
"value": "application/json"
}
],
"cookie": [
],
"body": "{\n \"instance\": \"/expressapi/address-validate\",\n \"detail\": \"Parameters not having correct format: cityName (maxLength=45)\",\n \"title\": \"Bad request\",\n \"message\": \"Bad request\",\n \"status\": \"400\"\n}"
}
]
}