Parcel Label API

This API can be used to generate and return a label for an order generated in DI


Content

Setup



Example



Example

Username (see Authentication section)

wsfoobar

Password (see Authentication section)

a-very-very-long-password

  • The user is a web service user

  • The user has access to the web service for labels

  • The user has access to the shop registered on the parcel

Environments / endpoints

TEST GET

https://staging-ws.di.no/ws/json/parcel/label/v-1/labels/{identifier}/{labelType}

PRODUCTION GET

https://ws.di.no/ws/json/parcel/label/v-1/labels/{identifier}/{labelType}

Authentication

This endpoint requires the user to be authenticated. Refer to the documentation here for more information on how to obtain a valid token to use in your request. 

Making a request

The shipment must be registered before the label is available. If registering a shipment (e.g. through the Parcel Booking API ) and fetching label is done in one action we recommend you verify a successful respons from the registration before you make a request to the label API. If registrering the parcel is done through file or other formats we recommend a longer latency.

Request header

key

value example

comment

key

value example

comment

Authorization

Bearer $SECRET_WS_TOKEN"

see Authentication

Content-Type

application/json



Accept

application/pdf
OR
image/svg+xml
OR
application/zpl
OR
image/png

label in pdf format
OR
label in svg format 
OR
label in zpl format
OR
label in png format

Accept

application/json

warnings/ error messages in json format

 

Request path parameters

key

value example

comment

key

value example

comment

identifier

(00)370724760010119754

can be either a trackingReference or a shipmentId.

labelType

unified-large

What kind of label that is wanted. The type determines both layout and size of the label. Currently the following types are supported:

  • "unified-large" - this label measures 102 mm x 192mm

    • ZPL labels deviates from this standard, it measures 4x9 inches ( 101,6mm x 228,6 mm) in 200dpi

 

Curl request example

with application/pdf response format

curl --request GET --url https://staging-ws.di.no/ws/json/parcel/label/v-1/labels/00370724760010119754/unified-large \ --header "authorization: Bearer $SECRET_WS_TOKEN" \ --header 'content-type: application/json' \ --header 'accept: application/pdf,application/json' \

Response

General notes for API response

The API will respons with a file in the specified file format.

  • If shipmentId is specified the response will return a file containing one page pr. item for that shipment

  • If trackingReference is specified the response will return a file containing one page for that item

  • ZPL labels measures 4x9 inches ( 101,6mm x 228,6 mm) in 200dpi

  • Response time for ZPL format is significantly slower than other formats

Error handling

API requests that result in errors will return an appropriate HTTP status code to help you identify the type of error. You can use the table below to understand what each code means. og search online with the HTTP status code. The HTTP error keys used are based on the standard, and therefore available online (Tips to search “HTTP code XXX”)

In addition to HTTP status there may be more details in the errorKey field. Error Keys can be added at a later stage, clients should handle this as well as an empty value for errorKey.

HTTP Status code

Text

Description

HTTP Status code

Text

Description

400

Client or Validation Error

The request body/query string is not in the correct format.

401

Authentication Failure

Indicates that the Authorization header is either missing or incorrect. You can learn more about the Authorization header here.

403

Access denied

This indicates that the agent whose credentials were used in making this request was not authorized to perform this API call. It could be that you do not have access to the shop or transportsolution you provided in your request. If you believe this is a mistake, please reach out to your contact so it can be rectified.

405

Method not allowed

This API request used the wrong HTTP verb/method. For example a PUT request will result in this error.

4xx

Client error

Generally receiving an error code that starts with 4 indicates that the client needs to change something.

500

Unexpected Server Error

Oops! This may indicates an error on our side. Please try again, if the error continues notify your contact person

Error response

In addition to the HTTP status code, most errors will also return a response body that contains more information to help you debug the error. A sample error response is shown below. The format of the error response body is explained after the example.

Sample error

{ "statusCode": 401, "errorKey": "authentication.missing", "errorMap": {} }

Field

Description

Field

Description

statusCode

The HTTP code associated with this error.

errorKey

A machine parseable error code.

errorMap

Additional details pertaining to the error.

Error keys

error key

status code

error key

status code

required.identifier

400

unsupported.labelType

400

no.access.api

403

not.found

404

service.point.not.set.for.order

206

invalid.service.point.on.order

206

cannot.find.routingcode.for.order

206

no.access.shop.id

403

unsupported.transportProduct

501

internal.error

500