Chilkat Online Tools

unicodeC / DHL Express APIs (MyDHL API) / Get Image

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 *shipmentTrackingNumber;
    const wchar_t *typeCode;
    const wchar_t *encodingFormat;
    const wchar_t *content;
    const wchar_t *v_function;
    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"shipperAccountNumber",L"Ut aliqua");
    CkJsonObjectW_UpdateString(queryParams,L"typeCode",L"customs-entry");
    CkJsonObjectW_UpdateString(queryParams,L"pickupYearAndMonth",L"YYYY-MM");
    CkJsonObjectW_UpdateString(queryParams,L"encodingFormat",L"tiff");
    CkJsonObjectW_UpdateString(queryParams,L"allInOnePDF",L"false");
    CkJsonObjectW_UpdateString(queryParams,L"compressedPackage",L"false");

    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/shipments/:shipmentTrackingNumber/get-image",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)

    // {
    //   "documents": [
    //     {
    //       "shipmentTrackingNumber": "1234567890",
    //       "typeCode": "waybill",
    //       "encodingFormat": "PDF",
    //       "content": "base64 encoded document",
    //       "function": "import"
    //     },
    //     {
    //       "shipmentTrackingNumber": "1234567890",
    //       "typeCode": "waybill",
    //       "encodingFormat": "PDF",
    //       "content": "base64 encoded document",
    //       "function": "import"
    //     }
    //   ]
    // }

    // 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"documents");
    while (i < count_i) {
        CkJsonObjectW_putI(jResp,i);
        shipmentTrackingNumber = CkJsonObjectW_stringOf(jResp,L"documents[i].shipmentTrackingNumber");
        typeCode = CkJsonObjectW_stringOf(jResp,L"documents[i].typeCode");
        encodingFormat = CkJsonObjectW_stringOf(jResp,L"documents[i].encodingFormat");
        content = CkJsonObjectW_stringOf(jResp,L"documents[i].content");
        v_function = CkJsonObjectW_stringOf(jResp,L"documents[i].function");
        i = i + 1;
    }



    CkHttpW_Dispose(http);
    CkJsonObjectW_Dispose(queryParams);
    CkStringBuilderW_Dispose(sbResponseBody);
    CkJsonObjectW_Dispose(jResp);

    }

Curl Command

curl -G -d "shipperAccountNumber=Ut%20aliqua"
	-d "typeCode=customs-entry"
	-d "pickupYearAndMonth=YYYY-MM"
	-d "encodingFormat=tiff"
	-d "allInOnePDF=false"
	-d "compressedPackage=false"
	-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/shipments/:shipmentTrackingNumber/get-image

Postman Collection Item JSON

{
  "name": "Get Image",
  "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}}/shipments/:shipmentTrackingNumber/get-image?shipperAccountNumber=Ut aliqua&typeCode=customs-entry&pickupYearAndMonth=YYYY-MM&encodingFormat=tiff&allInOnePDF=false&compressedPackage=false",
      "host": [
        "{{baseUrl}}"
      ],
      "path": [
        "shipments",
        ":shipmentTrackingNumber",
        "get-image"
      ],
      "query": [
        {
          "key": "shipperAccountNumber",
          "value": "Ut aliqua",
          "description": "(Required) DHL Express customer shipper account number"
        },
        {
          "key": "typeCode",
          "value": "customs-entry",
          "description": "(Required) Please provide correct document type."
        },
        {
          "key": "pickupYearAndMonth",
          "value": "YYYY-MM",
          "description": "(Required) Please provide the pickup's date in YYYY-MM format\n"
        },
        {
          "key": "encodingFormat",
          "value": "tiff",
          "description": "Please provide the document image encoding format in pdf or tiff format\n"
        },
        {
          "key": "allInOnePDF",
          "value": "false",
          "description": "Option to return all the document images in a single PDF file\n"
        },
        {
          "key": "compressedPackage",
          "value": "false",
          "description": "Option to return all the document images in a compressed package\n"
        }
      ],
      "variable": [
        {
          "key": "shipmentTrackingNumber",
          "value": "dolor veniam officia non",
          "description": "(Required) DHL Express shipment identification number"
        }
      ]
    },
    "description": "The Get Image service can be used to retrieve customer's own uploaded Commercial Invoice, Waybill Document  or supporting documents that uploaded during shipment creation. \n"
  },
  "response": [
    {
      "name": "Document Image found",
      "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}}/shipments/:shipmentTrackingNumber/get-image?shipperAccountNumber=Ut aliqua&typeCode=customs-entry&pickupYearAndMonth=YYYY-MM&encodingFormat=tiff&allInOnePDF=false&compressedPackage=false",
          "host": [
            "{{baseUrl}}"
          ],
          "path": [
            "shipments",
            ":shipmentTrackingNumber",
            "get-image"
          ],
          "query": [
            {
              "key": "shipperAccountNumber",
              "value": "Ut aliqua"
            },
            {
              "key": "typeCode",
              "value": "customs-entry"
            },
            {
              "key": "pickupYearAndMonth",
              "value": "YYYY-MM"
            },
            {
              "key": "encodingFormat",
              "value": "tiff"
            },
            {
              "key": "allInOnePDF",
              "value": "false"
            },
            {
              "key": "compressedPackage",
              "value": "false"
            }
          ],
          "variable": [
            {
              "key": "shipmentTrackingNumber",
              "value": "dolor veniam officia non",
              "description": "(Required) DHL Express shipment identification number"
            }
          ]
        }
      },
      "status": "OK",
      "code": 200,
      "_postman_previewlanguage": "json",
      "header": [
        {
          "key": "Invocation-Id",
          "value": "sed ut mollit",
          "description": "Unique identifier of the transaction"
        },
        {
          "key": "Message-Reference",
          "value": "sed ut mollit",
          "description": "Message reference provided by customer as part of reqeust or automatically generated when not provided"
        },
        {
          "key": "Content-Language",
          "value": "sed ut mollit",
          "description": ""
        },
        {
          "key": "Content-Type",
          "value": "application/json"
        }
      ],
      "cookie": [
      ],
      "body": "{\n  \"documents\": [\n    {\n      \"shipmentTrackingNumber\": \"1234567890\",\n      \"typeCode\": \"waybill\",\n      \"encodingFormat\": \"PDF\",\n      \"content\": \"base64 encoded document\",\n      \"function\": \"import\"\n    },\n    {\n      \"shipmentTrackingNumber\": \"1234567890\",\n      \"typeCode\": \"waybill\",\n      \"encodingFormat\": \"PDF\",\n      \"content\": \"base64 encoded document\",\n      \"function\": \"import\"\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}}/shipments/:shipmentTrackingNumber/get-image?shipperAccountNumber=Ut aliqua&typeCode=customs-entry&pickupYearAndMonth=YYYY-MM&encodingFormat=tiff&allInOnePDF=false&compressedPackage=false",
          "host": [
            "{{baseUrl}}"
          ],
          "path": [
            "shipments",
            ":shipmentTrackingNumber",
            "get-image"
          ],
          "query": [
            {
              "key": "shipperAccountNumber",
              "value": "Ut aliqua"
            },
            {
              "key": "typeCode",
              "value": "customs-entry"
            },
            {
              "key": "pickupYearAndMonth",
              "value": "YYYY-MM"
            },
            {
              "key": "encodingFormat",
              "value": "tiff"
            },
            {
              "key": "allInOnePDF",
              "value": "false"
            },
            {
              "key": "compressedPackage",
              "value": "false"
            }
          ],
          "variable": [
            {
              "key": "shipmentTrackingNumber",
              "value": "dolor veniam officia non",
              "description": "(Required) DHL Express shipment identification number"
            }
          ]
        }
      },
      "status": "Bad Request",
      "code": 400,
      "_postman_previewlanguage": "json",
      "header": [
        {
          "key": "Content-Type",
          "value": "application/json"
        }
      ],
      "cookie": [
      ],
      "body": "{\n  \"instance\": \"/expressapi/shipments/1371943801/get-image?shipperAccountNumber=848811505&typeCode=waybill&typeCode=commercial-invoice&pickupYearAndMonth=2021-11&encodingFormat=tiff&allInOnePDF=true&compressedPackage=false\",\n  \"detail\": \"1506: encodingFormat TIFF is not applicable in combination with allInOnePDF = true.  Please check the request message and retry.\",\n  \"title\": \"Bad request\",\n  \"message\": \"Bad request\",\n  \"status\": \"400\"\n}"
    },
    {
      "name": "No document image found",
      "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}}/shipments/:shipmentTrackingNumber/get-image?shipperAccountNumber=Ut aliqua&typeCode=customs-entry&pickupYearAndMonth=YYYY-MM&encodingFormat=tiff&allInOnePDF=false&compressedPackage=false",
          "host": [
            "{{baseUrl}}"
          ],
          "path": [
            "shipments",
            ":shipmentTrackingNumber",
            "get-image"
          ],
          "query": [
            {
              "key": "shipperAccountNumber",
              "value": "Ut aliqua"
            },
            {
              "key": "typeCode",
              "value": "customs-entry"
            },
            {
              "key": "pickupYearAndMonth",
              "value": "YYYY-MM"
            },
            {
              "key": "encodingFormat",
              "value": "tiff"
            },
            {
              "key": "allInOnePDF",
              "value": "false"
            },
            {
              "key": "compressedPackage",
              "value": "false"
            }
          ],
          "variable": [
            {
              "key": "shipmentTrackingNumber",
              "value": "dolor veniam officia non",
              "description": "(Required) DHL Express shipment identification number"
            }
          ]
        }
      },
      "status": "Not Found",
      "code": 404,
      "_postman_previewlanguage": "json",
      "header": [
        {
          "key": "Content-Type",
          "value": "application/json"
        }
      ],
      "cookie": [
      ],
      "body": "{\n  \"instance\": \"/expressapi/shipments/1371943802/get-image?shipperAccountNumber=848811505&typeCode=waybills&pickupYearAndMonth=2021-11&encodingFormat=tiff&allInOnePDF=true&compressedPackage=false\",\n  \"detail\": \"1504: No document images found for the provided search criteria.\",\n  \"title\": \"Not found\",\n  \"message\": \"Not found\",\n  \"status\": \"404\"\n}"
    }
  ]
}