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
}
}
Calculate the price of a shipping option in a cart.
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
}
}
Publishable API Key created in the Medusa Admin.
The shipping option's ID.
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.
The calculation's details.
OK
The shipping option's details.