# Using a shipping endpoint

With [low-code checkouts](/digital-river-api/integration-options/low-code-checkouts.md), you can save a [shipping endpoint in the Digital River Dashboard](/digital-river-api/administration/dashboard/settings/prebuilt-checkout.md#configure-a-shipping-callout). Digital River calls it during physical product checkouts and uses the response to present customers with their shipping options.

If you are using an external logistics provider, the service you set up to handle our call can either filter and adjust the shipping options we send or use the request's data to make yet another request to your external provider to get their available options.&#x20;

In both cases, you must respond with the options you want us to present to customers in the shipping choice selection stage.

On this page, you’ll find details on:

* [Creating the checkout-session](#creating-the-checkout-session)
* [Restricting available ship to countries](#restricting-available-ship-to-countries)
* [How to use the endpoint with an external logistics provider](#using-the-endpoint-with-an-external-logistics-providers)
* [How to display error messages](#displaying-errors)

## Creating the checkout-session

In your [create checkout-session request](https://docs.digitalriver.com/digital-river-api-reference/2021-12-13/drop-in-checkout-sessions), include the `weight` and `weightUnit` of each [physical product](/digital-river-api/product-management/skus.md#how-products-are-classified-as-physical-or-digital) in the cart in either the [SKU](/digital-river-api/product-management/creating-and-updating-skus.md) referenced by `items[].skuId` or directly in [`items[].productDetails`](/digital-river-api/product-management/using-product-details.md).

{% hint style="info" %}
A product's weight should be exclusive of its packaging but inclusive of its [dunnage](https://en.wikipedia.org/wiki/Dunnage). In other words, don't include the weight of the product's box, but include the weight of the protective and supporting materials inside it.
{% endhint %}

Goods eligible for inclusion in [cross-border shipments](/digital-river-api/general-resources/glossary.md#cross-border) should also be assigned a `name`, `description`, `image`, and `url`. They must also contain a product taxonomy to identify the correct tariff codes. For details, refer to [Item Classification](/digital-river-api/using-our-services/item-classification.md).&#x20;

For each physical `items[]`, if you want the carrier to provide one or more `logisticsOptions`, and you decided not to save these options to the product's [SKU Group](/digital-river-api/product-management/setting-up-sku-groups.md), then make sure you enumerate them in `deliveryOptions[]` and/or `dangerousGoods[]`. This ensures that the cost of each service gets added to the shipping quotes customers select from.

## Restricting available ship to countries

You'll need to restrict the countries customers can select from during the shipping address collection stage to those you support.

For details on how to do this, refer to [Shipping country](https://docs.digitalriver.com/digital-river-api-reference/2021-12-13/drop-in-checkout-sessions/checkout-sessions-basics#shopping-country) on the [Checkout-sessions basics](https://docs.digitalriver.com/digital-river-api-reference/2021-12-13/drop-in-checkout-sessions/checkout-sessions-basics) page.

{% hint style="info" %}
In [Prebuilt Checkout](/digital-river-api/integration-options/low-code-checkouts/drop-in-checkout.md), you can also use its [configuration object](/digital-river-api/developer-resources/digitalrivercheckout.js-reference/digitalrivercheckout-object/configuring-prebuilt-checkout.md) to [restrict shipping and billing countries](/digital-river-api/developer-resources/digitalrivercheckout.js-reference/digitalrivercheckout-object/configuring-prebuilt-checkout.md#restrict-shipping-and-billing-countries).
{% endhint %}

## Using the endpoint with an external logistics provider

If you (1) select either a [low-code checkout](/digital-river-api/integration-options/low-code-checkouts.md) solution, (2) [save a shipping endpoint in the Digital River Dashboard](/digital-river-api/administration/dashboard/settings/prebuilt-checkout.md#configure-a-shipping-callout) and (3) engage an external logistics service, you can use this section to understand better:

* [The shipping quotes request we send to your endpoint](#the-shipping-quotes-request-1)
* [How to process and respond to our request](#processing-and-responding-to-our-request-1)
* [How Digital River processes your response](#how-digital-river-processes-your-response-1)
* [How the ship request can be defined](#defining-the-ship-request-1)

<div align="left" data-full-width="true"><figure><img src="/files/YeBEJ0JiCnC1yYRITBem" alt=""><figcaption></figcaption></figure></div>

### The shipping quotes request

Once customers input a shipping address and Digital River determines that an external logistics provider is facilitating the transaction, we send a request to [your shipping endpoint](https://docs.digitalriver.com/digital-river-api-reference/2021-12-13/drop-in-shipping-quotes).

{% code title="Request" %}

```json
{
    "sessionId": "8e8f8a1b-4049-4e4f-a8b6-d5c6a90b713b",
    "currency": "USD",
    "shipTo": {
        "address": {
            "line1": "1234 Rocky Mountain Highway",
            "city": "Estes Park",
            "state": "CO",
            "postalCode": "80517",
            "country": "US"
        },
        "name": "John D.",
        "phone": "5555555555",
        "email": "jdenver@digitalriver.com"
    },
    "items": [
        {
            "sku": {
                "id": "sku_e628c0d0-33b7-4dea-aa40-9eadc43e1583",
                "name": "Blue shirt",
                "eccn": "8A992",
                "taxCode": "55101504.100",
                "image": "https://mdbootstrap.com/img/Photos/Horizontal/E-commerce/Vertical/12.jpg",
                "url": "https://digitalriver.com/blue-shirt",
                "physical": true,
                "skuGroupId": "physical-product",
                "weight": 20.5,
                "weightUnit": "oz"
            },
            "amount": 11.95,
            "quantity": 1,
            "id": "714eb8ef-5a11-4faa-b6e5-35992d01d628"
        },
        {
            "sku": {
                "id": "sku_32ee813a-e7a8-46dc-97f4-fca07b47eca6",
                "name": "Red shirt",
                "eccn": "8A992",
                "taxCode": "55101504.100",
                "image": "https://mdbootstrap.com/img/Photos/Horizontal/E-commerce/Vertical/12.jpg",
                "url": "https://digitalriver.com/red-shirt",
                "physical": true,
                "skuGroupId": "physical-product",
                "weight": 20.5,
                "weightUnit": "oz"
            },
            "amount": 11.95,
            "quantity": 1,
            "id": "945gh8ed-3g21-6ffg-mj6e6-45113e11d628"
        }
    ]
}
```

{% endcode %}

Since we don't yet know what shipping options are available, the request contains no `shippingMethods[]`.

It does, however, contain the [checkout-session’s](https://docs.digitalriver.com/digital-river-api-reference/2021-12-13/drop-in-checkout-sessions/checkout-sessions-basics) `currency`, `shipTo`, `items[]`, and unique identifier (`sessionId`).

For each `items[]`, we also give you an `id` that uniquely identifies that line item in our system.

### Processing and responding to our request

After you accept our request and determine that it contains no `shippingMethods[]`, you can use its `currency`, `items[]`, and `shipTo` to call your logistics provider and get the transaction’s available shipping options.

In that request, you'll most likely want to pass the `weight` and `weightUnit` of each `items[]`. Your logistics provider can typically use that data for more precise shipping rates.

In addition, depending on the sophistication of the integration you have with your provider, they might be able to give you the location of the warehouse(s) from which each `items[]` will be shipped.

After your logistics provider returns the available shipping options, your service could add a markup, discount them, and/or filter them by terms.

Your response must contain `shippingMethods[]`, which lists the options you want Digital River to present in the shipping choice selection stage. Each element in this array must have an `amount`, `description`, and `serviceLevel` and can optionally include an `id`, `deliveryInformation`, `shippingTerms`, and a `shipFrom` location.

If your logistic provider informed you where each line item is shipping from, your response can also contain `shipments[]`, each of which should have a single `shipFrom` and an array of `itemIds[]`, each mapped to an `items[].id` we sent in the request.

{% code title="Response" %}

```json
{
    "shipments": [
        {
            "itemIds": [
                "714eb8ef-5a11-4faa-b6e5-35992d01d628"
            ],
            "shipFrom": {
                "address": {
                    "line1": "10380 Bren Rd W",
                    "city": "Minnetonka",
                    "postalCode": "55343",
                    "state": "MN",
                    "country": "US"
                }
            }
        },
        {
            "itemIds": [
                "945gh8ed-3g21-6ffg-mj6e6-45113e11d628"
            ],
            "shipFrom": {
                "address": {
                    "line1": "1234 5th Ave",
                    "city": "New York",
                    "postalCode": "10005",
                    "state": "NY",
                    "country": "US"
                }
            }
        }
    ],
    "shippingMethods": [
        {
            "description": "Standard Shipping",
            "serviceLevel": "Standard",
            "amount": 2.99
        },
        {
            "description": "Expedited Shipping",
            "serviceLevel": "Expedited",
            "amount": 10.98
        }
    ]
}
```

{% endcode %}

### How Digital River processes your response

For each `shipments[]` in your response, we iterate through its `itemsIds[]`, looking up that resource in our system, and then using the `shipments[].shipFrom` to set the appropriate `items[].shipFrom` value(s) in the [checkout-session](https://docs.digitalriver.com/digital-river-api-reference/2021-12-13/drop-in-checkout-sessions).

For each `shippingMethods[]`, Digital River displays its `amount`, `description`, and `shippingTerms` to customers in the shipping choice selection stage. If `businessDaysInTransit`, `estimatedArrival.date`, and/or `estimatedArrival.dayOfWeek` exist in `deliveryInformation`, then their values are also displayed.

{% hint style="info" %}
In [Prebuilt Checkout](/digital-river-api/integration-options/low-code-checkouts/drop-in-checkout.md), Digital River renders [`shippingTerms`](/digital-river-api/general-resources/glossary.md#shipping-terms) so that its meaning is clearer to customers.
{% endhint %}

Each time customers make a selection, we use its data to update the [checkout-session’s](https://docs.digitalriver.com/digital-river-api-reference/2021-12-13/drop-in-checkout-sessions) `shippingChoice` and, if that selection contains a `shipFrom` , we also use it to set that resource's [`shipFrom`](https://docs.digitalriver.com/digital-river-api-reference/2021-12-13/drop-in-checkout-sessions/checkout-sessions-basics#ship-from).

### Defining the ship request

After Digital River converts the [checkout-session](https://docs.digitalriver.com/digital-river-api-reference/2021-12-13/drop-in-checkout-sessions) to an [order](https://docs.digitalriver.com/digital-river-api-reference/2021-12-13/orders) and sends you the [event](https://docs.digitalriver.com/digital-river-api-reference/2021-12-13/events) with a [`type`](/digital-river-api/order-management/events-and-webhooks-1/events-1.md#event-types) of [`order.accepted`](/digital-river-api/order-management/creating-and-updating-an-order.md#listening-for-the-order-accepted-event), you can pass its data to your fulfillment service, which can then read the line-item level and/or order-level ship from values and route ship requests to the appropriate warehouses.

{% code title="Event" %}

```json
{
    "id": "a443e1ee-61ec-4f9c-8c27-97b144c8f8f5",
    "type": "order.accepted",
    "data": {
        "object": {
            "id": "255896870336",
            ...
            "items": [
                {
                    "id": "185466030336",
                    "productDetails": {
                        "id": "physical-product-1",
                        "skuGroupId": "physical-product",
                        "name": "Blue shirt",
                        "url": "https://digitalriver.com/blue-shirt",
                        "countryOfOrigin": "US",
                        "image": "https://mdbootstrap.com/img/Photos/Horizontal/E-commerce/Vertical/12.jpg",
                        "weight": 20.5,
                        "weightUnit": "oz",
                        "partNumber": "Part123"
                    },
                    ...
                    "shipFrom": {
                        "address": {
                            "line1": "10380 Bren Rd W",
                            "city": "Minnetonka",
                            "postalCode": "55343",
                            "state": "MN",
                            "country": "US"
                        }
                    },
                    ...
                },
                {
                    "id": "185466050336",
                    "productDetails": {
                        "id": "physical-product-2",
                        "skuGroupId": "physical-product",
                        "name": "Red shirt",
                        "url": "https://digitalriver.com/red-shirt",
                        "countryOfOrigin": "US",
                        "image": "https://mdbootstrap.com/img/Photos/Horizontal/E-commerce/Vertical/12.jpg",
                        "weight": 20.5,
                        "weightUnit": "oz",
                        "partNumber": "Part123"
                    },
                    ...
                    "shipFrom": {
                        "address": {
                            "line1": "1234 5th Ave",
                            "city": "New York",
                            "postalCode": "10005",
                            "state": "NY",
                            "country": "US"
                        }
                    },
                    ...
                }
            ],
            "shippingChoice": {
                "amount": 10.98,
                "description": "Expedited Shipping",
                "serviceLevel": "Expedited",
                "taxAmount": 0.0
            },
            ...
        }
    },
    ...
}
```

{% endcode %}

## Displaying errors

The body of the [request](https://docs.digitalriver.com/digital-river-api-reference/2021-12-13/drop-in-shipping-quotes) Digital River sends to your server always has (1) `shipTo`, which contains the customer's designated `address` and, depending on their selected `country`, might also have `additionalAddressInfo` as well as (2) the details of each `items[]` the customer is purchasing.

If your service checks this data and determines that it's invalid, perhaps because `line1` or `line2` indicate that the customer is trying to ship the goods to a PO Box, and you don't support that or `additionalAddressInfo.neighborhood` isn't serviced by your carriers, then it can return an error.

We'll then display that error's `message` in the checkout experience.

What you need to do to get this message displayed depends on whether you're using [Prebuilt Checkout](#prebuilt-checkout) or [Components](#components).

### Prebuilt Checkout

When implementing this feature in [Prebuilt Checkout](/digital-river-api/integration-options/low-code-checkouts/drop-in-checkout.md), here are some things to keep in mind:

* Your server must return one of our [stock errors](#stock-errors).
* Don't modify the [stock error's](#stock-errors) `code`. If you do, then its `message` won't display in the checkout experience. Instead, users will be told that an unknown error occurred.<br>

  <div align="left"><figure><img src="/files/BP3LlVZPvxHr7q6VQR6D" alt=""><figcaption></figcaption></figure></div>
* Altering your error's `message` does not affect what's shown to users. If its `code` matches one of our supported values, then that [stock error's](#stock-errors) `message` is displayed, unmodified, in the checkout experience.
* To get the `message` displayed, your server needs to respond with a status code of `400` or `409` and the error's `type` must be `bad_request` or `conflict`.
* Digital River blocks customers from advancing to the shipping choice selection stage until they correct the issue.
* The error's `message` isn't translated into the [checkout-session's](https://docs.digitalriver.com/digital-river-api-reference/2021-12-13/drop-in-checkout-sessions/checkout-sessions-basics) [`language`](https://docs.digitalriver.com/digital-river-api-reference/2021-12-13/drop-in-checkout-sessions/checkout-sessions-basics#language). Rather, it's always rendered in English.

#### Stock errors

The following lists the stock and preformatted errors that are available. For illustration purposes, we also show how each is rendered:

{% tabs %}
{% tab title="Invalid address" %}

```json
{
    "type": "bad_request",
    "errors": [
        {
            "code": "shipping_address_invalid",
            "parameter": "string",
            "message": "The shipping address provided is not valid."
        }
    ]
}
```

<div align="left"><figure><img src="/files/cl0RL5pwhxfOkHibgAvI" alt=""><figcaption></figcaption></figure></div>
{% endtab %}

{% tab title="P.O. boxes unsupported" %}

```json
{
    "type": "bad_request",
    "errors": [
        {
            "code": "shipping_address_POBox_invalid",
            "parameter": "string",
            "message": "Shipping to a PO Box is not allowed."
        }
    ]
}
```

<div align="left"><figure><img src="/files/lHoyeB50sRI6EMoP1LLT" alt=""><figcaption></figcaption></figure></div>
{% endtab %}

{% tab title="Invalid location" %}

```json
{
    "type": "bad_request",
    "errors": [
        {
            "code": "shipping_address_location_invalid",
            "parameter": "string",
            "message": "Shipping is not supported for the provided location."
        }
    ]
}
```

<div align="left"><figure><img src="/files/tnijsUznGd7P1bNX82Mi" alt=""><figcaption></figcaption></figure></div>
{% endtab %}

{% tab title="Invalid subdivision" %}

```json
{
    "type": "bad_request",
    "errors": [
        {
            "code": "shipping_address_subdivision_invalid",
            "parameter": "string",
            "message": "Shipping is not supported for the provided subdivision."
        }
    ]
}
```

<div align="left"><figure><img src="/files/Zc0SOMXrsq1SR8uuasy9" alt=""><figcaption></figcaption></figure></div>
{% endtab %}
{% endtabs %}

### Components

If you're implementing this feature in [Components](/digital-river-api/developer-resources/digitalrivercheckout.js-reference/digitalrivercheckout-object/components.md):

* The error returned by your service must have a `message`, but doesn't need a `code`.
* The value you assign to `message` is customizable.
* Any [valid HTTP status code](https://en.wikipedia.org/wiki/List_of_HTTP_status_codes) in the `4xx` or `5xx` range is accepted, but we recommend that you send back a `400 Bad Request`.

Digital River displays your error's `message` in the [address component](/digital-river-api/developer-resources/digitalrivercheckout.js-reference/digitalrivercheckout-object/components/address-component.md). Before doing that, we don't translate it into the [checkout-session's](https://docs.digitalriver.com/digital-river-api-reference/2021-12-13/drop-in-checkout-sessions/checkout-sessions-basics) [`language`](https://docs.digitalriver.com/digital-river-api-reference/2021-12-13/drop-in-checkout-sessions/checkout-sessions-basics#language) or perform any other operations.

{% tabs %}
{% tab title="Error" %}
{% code title="400 Bad Request" %}

```json
{
    "errors": [
        {
            "message": "An error message that you define"
        }
    ]
}
```

{% endcode %}
{% endtab %}

{% tab title="Address component" %}

<div align="left"><figure><img src="/files/wUC77BR4TDKF8xnI7mxY" alt=""><figcaption></figcaption></figure></div>
{% endtab %}
{% endtabs %}

In addition, if your response contains an error, that component's [`done()`](/digital-river-api/developer-resources/digitalrivercheckout.js-reference/digitalrivercheckout-object/components/address-component.md#submitting-the-address-component) function will return `false`, which, if your application is set up correctly, should block customers from proceeding to the [shipping choice selection stage](/digital-river-api/developer-resources/digitalrivercheckout.js-reference/digitalrivercheckout-object/components/shipping-component.md).

For details, refer to [Controlling the checkout flow](/digital-river-api/integration-options/low-code-checkouts/implementing-a-components-checkout.md#controlling-the-checkout-flow).


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.digitalriver.com/digital-river-api/integration-options/low-code-checkouts/using-a-shipping-endpoint.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
