Chilkat Online Tools

SQL Server / DHL Express APIs (MyDHL API) / Electronic Proof of Delivery

Back to Collection Items

-- Important: See this note about string length limitations for strings returned by sp_OAMethod calls.
--
CREATE PROCEDURE ChilkatSample
AS
BEGIN
    DECLARE @hr int
    DECLARE @iTmp0 int
    -- Important: Do not use nvarchar(max).  See the warning about using nvarchar(max).
    DECLARE @sTmp0 nvarchar(4000)
    -- This example assumes the Chilkat API to have been previously unlocked.
    -- See Global Unlock Sample for sample code.

    DECLARE @http int
    EXEC @hr = sp_OACreate 'Chilkat_9_5_0.Http', @http OUT
    IF @hr <> 0
    BEGIN
        PRINT 'Failed to create ActiveX component'
        RETURN
    END

    DECLARE @success int

    EXEC sp_OASetProperty @http, 'BasicAuth', 1
    EXEC sp_OASetProperty @http, 'Login', '<Basic Auth Username>'
    EXEC sp_OASetProperty @http, 'Password', '<Basic Auth Password>'

    DECLARE @queryParams int
    EXEC @hr = sp_OACreate 'Chilkat_9_5_0.JsonObject', @queryParams OUT

    EXEC sp_OAMethod @queryParams, 'UpdateString', @success OUT, 'shipperAccountNumber', 'Ut aliqua'
    EXEC sp_OAMethod @queryParams, 'UpdateString', @success OUT, 'content', 'epod-summary'

    EXEC sp_OAMethod @http, 'SetRequestHeader', NULL, 'Webstore-Platform-Name', ''
    EXEC sp_OAMethod @http, 'SetRequestHeader', NULL, 'Shipping-System-Platform-Name', ''
    EXEC sp_OAMethod @http, 'SetRequestHeader', NULL, 'Message-Reference', 'd0e7832e-5c98-11ea-bc55-0242ac13'
    EXEC sp_OAMethod @http, 'SetRequestHeader', NULL, 'Plugin-Version', ''
    EXEC sp_OAMethod @http, 'SetRequestHeader', NULL, 'Plugin-Name', ''
    EXEC sp_OAMethod @http, 'SetRequestHeader', NULL, 'Shipping-System-Platform-Version', ''
    EXEC sp_OAMethod @http, 'SetRequestHeader', NULL, 'Accept', 'application/json'
    EXEC sp_OAMethod @http, 'SetRequestHeader', NULL, 'Message-Reference-Date', 'Wed, 21 Oct 2015 07:28:00 GMT'
    EXEC sp_OAMethod @http, 'SetRequestHeader', NULL, 'Webstore-Platform-Version', ''

    DECLARE @resp int
    EXEC sp_OAMethod @http, 'QuickRequestParams', @resp OUT, 'GET', 'https://api-mock.dhl.com/mydhlapi/shipments/:shipmentTrackingNumber/proof-of-delivery', @queryParams
    EXEC sp_OAGetProperty @http, 'LastMethodSuccess', @iTmp0 OUT
    IF @iTmp0 = 0
      BEGIN
        EXEC sp_OAGetProperty @http, 'LastErrorText', @sTmp0 OUT
        PRINT @sTmp0
        EXEC @hr = sp_OADestroy @http
        EXEC @hr = sp_OADestroy @queryParams
        RETURN
      END

    DECLARE @sbResponseBody int
    EXEC @hr = sp_OACreate 'Chilkat_9_5_0.StringBuilder', @sbResponseBody OUT

    EXEC sp_OAMethod @resp, 'GetBodySb', @success OUT, @sbResponseBody

    DECLARE @jResp int
    EXEC @hr = sp_OACreate 'Chilkat_9_5_0.JsonObject', @jResp OUT

    EXEC sp_OAMethod @jResp, 'LoadSb', @success OUT, @sbResponseBody
    EXEC sp_OASetProperty @jResp, 'EmitCompact', 0


    PRINT 'Response Body:'
    EXEC sp_OAMethod @jResp, 'Emit', @sTmp0 OUT
    PRINT @sTmp0

    DECLARE @respStatusCode int
    EXEC sp_OAGetProperty @resp, 'StatusCode', @respStatusCode OUT

    PRINT 'Response Status Code = ' + @respStatusCode
    IF @respStatusCode >= 400
      BEGIN

        PRINT 'Response Header:'
        EXEC sp_OAGetProperty @resp, 'Header', @sTmp0 OUT
        PRINT @sTmp0

        PRINT 'Failed.'
        EXEC @hr = sp_OADestroy @resp

        EXEC @hr = sp_OADestroy @http
        EXEC @hr = sp_OADestroy @queryParams
        EXEC @hr = sp_OADestroy @sbResponseBody
        EXEC @hr = sp_OADestroy @jResp
        RETURN
      END
    EXEC @hr = sp_OADestroy @resp

    -- Sample JSON response:
    -- (Sample code for parsing the JSON response is shown below)

    -- {
    --   "documents": [
    --     {
    --       "encodingFormat": "PDF",
    --       "content": "base64 encoded content",
    --       "typeCode": "POD"
    --     },
    --     {
    --       "encodingFormat": "PDF",
    --       "content": "base64 encoded content",
    --       "typeCode": "POD"
    --     }
    --   ]
    -- }

    -- Sample code for parsing the JSON response...
    -- Use this online tool to generate parsing code from sample JSON: Generate JSON Parsing Code

    DECLARE @encodingFormat nvarchar(4000)

    DECLARE @content nvarchar(4000)

    DECLARE @typeCode nvarchar(4000)

    DECLARE @i int
    SELECT @i = 0
    DECLARE @count_i int
    EXEC sp_OAMethod @jResp, 'SizeOfArray', @count_i OUT, 'documents'
    WHILE @i < @count_i
      BEGIN
        EXEC sp_OASetProperty @jResp, 'I', @i
        EXEC sp_OAMethod @jResp, 'StringOf', @encodingFormat OUT, 'documents[i].encodingFormat'
        EXEC sp_OAMethod @jResp, 'StringOf', @content OUT, 'documents[i].content'
        EXEC sp_OAMethod @jResp, 'StringOf', @typeCode OUT, 'documents[i].typeCode'
        SELECT @i = @i + 1
      END

    EXEC @hr = sp_OADestroy @http
    EXEC @hr = sp_OADestroy @queryParams
    EXEC @hr = sp_OADestroy @sbResponseBody
    EXEC @hr = sp_OADestroy @jResp


END
GO

Curl Command

curl -G -d "shipperAccountNumber=Ut%20aliqua"
	-d "content=epod-summary"
	-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/proof-of-delivery

Postman Collection Item JSON

{
  "name": "Electronic Proof of Delivery",
  "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/proof-of-delivery?shipperAccountNumber=Ut aliqua&content=epod-summary",
      "host": [
        "{{baseUrl}}"
      ],
      "path": [
        "shipments",
        ":shipmentTrackingNumber",
        "proof-of-delivery"
      ],
      "query": [
        {
          "key": "shipperAccountNumber",
          "value": "Ut aliqua",
          "description": "DHL Express customer shipper account number"
        },
        {
          "key": "content",
          "value": "epod-summary"
        }
      ],
      "variable": [
        {
          "key": "shipmentTrackingNumber",
          "value": "dolor veniam officia non",
          "description": "(Required) DHL Express shipment identification number"
        }
      ]
    },
    "description": "The electronic proof of delivery service can be used to retrieve proof of delivery for certain delivered DHL Express shipments\n"
  },
  "response": [
    {
      "name": "Electronic Proof of delivery 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/proof-of-delivery?shipperAccountNumber=Ut aliqua&content=epod-summary",
          "host": [
            "{{baseUrl}}"
          ],
          "path": [
            "shipments",
            ":shipmentTrackingNumber",
            "proof-of-delivery"
          ],
          "query": [
            {
              "key": "shipperAccountNumber",
              "value": "Ut aliqua"
            },
            {
              "key": "content",
              "value": "epod-summary"
            }
          ],
          "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      \"encodingFormat\": \"PDF\",\n      \"content\": \"base64 encoded content\",\n      \"typeCode\": \"POD\"\n    },\n    {\n      \"encodingFormat\": \"PDF\",\n      \"content\": \"base64 encoded content\",\n      \"typeCode\": \"POD\"\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/proof-of-delivery?shipperAccountNumber=Ut aliqua&content=epod-summary",
          "host": [
            "{{baseUrl}}"
          ],
          "path": [
            "shipments",
            ":shipmentTrackingNumber",
            "proof-of-delivery"
          ],
          "query": [
            {
              "key": "shipperAccountNumber",
              "value": "Ut aliqua"
            },
            {
              "key": "content",
              "value": "epod-summary"
            }
          ],
          "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/1234567890/proof-of-delivery\",\n  \"title\": \"Bad request\",\n  \"message\": \"Bad request\",\n  \"status\": \"400\"\n}"
    },
    {
      "name": "No electronic proof of delivery 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/proof-of-delivery?shipperAccountNumber=Ut aliqua&content=epod-summary",
          "host": [
            "{{baseUrl}}"
          ],
          "path": [
            "shipments",
            ":shipmentTrackingNumber",
            "proof-of-delivery"
          ],
          "query": [
            {
              "key": "shipperAccountNumber",
              "value": "Ut aliqua"
            },
            {
              "key": "content",
              "value": "epod-summary"
            }
          ],
          "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/1234567890/proof-of-delivery\",\n  \"title\": \"No data found\",\n  \"status\": \"404\"\n}"
    }
  ]
}