Skip to main content
Skip to main content

AdminShippingOptionsResource

This class is used to send requests to Admin Shipping Option API Routes. All its method are available in the JS Client under the medusa.admin.shippingOptions property.

All methods in this class require user authentication.

A shipping option is used to define the available shipping methods during checkout or when creating a return. Admins can create an unlimited number of shipping options, each associated with a shipping profile and fulfillment provider, among other resources.

Related Guide: Shipping Option architecture.

Methods

create

Create a shipping option.

Example

import Medusa from "@medusajs/medusa-js"
const medusa = new Medusa({ baseUrl: MEDUSA_BACKEND_URL, maxRetries: 3 })
// must be previously logged in or use api token
medusa.admin.shippingOptions.create({
name: "PostFake",
region_id,
provider_id,
data: {
},
price_type: "flat_rate"
})
.then(({ shipping_option }) => {
console.log(shipping_option.id)
})

Parameters

The shipping option to create.
customHeadersRecord<string, any>Required
Custom headers to attach to the request.

Default: {}

Returns

ResponsePromiseResponsePromise<AdminShippingOptionsRes>Required
Resolves to the shipping option's details.

delete

Delete a shipping option. Once deleted, it can't be used when creating orders or returns.

Example

import Medusa from "@medusajs/medusa-js"
const medusa = new Medusa({ baseUrl: MEDUSA_BACKEND_URL, maxRetries: 3 })
// must be previously logged in or use api token
medusa.admin.shippingOptions.delete(optionId)
.then(({ id, object, deleted }) => {
console.log(id);
})

Parameters

idstringRequired
The shipping option's ID.
customHeadersRecord<string, any>Required
Custom headers to attach to the request.

Default: {}

Returns

ResponsePromiseResponsePromise<DeleteResponse>Required
Resolves to the deletion operation's details.

list

Retrieve a list of shipping options. The shipping options can be filtered by fields such as region_id or is_return passed in the query parameter.

Example

import Medusa from "@medusajs/medusa-js"
const medusa = new Medusa({ baseUrl: MEDUSA_BACKEND_URL, maxRetries: 3 })
// must be previously logged in or use api token
medusa.admin.shippingOptions.list()
.then(({ shipping_options, count }) => {
console.log(shipping_options.length);
})

Parameters

Filters to apply on the retrieved shipping options.
customHeadersRecord<string, any>Required
Custom headers to attach to the request.

Default: {}

Returns

ResponsePromiseResponsePromise<AdminShippingOptionsListRes>Required
Resolves to the list of shipping options.

retrieve

Retrieve a shipping option's details.

Example

import Medusa from "@medusajs/medusa-js"
const medusa = new Medusa({ baseUrl: MEDUSA_BACKEND_URL, maxRetries: 3 })
// must be previously logged in or use api token
medusa.admin.shippingOptions.retrieve(optionId)
.then(({ shipping_option }) => {
console.log(shipping_option.id);
})

Parameters

idstringRequired
The shipping option's ID.
customHeadersRecord<string, any>Required
Custom headers to attach to the request.

Default: {}

Returns

ResponsePromiseResponsePromise<AdminShippingOptionsRes>Required
Resolves to the shipping option's details.

update

Update a shipping option's details.

Example

import Medusa from "@medusajs/medusa-js"
const medusa = new Medusa({ baseUrl: MEDUSA_BACKEND_URL, maxRetries: 3 })
// must be previously logged in or use api token
medusa.admin.shippingOptions.update(optionId, {
name: "PostFake",
requirements: [
{
id,
type: "max_subtotal",
amount: 1000
}
]
})
.then(({ shipping_option }) => {
console.log(shipping_option.id)
})

Parameters

idstringRequired
The shipping option's ID.
The attributes to update in the shipping option.
customHeadersRecord<string, any>Required
Custom headers to attach to the request.

Default: {}

Returns

ResponsePromiseResponsePromise<AdminShippingOptionsRes>Required
Resolves to the shipping option's details.
Was this section helpful?