This guide is intended for developers who want to integrate their own applications with PortConnect.
What is the PortConnect API?
The PortConnect API (Application programming interface) is a new, more modern way of sending and retrieving data from PortConnect. PortConnect receives container event information 24 hours a day from our partner ports Ports of Auckland, Port of Tauranga and the Timaru Container Terminal. Events are received at least every ten minutes.
All API operations work for all partner ports.
Scheduled vessels: Returns scheduled vessel information, including expected time of arrival and departure.
Containers: Returns the latest detailed information for specified containers. Up to 10 containers can be searched at any one time.
Container event subscriptions: This is a suite of operations which allows container events to be sent to any end point you specify.
In order to use the PortConnect API, you need to sign up to our Microsoft APIM based developer portal, which is located at https://developer.portconnect.io. Signing up is free of charge.
Once signed up, you will be able to subscribe to either the Full Access or Trial product variations for the API, via the "Products" menu. Both products contain the same API end points, and both products require you to accept the PortConnect API terms and conditions of use.
The Trial version restricts the number of requests that you can make to an API end point to 100 calls within a 24 hour period. Full Access has no restrictions on the number of requests you can make, however some charges may apply.
Once the subscription is confirmed, an API key will be generated. You can see your API key from the profile menu.
All calls to the PortConnect API must include either the primary or secondary key in the header Ocp-Apim-Subscription-Key. You can regenerate your subscription key any time you choose.
The Developer Portal is a useful tool that provides documentation for end points and auto-generated definitions for API object models. It also includes a test function that allows you to test API calls against our live data.
The PortConnect API endpoint to use from your client application is https://api.portconnect.io. The developer portal can generate sample code in a number of different programming languages:
Feel free to use other API tools such as Postman. See the resources section below for some Postman tests you can use.
This end point returns vessels that are scheduled to arrive at our partner ports. It can also be used to query vessels currently in port and vessels that have recently departed. This data is updated approximately every 15 minutes.
If you have a single container visit id, which is a PortConnect reference to a unique container visit, you can also retrieve container data by putting the id in the path of the container visits uri. For instance this request returns the same information as the above example:
Use container event subscriptions, or "subscriptions", when you want PortConnect to send you an http (“webhook”) callback when a particular container event occurs. This is an alternative to the email / xml based notifications which are also operated by PortConnect.
To receive callbacks for particular container events, you need to create a subscription by posting a request the subscriptions endpoint. Version 1 requests a single container visit event type code per request, Version 2 supports multiple container visit event type codes in a single request. Version 2 also supports the use of “ALL” to subscribe to all events for one or more containers.
Each subscription relates to a single event type, however multiple containers can be included.
For version 1, a new subscription is created for every unique combination of PortCode, Category, EventTypeCode and FacilityCode . If a subscription already exists for a particular combination, then containers are added to that subscription.
Subscription V1 Create Example
For example, the following subscription request will result in a webhook callback when any of the three specified import containers become available:
Version 2 of the subscription API supports multiple container event types, as well as the of “ALL” to subscribe to all possible events. Event type codes are supplied as an array.
For version 2, a new subscription is created for every unique combination of PortCode, Category and FacilityCode . If a subscription already exists for a particular combination, then containers are added to that subscription.
Facility codes are optional and relate to the port facility where the event takes place. If no facility code is specified, then webhook callbacks will be sent whenever the event occurs, regardless of the location. For instance, if a subscription is created for an export "gate in", and the container is gated in to both an inland port and the sea port, then two gate in events will be sent as webhook callbacks.
Only some event type codes support the use of the facility code, in all other cases a null value should be supplied. Refer to the table below.
User Defined References
We only permit one userDefinedReference per container. This is a maximum of 50 characters and designed to support container visit identifiers in calling systems.
The user defined reference will be included in the webhook callback payload against the specified container.
If you create a new subscription with a different user defined reference, it will overwrite the existing subscription including the user defined reference.
If you have already received events against the first subscription you will receive future events against the new subscription with the new user defined reference.
Valid event type codes are shown in the following table, along with event values that are returned in the webhook callback payload:
Supported Facility Codes
Event Value 1
Event Value 2
Supported Facility Codes
Event Value 1
Event Value 2
Container record becomes live in PortConnect system
NZAKL, NZTRG, NZTIU, NZLYT
Availability Advice (Container is fully released)
NZAKL, NZTRG, NZTIU, NZLYT
Availability Advice cancelled
NZAKL, NZTRG, NZTIU, NZLYT
Discrepancy: Booking does not match Preadvise/Gate-in details
The response includes a subscription id. You can use the subscription id as a handle for future get, update and delete calls.
Each container includes a subscriptionContainerId, which you can use as a reference as this is passed back in the webhook payload.
The expiration datetime for the container is also shown. Each container in a subscription has an expiration date of the creation date plus 60 calendar days. After this time no callbacks will be made for the container, and the container is no longer returned when querying the subscription. Calling the subscription create event with the same container number will extend the expiration datetime.
Webhook Callback Payload
When PortConnect detects an event that matches your subscription, it will send an HTTP POST to your specified end point. Event matching happens when new events are processed into the PortConnect system,and also when the subscription is first created (for events that have occurred for a currently active container).
For testing purposes, you may find it useful to create a webhook uri using Request Bin or similar. This allows you to easily view the webhook payload.
Multiple events may be returned in a single payload, as in this example:
Included as a header key of the callback is a value X-WebhookToken which you can choose to validate as the webhookToken value specified when creating the subscription. This is designed to help protect your webhook end point from unauthorised access.
If you require additional information about the container visit, call the containerVisitUri returned. Refer to the Container Visits section for details.
Searching All Subscriptions
You can search for all active container event subscriptions for your API user by invoking a GET action on the subscriptions end point with no parameters:
Subscription V1 GET All Example
Subscription V1 GET All Response
The response payload lists all of you current subscriptions, for example:
A single subscription can be updated by sending a patch to the subscriptions end point, specifying the subscription id in the uri. Any containers supplied replace all existing containers in the subscription.
You can update the port code, category, event type and facility codes if you wish, but this isn't recommended as a different subscription id can result, possibly causing confusion.
For instance, subscription id 35 can be updated to include containers:
A return code of 204 indicates the subscription has been deleted successfully.
Use the Export Pre-Advice end point to submit, retrieve and delete export pre-advice programmatically on behalf of a PortConnect user. Contact our User Support to be granted access to this end point. PortConnect will associate an API user id with a specific PortConnect user so that export pre-advice can be submitted on behalf of that user.
Only the Ports of Auckland and the Port of Tauranga support Export Pre-advice submitted via PortConnect.
Submitting an Export Pre-advice
In order to understand the Export Pre-advice submission, some familiarity with the Export Pre-advice User Guide is recommended. This details how export pre-advice submitted via the PortConnect website. The structure of the API is conceptually very similar to this screen, comprising a header with a list of containers being submitted.
This is a basic example of an export pre-advice message comprising the header with a single container record. Additional properties allow the submission of refrigeration, vent, hazardous and over gauge settings, and these are detailed in the developer test portal.
A return code of 201 Created results when the export pre-advice request is submitted. Importantly, the response payload needs to be examined to determine if both the overall export pre-advice was created successfully, along with the associated container records. For instance the above request will return success flags at the header and the container level:
However, should the requiredTemperature value be set to -50 in the example above, then the following is returned:
Export pre-advice partial failure
"Temperature too high/low for the selected commodity (Range: -5.0 to 2.0). Change commodity or contact Terminal"
Validation of the export pre-advice request is extensive. Validation messages are generated at the PortConnect API level and also from the partner port, such as the example above. Validation message include:
Must provide a valid booking
Load Port must match the booking
Load Port must be valid
Line Operator code must be valid
Line Operator code must match the booking
Vessel Visit must match the booking
Discharge Port must match the booking
Reefer ISO type containers must have a Temperature (unless specified as a Non-Operating Reefer)
Freight Kind (Full vs Empty) must match the booking
Reefer temperatures must match the booking
Conditioning details must match the booking. Conditioning details include: Humidity %, Vent value, Vent Type, O2% and CO2%
Hazard UN Codes must match the booking
Total Pre-Advised Containers must not exceed the booking quanta (count)
Seal Type must be valid
Common to the export pre-advice screen and B2B export pre-advice functions, the export pre-advice api supports the use of email notifications. By specifying one or more email addresses in the notificationEmails property, an email is generated which confirms which containers are successfully pre-advised. This is an optional property.
The emails contain two boxes, a green box in which successful containers will display and a red box in which unsuccessful containers will display. Containers in the green box show all the key details of the container. You can use this email to share the details with other parties. Any unsuccessful containers will show in the red box with a comment about why the Pre-Advice was not successful. The same message also appears on the PortConnect website.
Subsequent calls using the same header information will update the container list, overwriting the previous container list with the new values.
Calls made via the API are reflected in the PortConnect Export Pre-advice screen. For instance, if containers are added or removed, then this will be reflected on the Export Pre-Advice screen. PortConnect also has the capability to generate an API call from the Export Pre-advice screen, which is useful for more complex scenarios. Contact user support to find out more about this.
Codes to use for various properties are listed on this page.
Retrieving an Export Pre-Advice
An export pre-advice can be retrieved using a GET to the export-preadvices end point, specifying the port and user reference in the URL, and optionally a container number. Specifying the container number restricts the response to only the export pre-advice header and the container number.
The following example returns all information relating to the export pre-advice submitted above.
Success will result in a return code of 204 No Content.
Any errors in the request payload will result in a return code of 400 Bad request. Further information will be supplied in the message payload.
Shipping Line Endpoints
PortConnect offers the following end points exclusively for the use of shipping lines. Shipping line developers will need to contact our user support team to have access to these endpoints. PortConnect associates an API user id with a specific line operator, so that storage pre-advice and booking api calls are associated with the correct shipping line. It isn't possible to send or retrieve information in relation to other shipping lines.
Storage Pre-Advice (Ports of Auckland Only)
Shipping lines have the ability to pre-advise the arrival of storage containers to the LINK facility at the Ports of Auckland via this end point. Containers cannot be gated in to the LINK facility unless they have been pre-advised in advance.
Import containers where the LINK facility has been specified by the shipping line as the return depot will automatically have a pre-advice generate for them at gate out. This applies to import containers at both Ports of Auckland and Port of Tauranga, including associated inland ports.
Storage pre-advice should be submitted for the LINK facility when:
An import has been gated out where an empty return depot other than LINK was specified or;
An import has been gated out from a port other the Ports of Auckland or Port of Tauranga
Submitting a Storage Pre-Advice
A storage pre-advice can be submitted by posting to the lines/storage-pre-advices endpoint.
At this time the only supported value for portCode is "NZAKL", and the only supported value for receiveLocation is "LNK"
Success will result in a return code of 201 Created.
Any errors will result in a return code of 400 Bad request. Further information will be supplied in the message payload.
Container bookings are used by PortConnect to validate the creation of export pre-advice messages.
Bookings have traditionally been supplied via EDIFACT messages such as COPARN. PortConnect has created a set of endpoints that allows shipping lines to submit, retrieve and delete bookings from the PortConnect system.
Submit a Booking
A booking consists of top level booking information and one or more booking items. Each booking item can optionally have hazardous and conditioning information.