# parcelLab API - Promise

# API Description

## Overview

Use this API to interact with the parcelLab platform. It is currently in preview. For a reference of our current API, please refer to the [API documentation](https://how.parcellab.works/docs/using-connect/parcellab-api).

The API v4 allows for enhanced and more standardized interaction with our platform. It does however not yet cover all of the features of our v1/v2 APIs.

## Integrate with a coding agent

Use the [parcelLab v4 integration skill](https://product-api.parcellab.com/.well-known/agent-skills/parcellab-v4-integration/SKILL.md) with Codex, Claude Code, or another agent that supports Agent Skills. It maps OMS order feeds, delivery estimates, order status, returns, size guidance, and conversational agents to the live OpenAPI specification and public documentation. It recommends parcelLab's embedded UI for standard storefront journeys.

Run this command in your application project:

```sh
npx skills add https://product-api.parcellab.com \
  --skill parcellab-v4-integration --agent codex claude-code
```

Select only the agents you use. Then ask your agent to use `parcellab-v4-integration` to implement your integration. Keep API tokens in your application's secret store.

## Authentication

Most endpoints in this API need authentication, unless otherwise stated. The authentication is done using the `Authorization` header with the value `Parcellab-API-Token <token>`. You can generate the token in our portal, or ask our support team for one. The token needs to be base64 encoded together with the account ID, like: `base64encode(account_id:token)`. Here is an example of how to do it in Python:

```python
import base64
base64.b64encode(b'account_id:token').decode('utf-8')
```

## Errors

The API uses standard HTTP status codes to show the success or failure of a request. In case of an error, the response body will contain a JSON object with the following structure:

```json
{
  "type": "client_error",
  "errors": [
    {
      "code": "error_code",
      "detail": "Error message.",
      "attr": "Optional additional information."
    }
  ]
}
```

### 401 Unauthorized

The API returns these errors with the status code 401 when the authentication fails. It also returns them when a request does not include the authentication information. Here are the 2 possible errors.

```json
{
  "type": "client_error",
  "errors": [
    {
      "code": "authentication_failed",
      "detail": "Incorrect authentication credentials.",
      "attr": null
    }
  ]
}
```

```json
{
  "type": "client_error",
  "errors": [
    {
      "code": "not_authenticated",
      "detail": "Authentication credentials were not provided.",
      "attr": null
    }
  ]
}
```

### 403 Forbidden

The API returns this error when the authentication is correct but does not allow the request. For example, an API token with only the `read` scope gets this error on a POST. Here is how it looks:

```json
{
  "type": "client_error",
  "errors": [
    {
      "code": "permission_denied",
      "detail": "You do not have permission to perform this action.",
      "attr": null
    }
  ]
}
```

### 405 Method Not Allowed

The API returns this error when you call an endpoint with an unexpected HTTP method. For example, if updating a user needs a POST request and you send a PATCH instead, you get this error. Here is how it looks:

```json
{
  "type": "client_error",
  "errors": [
    {
      "code": "method_not_allowed",
      "detail": "Method “patch” not allowed.",
      "attr": null
    }
  ]
}
```

### 406 Not Acceptable

The API returns this error if you send an `Accept` header with a value other than `application/json`. Here is how the response would look:

```json
{
  "type": "client_error",
  "errors": [
    {
      "code": "not_acceptable",
      "detail": "Could not satisfy the request Accept header.",
      "attr": null
    }
  ]
}
```

### 415 Unsupported Media Type

The API returns this error when the request content type is not JSON. Here is how the response would look:

```json
{
  "type": "client_error",
  "errors": [
    {
      "code": "not_acceptable",
      "detail": "Unsupported media type “application/xml” in request.",
      "attr": null
    }
  ]
}
```

### 500 Internal Server Error

The API returns this error when the server encounters an unexpected error. Here is how the response would look:

```json
{
  "type": "server_error",
  "errors": [
    {
      "code": "error",
      "detail": "A server error occurred.",
      "attr": null
    }
  ]
}
```


## Base URL

| URL | Description |
| --- | --- |
| https://api.parcellab.com | API server |


## Authentication

| Name | Type | Scheme | Bearer Format | Description |
| --- | --- | --- | --- | --- |
| HeaderToken | apiKey |  |  | Send `Authorization: Parcellab-API-Token <encoded-token>`.

`<encoded-token>` = `base64(account_id:token)` as provided in the portal. |
| OAuth2Authentication | http | bearer | JWT | Unbound access tokens use Authorization: Bearer <token>. DPoP-bound tokens use Authorization: DPoP <token> and a DPoP proof header signed with the bound key for each request. Supported proof algorithms: ES256 and RS256. |

## Operations

### GET /v4/promise/prediction/predict/

Generate prediction
If IP lookup fails or no delivery methods match, Backend uses fallback_country_iso3 when supplied. Matching IP methods take priority, even in another country. An empty prediction list after method selection does not trigger a fallback.

IP requests are limited to 60 per minute per caller IP. Excess requests return HTTP 429 with Retry-After. Country and postal code requests do not use this limit.
#### Parameters

| Name | In | Type | Required | Description |
| --- | --- | --- | --- | --- |
| account | query | integer | True | Account ID |
| calibration | query | ['string', 'null'] |  | Set to true, to indicate that the prediction should be done based on the current, not yet published, promise configuration

* `conservative` - conservative
* `balanced` - balanced
* `aggressive` - aggressive |
| courier | query | ['string', 'null'] |  | The logistics courier to be used. Defaults to returning all configured couriers. |
| destination_country_iso3 | query | ['string', 'null'] |  | ISO 3166-1 alpha-3 code of the destination country. Supply either this field or destination_ip_address. |
| destination_ip_address | query | ['string', 'null'] |  | Shopper IPv4 or IPv6 address for an estimated delivery location. Do not combine with destination_country_iso3 or destination_postal_code. IP lookup does not confirm a delivery address. |
| destination_postal_code | query | ['string', 'null'] |  | Postal code of the destination. Requires destination_country_iso3. |
| dispatch_now | query | boolean |  | Forces the forecasted delivery date to skip any warehouse calculation and generate a prediction if the parcel is shipped at the moment of the API call, if set to 'true' |
| draft | query | ['boolean', 'null'] |  | Set to true, to indicate that the prediction should be done based on the current, not yet published, promise configuration |
| fallback_country_iso3 | query | ['string', 'null'] |  | Optional ISO 3166-1 alpha-3 country for IP destinations. Used when IP lookup fails or no delivery methods match. Matching IP delivery methods take priority. The fallback uses no IP postal code or region. |
| global_courier_service_level | query | ['string', 'null'] |  | Filter by the parcelLab global service level: standard, expedited, express, or unused. Combined with service_level when both are supplied. Requires Backend support for globalCourierServiceLevel.

* `standard` - standard
* `unused` - unused
* `express` - express
* `expedited` - expedited |
| language_iso2 | query | ['string', 'null'] |  | Language code to use for localization. Plain language codes such as en or es are supported. Locale codes with country suffixes such as es_US or es-US are also accepted. |
| now_override | query | ['string', 'null'] |  | Locks the prediction for a specified request date as a ISO 8601 date and time in UTC format like 2022-06-10T06:42:00Z. Defaults now to the current time if omitted, which is required for production usage.  |
| service_level | query | ['string', 'null'] |  | The courier service level mapped in your Promise configuration (for example: express delivery). Defaults to returning all courier service levels. |
| tag | query | ['string', 'null'] |  | Tag to target prediction adjustment rule |
| warehouse | query | ['string', 'null'] |  | The warehouse the delivery shipped from (input field: key). Defaults to the default warehouse for the destination. |
#### Responses

##### 200

###### application/json

```yaml
properties:
  request_id:
    title: Request Id
    type: string
  success:
    title: Success
    type: boolean
  prediction:
    items:
      properties:
        id:
          description: Delivery Method ID
          title: Id
          type: string
        warehouse:
          description: Warehouse ID
          title: Warehouse
          type: string
        courier:
          description: parcelLab courier code, e.g. ups
          title: Courier
          type: string
        courier_name:
          description: Pretty courier name
          title: Courier Name
          type: string
        courier_alias:
          description: Retailer internal courier code
          items:
            type: string
          title: Courier Alias
          type: array
        courier_service_level:
          description: All specified aliases for the service level
          items:
            type: string
          title: Courier Service Level
          type: array
        global_courier_service_level:
          enum:
          - standard
          - unused
          - express
          - expedited
          - unknown
          title: CourierServiceLevelEnum
          type: string
          $ref: '#/components/schemas/CourierServiceLevelEnum'
          description: parcelLab global courier service level for the delivery method.
            Unrecognized Backend values are returned as unknown.
        prediction:
          properties:
            min:
              description: 'The minimum number of expected courier working days until
                delivery. Note: The value for minimum and maximum can be equal.'
              title: Min
              type: integer
            max:
              description: 'The maximum number of expected courier working days until
                delivery. Note: The value for minimum and maximum can be equal.'
              title: Max
              type: integer
            likely:
              description: The most likely number of expected courier working days
                until delivery.
              title: Likely
              type: integer
            send_date:
              description: The date of dispatch as per warehouse configuration.
              format: date
              title: Send Date
              type: string
            earliest_date:
              description: The earliest expected delivery date taking into consideration
                working days of the courier, holidays in the destination, and warehouse
                cut-off and handling times.
              format: date
              title: Earliest Date
              type: string
            latest_date:
              description: The latest expected delivery date taking into consideration
                working days of the courier, holidays in the destination, and warehouse
                cut-off and handling times.
              format: date
              title: Latest Date
              type: string
            most_likely_date:
              description: The most likely individual date of delivery.
              format: date
              title: Most Likely Date
              type: string
            earliest_locale:
              description: Localized representations of the earliest expected delivery
                date in the specified format.
              title: Earliest Locale
              type: string
            latest_locale:
              description: Localized representations of the latest expected delivery
                date in the specified format.
              title: Latest Locale
              type: string
            most_likely_locale:
              description: Localized representations of the most likely delivery date
                in the specified format.
              title: Most Likely Locale
              type: string
            cutoff:
              description: The time in minutes until cut-off for the estimated delivery
                dates.
              title: Cutoff
              type: integer
            cutoff_locale:
              description: Localized representation of the cut-off time.
              title: Cutoff Locale
              type: string
          required:
          - min
          - max
          - likely
          - send_date
          - earliest_date
          - latest_date
          - most_likely_date
          - earliest_locale
          - latest_locale
          - most_likely_locale
          - cutoff
          - cutoff_locale
          title: PredictionDetails
          type: object
          $ref: '#/components/schemas/PredictionDetails'
          description: The prediction details
      required:
      - id
      - warehouse
      - courier
      - courier_name
      - courier_alias
      - courier_service_level
      - global_courier_service_level
      - prediction
      title: Prediction
      type: object
      $ref: '#/components/schemas/Prediction'
    title: Prediction
    type: array
  location:
    anyOf:
    - properties:
        country:
          description: Country code returned by Backend for prediction.
          title: Country
          type: string
        region:
          description: Resolved region, or the ISO2 country for a country-level location.
          title: Region
          type: string
        zip:
          anyOf:
          - type: string
          - type: 'null'
          description: Postal code used for prediction. Can be null, or "0" for the
            existing country-level fallback.
          title: Zip
      required:
      - country
      - region
      - zip
      title: PredictionLocation
      type: object
      $ref: '#/components/schemas/PredictionLocation'
    - type: 'null'
    default: null
    description: Location selected by Backend for prediction, including an IP fallback
      country when used. Retained when no predictions are generated. Null if resolution
      failed or an older Backend response omits the location.
required:
- request_id
- success
- prediction
title: PredictionResponse
type: object
$ref: '#/components/schemas/PredictionResponse'
```
