Shipment documents

The Shipments platform can automatically generate customs documentation, and hazard labels for shipments.

Once a shipment is allocated, Shipments will automatically determine what documentation is required for it. Shipments API can generate the following document types:

  • cn22 - Customs documentation. Only generated for applicable international shipments.
  • cn23 - Customs documentation. Only generated for applicable international shipments.
  • commercial_invoice - Customs documentation. Only generated for applicable international shipments.
  • hazard_label - Generated for shipments containing dangerous goods.
  • collection_note - A driver’s manifest for the shipment. Generated for all shipments.

Shipments API offers two endpoints to retrieve documents once they have been generated:

  • Get Document retrieves a specific document.
  • Get Customs Documents retrieves all customs documents (that is, CN22, CN23, and commercial invoice documents) that have been generated for a particular shipment.

Getting a specific shipment document

To call Get Document, send a GET request to https://api.sorted.com/pro/documents/{shipment_reference}/{document_type}, where {shipment_reference} is the unique reference of the shipment that the document belongs to and {document_type} is the type of document you want to return for that shipment.

If the specified shipment has a document of the specified type, then Shipments returns a document object representing that document. Otherwise, an error is returned.

Getting all of a shipment’s customs documents

To call Get Customs Documents, send a GET request to https://api.sorted.com/pro/documents/{shipment_reference}, where {shipment_reference} is the unique reference of the shipment that you want to get customs documents for.

If the specified shipment has customs documents (that is, it is an international shipment), then Shipments returns a list of document objects representing those documents. Otherwise, an error is returned.

The document response

Both Documents endpoints return document objects. Get Document returns a single document, while Get Customs Documents returns a list.

The document object has four properties:

  • file - A base64-encoded byte array representing the file content.
  • content_type - The document’s format (e.g. application/pdf).
  • document_type - The type of document (e.g. commercial_invoice).
  • dpi - The document’s resolution in DPI.

Examples

The example below shows a successful Get Document request for the cn22 document associated with shipment sp_00670175533382557003917067812864. Shipments returns a document object representing that document. In this example, the Base64 data returned has been removed for clarity.

Get document request

  GET https://api.sorted.com/pro/documents/sp_00670175533382557003917067812864/cn22
  

Get document response

  {
  "file": {Base64 file contents},
  "content_type": "application/pdf",
  "document_type": "cn22",
  "dpi": 203
}
  

The example below shows a successful Get Customs Documents request for all customs documents associated with shipment sp_00670175533382557003917067812864. Shipments returns a list of document objects representing the cn22, cn23, and commercial_invoice documents associated with that shipment. In this example, the Base64 data returned has been removed for clarity.

Get customs documents request

  GET https://api.sorted.com/pro/documents/sp_00670175533382557003917067812864
  

Get customs documents response

  [
  {
    "file": {Base64 file contents},
    "content_type": "application/pdf",
    "document_type": "cn22",
    "dpi": 203
  },
  {
    "file": {Base64 file contents},
    "content_type": "application/pdf",
    "document_type": "cn23",
    "dpi": 203
  },
  {
    "file": {Base64 file contents},
    "content_type": "application/pdf",
    "document_type": "commercial_invoice",
    "dpi": 203
  }
]
  

Using the label data

Once you have downloaded the file data, you will need to decode the file’s Base64 in order to view the label itself. If you are unsure how to do so, see the MDN docs for more information.

Next steps