Chilkat Online Tools

SQL Server / DHL Express APIs (MyDHL API) / Upload Paperless Trade shipment (PLT) images of previously created shipment.

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>'

    -- Use this online tool to generate code from sample JSON: Generate Code to Create JSON

    -- The following JSON is sent in the request body.

    -- {
    --   "shipmentTrackingNumber": "123456790",
    --   "originalPlannedShippingDate": "2020-04-20",
    --   "accounts": [
    --     {
    --       "typeCode": "shipper",
    --       "number": "123456789"
    --     }
    --   ],
    --   "productCode": "D",
    --   "documentImages": [
    --     {
    --       "content": "base64 encoded image",
    --       "typeCode": "INV",
    --       "imageFormat": "PDF"
    --     }
    --   ]
    -- }

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

    EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'shipmentTrackingNumber', '123456790'
    EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'originalPlannedShippingDate', '2020-04-20'
    EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'accounts[0].typeCode', 'shipper'
    EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'accounts[0].number', '123456789'
    EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'productCode', 'D'
    EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'documentImages[0].content', 'base64 encoded image'
    EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'documentImages[0].typeCode', 'INV'
    EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'documentImages[0].imageFormat', 'PDF'

    EXEC sp_OAMethod @http, 'SetRequestHeader', NULL, 'Content-Type', 'application/json'
    EXEC sp_OAMethod @http, 'SetRequestHeader', NULL, 'Accept', 'application/json'

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

    EXEC sp_OAMethod @json, 'EmitSb', @success OUT, @sbRequestBody

    DECLARE @resp int
    EXEC sp_OAMethod @http, 'PTextSb', @resp OUT, 'PATCH', 'https://api-mock.dhl.com/mydhlapi/shipments/:shipmentTrackingNumber/upload-image', @sbRequestBody, 'utf-8', 'application/json', 0, 0
    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 @json
        EXEC @hr = sp_OADestroy @sbRequestBody
        RETURN
      END

    EXEC sp_OAGetProperty @resp, 'StatusCode', @iTmp0 OUT
    PRINT @iTmp0
    EXEC sp_OAGetProperty @resp, 'BodyStr', @sTmp0 OUT
    PRINT @sTmp0
    EXEC @hr = sp_OADestroy @resp


    EXEC @hr = sp_OADestroy @http
    EXEC @hr = sp_OADestroy @json
    EXEC @hr = sp_OADestroy @sbRequestBody


END
GO

Curl Command

curl -X PATCH
	-u '<Basic Auth Username>:<Basic Auth Password>'
	-H "Content-Type: application/json"
	-H "Accept: application/json"
	-d '{
  "shipmentTrackingNumber": "123456790",
  "originalPlannedShippingDate": "2020-04-20",
  "accounts": [
    {
      "typeCode": "shipper",
      "number": "123456789"
    }
  ],
  "productCode": "D",
  "documentImages": [
    {
      "content": "base64 encoded image",
      "typeCode": "INV",
      "imageFormat": "PDF"
    }
  ]
}'
https://api-mock.dhl.com/mydhlapi/shipments/:shipmentTrackingNumber/upload-image

Postman Collection Item JSON

{
  "name": "Upload Paperless Trade shipment (PLT) images of previously created shipment.",
  "request": {
    "method": "PATCH",
    "header": [
      {
        "key": "Content-Type",
        "value": "application/json"
      },
      {
        "key": "Accept",
        "value": "application/json"
      }
    ],
    "body": {
      "mode": "raw",
      "raw": "{\n  \"shipmentTrackingNumber\": \"123456790\",\n  \"originalPlannedShippingDate\": \"2020-04-20\",\n  \"accounts\": [\n    {\n      \"typeCode\": \"shipper\",\n      \"number\": \"123456789\"\n    }\n  ],\n  \"productCode\": \"D\",\n  \"documentImages\": [\n    {\n      \"content\": \"base64 encoded image\",\n      \"typeCode\": \"INV\",\n      \"imageFormat\": \"PDF\"\n    }\n  ]\n}",
      "options": {
        "raw": {
          "language": "json"
        }
      }
    },
    "url": {
      "raw": "{{baseUrl}}/shipments/:shipmentTrackingNumber/upload-image",
      "host": [
        "{{baseUrl}}"
      ],
      "path": [
        "shipments",
        ":shipmentTrackingNumber",
        "upload-image"
      ],
      "variable": [
        {
          "key": "shipmentTrackingNumber",
          "value": "dolor veniam officia non",
          "description": "(Required) DHL Express shipment identification number"
        }
      ]
    },
    "description": "The upload-image service can be used to upload PLT images to a previously created shipment.  The PLT images for the shipment can be uploaded before the shipment has been physically  collected by DHL courier. However, the original shipment must contain WY as the special service otherwise,  an error will be returned when the customer wants to use the reupload function in this upload-image service.  \t IMPORTANT: Please note that at least 10mins must be given between the initial createShipment request and then  the upload-image request (including subsequent upload-image request). \n"
  },
  "response": [
    {
      "name": "Images uploaded",
      "originalRequest": {
        "method": "PATCH",
        "header": [
          {
            "description": "Added as a part of security scheme: basic",
            "key": "Authorization",
            "value": "Basic <credentials>"
          }
        ],
        "body": {
          "mode": "raw",
          "raw": "{\n  \"shipmentTrackingNumber\": \"123456790\",\n  \"originalPlannedShippingDate\": \"2020-04-20\",\n  \"accounts\": [\n    {\n      \"typeCode\": \"shipper\",\n      \"number\": \"123456789\"\n    }\n  ],\n  \"productCode\": \"D\",\n  \"documentImages\": [\n    {\n      \"content\": \"base64 encoded image\",\n      \"typeCode\": \"INV\",\n      \"imageFormat\": \"PDF\"\n    }\n  ]\n}",
          "options": {
            "raw": {
              "language": "json"
            }
          }
        },
        "url": {
          "raw": "{{baseUrl}}/shipments/:shipmentTrackingNumber/upload-image",
          "host": [
            "{{baseUrl}}"
          ],
          "path": [
            "shipments",
            ":shipmentTrackingNumber",
            "upload-image"
          ],
          "variable": [
            {
              "key": "shipmentTrackingNumber",
              "value": "dolor veniam officia non",
              "description": "(Required) DHL Express shipment identification number"
            }
          ]
        }
      },
      "status": "OK",
      "code": 200,
      "_postman_previewlanguage": "text",
      "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": "text/plain"
        }
      ],
      "cookie": [
      ],
      "body": ""
    },
    {
      "name": "Wrong input parameters",
      "originalRequest": {
        "method": "PATCH",
        "header": [
          {
            "description": "Added as a part of security scheme: basic",
            "key": "Authorization",
            "value": "Basic <credentials>"
          }
        ],
        "body": {
          "mode": "raw",
          "raw": "{\n  \"shipmentTrackingNumber\": \"123456790\",\n  \"originalPlannedShippingDate\": \"2020-04-20\",\n  \"accounts\": [\n    {\n      \"typeCode\": \"shipper\",\n      \"number\": \"123456789\"\n    }\n  ],\n  \"productCode\": \"D\",\n  \"documentImages\": [\n    {\n      \"content\": \"base64 encoded image\",\n      \"typeCode\": \"INV\",\n      \"imageFormat\": \"PDF\"\n    }\n  ]\n}",
          "options": {
            "raw": {
              "language": "json"
            }
          }
        },
        "url": {
          "raw": "{{baseUrl}}/shipments/:shipmentTrackingNumber/upload-image",
          "host": [
            "{{baseUrl}}"
          ],
          "path": [
            "shipments",
            ":shipmentTrackingNumber",
            "upload-image"
          ],
          "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/upload-image\",\n  \"title\": \"Bad request\",\n  \"message\": \"Bad request\",\n  \"status\": \"400\"\n}"
    },
    {
      "name": "No shipment details found",
      "originalRequest": {
        "method": "PATCH",
        "header": [
          {
            "description": "Added as a part of security scheme: basic",
            "key": "Authorization",
            "value": "Basic <credentials>"
          }
        ],
        "body": {
          "mode": "raw",
          "raw": "{\n  \"shipmentTrackingNumber\": \"123456790\",\n  \"originalPlannedShippingDate\": \"2020-04-20\",\n  \"accounts\": [\n    {\n      \"typeCode\": \"shipper\",\n      \"number\": \"123456789\"\n    }\n  ],\n  \"productCode\": \"D\",\n  \"documentImages\": [\n    {\n      \"content\": \"base64 encoded image\",\n      \"typeCode\": \"INV\",\n      \"imageFormat\": \"PDF\"\n    }\n  ]\n}",
          "options": {
            "raw": {
              "language": "json"
            }
          }
        },
        "url": {
          "raw": "{{baseUrl}}/shipments/:shipmentTrackingNumber/upload-image",
          "host": [
            "{{baseUrl}}"
          ],
          "path": [
            "shipments",
            ":shipmentTrackingNumber",
            "upload-image"
          ],
          "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/upload-image\",\n  \"detail\": \"Operation not possible since shipment information not found\",\n  \"title\": \"Not found\",\n  \"message\": \"Not found\",\n  \"status\": \"404\"\n}"
    },
    {
      "name": "Unprocessable Entity",
      "originalRequest": {
        "method": "PATCH",
        "header": [
          {
            "description": "Added as a part of security scheme: basic",
            "key": "Authorization",
            "value": "Basic <credentials>"
          }
        ],
        "body": {
          "mode": "raw",
          "raw": "{\n  \"shipmentTrackingNumber\": \"123456790\",\n  \"originalPlannedShippingDate\": \"2020-04-20\",\n  \"accounts\": [\n    {\n      \"typeCode\": \"shipper\",\n      \"number\": \"123456789\"\n    }\n  ],\n  \"productCode\": \"D\",\n  \"documentImages\": [\n    {\n      \"content\": \"base64 encoded image\",\n      \"typeCode\": \"INV\",\n      \"imageFormat\": \"PDF\"\n    }\n  ]\n}",
          "options": {
            "raw": {
              "language": "json"
            }
          }
        },
        "url": {
          "raw": "{{baseUrl}}/shipments/:shipmentTrackingNumber/upload-image",
          "host": [
            "{{baseUrl}}"
          ],
          "path": [
            "shipments",
            ":shipmentTrackingNumber",
            "upload-image"
          ],
          "variable": [
            {
              "key": "shipmentTrackingNumber",
              "value": "dolor veniam officia non",
              "description": "(Required) DHL Express shipment identification number"
            }
          ]
        }
      },
      "status": "Unprocessable Entity (WebDAV) (RFC 4918)",
      "code": 422,
      "_postman_previewlanguage": "json",
      "header": [
        {
          "key": "Content-Type",
          "value": "application/json"
        }
      ],
      "cookie": [
      ],
      "body": "{\n  \"instance\": \"/expressapi/shipments/1234567890/upload-image\",\n  \"detail\": \"#/productCode: expected minLength: 1, actual: 0\",\n  \"title\": \"Validation error\",\n  \"message\": \"Unprocessable Entity\",\n  \"status\": \"422\"\n}"
    }
  ]
}