Download Booking Documents
In this guide:
Introduction
Prerequisites
Querying Booking for Documents
Downloading a Document file
Introduction
Bookings in the system can have documents attached. For instance, we can attach Insurance Document or Certificate of Origin.
The API allows for querying and downloading of booking documents uploaded via UI.
Prerequisites
You need to have a Booking with at least one document uploaded.
Querying Booking for Documents
To fetch the list of documents assigned to the booking, we will perform following Boooking query with nested BookingDocument list in API console. How to perform GraphQL queries you can read more here.
POST /graphql
Query
query($zencargoReferences: [String!]){
bookings(zencargoReferences: $zencargoReferences){
nodes{
bookingDocuments{
documentType
description
assetUrl
}
}
}
}
We can use Booking filters to find documents for a specific booking. For instance, to find documents for "ZTEST-1" booking we need to provide following variables to the query:
{ "zencargoReferences": ["ZTEST-1"] }
JSON response
{
"data": {
"bookings": {
"nodes": [
{
"bookingDocuments": [
{
"documentType": "insurance-document",
"description": "Cargo insurance",
"assetUrl": "https://ztest.api.production.zencargo.com/api/booking_document_file/1acf0766-3f34-474e-a38f-dab5309011cc/Cargo%20insurance.png"
}
]
}
]
}
}
}
Downloading a Document file
To download a document file you need to follow its assetUrl link. Please note you may be redirected at this stage, so your
client may need to be configured to handle HTTP redirects. Below is an example of downloading with CURL (-L flag enables redirects).
curl -L -X GET \
https://ztest.api.production.zencargo.com/api/booking_document_file/1acf0766-3f34-474e-a38f-dab5309011cc/Cargo%20insurance.png \
-H 'Authorization: Basic ODAxZGQzNzUtYTdlZS00NzQwLWE3OGYtMzdiM2ZjYWQ2MjFiOjI3Yks3UlMxQ21uZVhRY3g1YnBx' \
--output downloaded.png