Shipping Methods are applied to Violet at the Bag level, since each Merchant can have their own shipping configurations. Once a shipping address has been added to a cart, you can use our Shipping Method endpoints to retrieve and apply methods.

Violet shows shipping methods based on what the Merchant has configured in their store through their e-commerce platform. They do not configure these in Violet. For example, you can learn about how Shopify stores configure shipping methods here.

Retrieve Shipping Methods

You can use the Retrieve Shipping Methods endpoint to retrieve shipping methods, once a shipping address has been added to the Order, as seen below:

curl https://sandbox-api.violet.io/v1/checkout/cart/{cart_id}/shipping/available \
-H "X-Violet-App-Id: your-app-id-here" \
-H "X-Violet-App-Secret: your-app-secret-here" \
-H "X-Violet-Token: your-token-here" \
-H "Content-type: application/json"

This call is at the Cart level, however, notice that the response contains shipping methods at the Bag (i.e. merchant) level.

[
    {
        "bag_id": 20440,
        "shipping_methods": [
            {
                "carrier": "OTHER",
                "label": "International Shipping",
                "price": 2000,
                "shipping_method_id": "shopify-International%20Shipping-20.00",
                "bag_id": 20440
            }
        ]
    },
		{
        "bag_id": 20441,
        "shipping_methods": [
            {
                "carrier": "USPS",
                "label": "US Domestic",
                "price": 999,
                "shipping_method_id": "shopify-usps%20Shipping-9.99",
                "bag_id": 20441
            }
        ]
    }
]

Applying Shipping Methods

Once you’ve retrieved shipping methods, you can use the Apply Shipping Methods endpoint to attach these shipping methods to Bags. Each bag in a cart will require its own shipping method. For this reason, data is passed in as a collection of shipping methods, one for each bag. If you only have one bag in your cart you will pass in a collection consisting of one shipping method, as seen below:

curl -X POST https://sandbox-api.violet.io/v1/checkout/cart/{cart_id}/shipping \
-H "X-Violet-App-Id: your-app-id-here" \
-H "X-Violet-App-Secret: your-app-secret-here" \
-H "X-Violet-Token: your-token-here" \
-H "Content-type: application/json" \
-d '[{"bag_id": 1, "shipping_method_id": "usps-flatrate"}]'

The response will then be an Order object, on which you will notice that now, each bag on the order you are applying shipping methods to will contain a shipping_method object. If there are any errors while applying shipping methods, the order will return with errors listed in the errors field on the object.