JSON:API Guide
Terminal49’s API follows the JSON:API specification, a standard for building APIs in JSON. This guide will help you understand the key concepts and how to work with our API effectively.What is JSON:API?
JSON:API is a specification for how a client should request resources to be fetched or modified, and how a server should respond. It’s designed to minimize both the number of requests and the amount of data transmitted between clients and servers.The Terminal49 API conforms to the JSON:API v1.0 specification. This standardization makes our API more predictable and easier to work with once you understand the patterns.
Why Terminal49 Uses JSON:API
Terminal49 uses the JSON:API specification for a number of important reasons that directly benefit developers working with shipping and container tracking data:Standardized Relationships for Complex Shipping Data
Shipping data is inherently relational - containers belong to shipments, shipments have transport events, containers have tracking events, and all these relate to carriers, terminals, and vessels. JSON:API excels at representing these complex relationships through:- Consistent Structure: Every response follows the same pattern, making data predictable and easy to parse
- Clear Resource Relationships: Explicit definition of how resources like shipments, containers, and events relate to each other
- Compound Documents: The ability to include related resources in a single request, eliminating the need for multiple API calls
Efficient Data Loading for Shipping Operations
JSON:API’s approach to related data is particularly valuable for shipping operations:- Reduced API Calls: Get containers and their shipments in a single request
- Minimized Latency: Critical for time-sensitive logistics operations
- Lower Bandwidth: Only request the related objects you need, when you need them
Standardized Error Handling
JSON:API provides a consistent format for error responses, making it easier to:- Identify Issues: Clearly pinpoint which field or relationship has an error
- Implement Error Handling: Write consistent error handling logic across your application
- Debug Problems: Receive detailed information about what went wrong and why
Client Libraries
Instead of writing custom code to parse JSON:API responses, you can leverage ready-made libraries for most programming languages:JavaScript
JSON:API libraries for JavaScript
Ruby
jsonapi-rb for Ruby applications
Python
JSON:API libraries for Python
PHP
PHP client libraries for JSON:API
Go
Go implementations of JSON:API
Java
Java frameworks for JSON:API
- Automatic Relationship Resolution: Easily navigate from shipments to containers and events without manual mapping
- Type Conversion: Convert API responses into native language objects/models
- Query Building: Construct complex API queries with simple, intuitive methods
- Consistent Updates: Standardized methods for creating and updating resources
- Error Handling: Built-in support for JSON:API error formats
JSON:API Structure
Basic Resource Objects
All Terminal49 API responses follow this general structure:The primary resource or collection of resources.
A unique identifier for the resource.
The resource type (e.g., “shipment”, “container”, “tracking_request”).
The resource’s properties (e.g., numbers, dates, status values).
References to related resources (e.g., a shipment’s containers).
Collections of Resources
When requesting multiple resources, the response structure is:Contains non-standard meta-information, like counts or pagination details.
Contains links for pagination or related operations.
Working with JSON:API in Terminal49
Creating Resources
When creating a resource (like a tracking request), your request should follow this format:- The
typefield is required and must match the expected resource type - All properties go inside the
attributesobject - You don’t specify an
idfor new resources (the server assigns it)
Including Related Resources
One powerful feature of JSON:API is the ability to include related resources in a single request using theinclude parameter:
Contains all the related resources referenced in the main resource’s relationships.
Error Handling
Error responses also follow a standard format:The HTTP status code relevant to the error.
A short, human-readable summary of the problem.
A human-readable explanation of the specific error.
An object containing references to the source of the error. The
pointer field typically contains a JSON Pointer to the specific field that caused the error.Tips for Working with Terminal49’s JSON:API
-
Always include the correct
Content-Typeheader in your requests: -
Use the
includeparameter to reduce the number of API calls when you need related resources -
When creating or updating resources, remember that all properties must be inside the
attributesobject -
For filtering collections, use the filter query parameter with the attribute name:
-
Pagination is handled via
page[number]andpage[size]query parameters
For a deeper understanding of JSON:API, check the official specification or our In-Depth Guides on working with Terminal49’s API.