POST
/
store
/
shipping-options
/
{id}
/
calculate
JS SDK
import Medusa from "@medusajs/js-sdk"

let MEDUSA_BACKEND_URL = "http://localhost:9000"

if (process.env.NEXT_PUBLIC_MEDUSA_BACKEND_URL) {
  MEDUSA_BACKEND_URL = process.env.NEXT_PUBLIC_MEDUSA_BACKEND_URL
}

export const sdk = new Medusa({
  baseUrl: MEDUSA_BACKEND_URL,
  debug: process.env.NODE_ENV === "development",
  publishableKey: process.env.NEXT_PUBLIC_MEDUSA_PUBLISHABLE_KEY,
})

sdk.store.fulfillment.calculate("so_123", {
  cart_id: "cart_123"
})
.then(({ shipping_option }) => {
  console.log(shipping_option)
})
{
"shipping_option": {
"id": "<string>",
"name": "<string>",
"price_type": "flat",
"service_zone_id": "<string>",
"provider_id": "<string>",
"provider": {
"id": "<string>",
"is_enabled": true
},
"type": {
"id": "<string>",
"label": "<string>",
"description": "<string>",
"code": "<string>"
},
"shipping_profile_id": "<string>",
"amount": 123,
"data": {},
"prices": [
{
"id": "<string>",
"currency_code": "usd",
"amount": 123,
"min_quantity": 123,
"max_quantity": 123,
"price_rules": [
{
"id": "<string>",
"attribute": "<string>",
"operator": "gt",
"value": "<string>"
}
]
}
],
"calculated_price": {
"id": "<string>",
"is_calculated_price_price_list": true,
"is_calculated_price_tax_inclusive": true,
"calculated_amount": 123,
"calculated_amount_with_tax": 123,
"calculated_amount_without_tax": 123,
"is_original_price_price_list": true,
"is_original_price_tax_inclusive": true,
"original_amount": 123,
"currency_code": "<string>",
"calculated_price": {
"id": "<string>",
"price_list_id": "<string>",
"price_list_type": "<string>",
"min_quantity": 123,
"max_quantity": 123
},
"original_price": {
"id": "<string>",
"price_list_id": "<string>",
"price_list_type": "<string>",
"min_quantity": 123,
"max_quantity": 123
},
"original_amount_with_tax": 123,
"original_amount_without_tax": 123
},
"insufficient_inventory": true
}
}

Headers

x-publishable-api-key
string
required

Publishable API Key created in the Medusa Admin.

Path Parameters

id
string
required

The shipping option's ID.

Query Parameters

fields
string

Comma-separated fields that should be included in the returned data. if a field is prefixed with + it will be added to the default fields, using - will remove it from the default fields. without prefix it will replace the entire default fields.

Body

application/json

The calculation's details.

cart_id
string
required

The ID of the cart the shipping option is used in.

data
object

Custom data that's useful for the fulfillment provider to calculate the price.

Response

OK

The shipping option's details.

shipping_option
object
required

The shipping option's details.