import Switchyard from "@switchyard/js-sdk"
export const sdk = new Medusa({
baseUrl: import.meta.env.VITE_BACKEND_URL || "/",
debug: import.meta.env.DEV,
auth: {
type: "session",
},
})
sdk.admin.shippingOption.create({
name: "Standard Shipping",
profile_id: "shp_123",
})
.then(({ shipping_option }) => {
console.log(shipping_option)
}){
"shipping_option": {
"id": "<string>",
"name": "<string>",
"price_type": "calculated",
"service_zone_id": "<string>",
"service_zone": {},
"provider_id": "<string>",
"provider": {
"id": "<string>",
"is_enabled": true
},
"shipping_option_type_id": "<string>",
"type": {
"id": "<string>",
"created_at": "2023-11-07T05:31:56Z",
"updated_at": "2023-11-07T05:31:56Z",
"deleted_at": "2023-11-07T05:31:56Z",
"label": "<string>",
"description": "<string>",
"code": "<string>",
"shipping_option_id": "<string>"
},
"shipping_profile_id": "<string>",
"shipping_profile": {
"id": "<string>",
"name": "<string>",
"type": "<string>",
"metadata": {},
"created_at": "2023-11-07T05:31:56Z",
"updated_at": "2023-11-07T05:31:56Z",
"deleted_at": "2023-11-07T05:31:56Z"
},
"rules": [
{
"id": "<string>",
"attribute": "is_return",
"operator": "gt",
"value": "true",
"shipping_option_id": "<string>",
"created_at": "2023-11-07T05:31:56Z",
"updated_at": "2023-11-07T05:31:56Z",
"deleted_at": "2023-11-07T05:31:56Z"
}
],
"prices": [
{
"price_rules": [
{
"id": "<string>",
"value": "<string>",
"operator": "gt",
"attribute": "<string>",
"price_id": "<string>",
"priority": 123,
"created_at": "2023-11-07T05:31:56Z",
"updated_at": "2023-11-07T05:31:56Z",
"deleted_at": "2023-11-07T05:31:56Z"
}
],
"rules_count": 123,
"id": "<string>",
"title": "<string>",
"currency_code": "usd",
"amount": 123,
"raw_amount": {},
"min_quantity": 123,
"max_quantity": 123,
"price_set_id": "<string>",
"created_at": "2023-11-07T05:31:56Z",
"updated_at": "2023-11-07T05:31:56Z",
"deleted_at": "2023-11-07T05:31:56Z"
}
],
"data": {},
"metadata": {},
"created_at": "2023-11-07T05:31:56Z",
"updated_at": "2023-11-07T05:31:56Z",
"deleted_at": "2023-11-07T05:31:56Z"
}
}Create a shipping option.
import Switchyard from "@switchyard/js-sdk"
export const sdk = new Medusa({
baseUrl: import.meta.env.VITE_BACKEND_URL || "/",
debug: import.meta.env.DEV,
auth: {
type: "session",
},
})
sdk.admin.shippingOption.create({
name: "Standard Shipping",
profile_id: "shp_123",
})
.then(({ shipping_option }) => {
console.log(shipping_option)
}){
"shipping_option": {
"id": "<string>",
"name": "<string>",
"price_type": "calculated",
"service_zone_id": "<string>",
"service_zone": {},
"provider_id": "<string>",
"provider": {
"id": "<string>",
"is_enabled": true
},
"shipping_option_type_id": "<string>",
"type": {
"id": "<string>",
"created_at": "2023-11-07T05:31:56Z",
"updated_at": "2023-11-07T05:31:56Z",
"deleted_at": "2023-11-07T05:31:56Z",
"label": "<string>",
"description": "<string>",
"code": "<string>",
"shipping_option_id": "<string>"
},
"shipping_profile_id": "<string>",
"shipping_profile": {
"id": "<string>",
"name": "<string>",
"type": "<string>",
"metadata": {},
"created_at": "2023-11-07T05:31:56Z",
"updated_at": "2023-11-07T05:31:56Z",
"deleted_at": "2023-11-07T05:31:56Z"
},
"rules": [
{
"id": "<string>",
"attribute": "is_return",
"operator": "gt",
"value": "true",
"shipping_option_id": "<string>",
"created_at": "2023-11-07T05:31:56Z",
"updated_at": "2023-11-07T05:31:56Z",
"deleted_at": "2023-11-07T05:31:56Z"
}
],
"prices": [
{
"price_rules": [
{
"id": "<string>",
"value": "<string>",
"operator": "gt",
"attribute": "<string>",
"price_id": "<string>",
"priority": 123,
"created_at": "2023-11-07T05:31:56Z",
"updated_at": "2023-11-07T05:31:56Z",
"deleted_at": "2023-11-07T05:31:56Z"
}
],
"rules_count": 123,
"id": "<string>",
"title": "<string>",
"currency_code": "usd",
"amount": 123,
"raw_amount": {},
"min_quantity": 123,
"max_quantity": 123,
"price_set_id": "<string>",
"created_at": "2023-11-07T05:31:56Z",
"updated_at": "2023-11-07T05:31:56Z",
"deleted_at": "2023-11-07T05:31:56Z"
}
],
"data": {},
"metadata": {},
"created_at": "2023-11-07T05:31:56Z",
"updated_at": "2023-11-07T05:31:56Z",
"deleted_at": "2023-11-07T05:31:56Z"
}
}Bearer authentication header of the form Bearer <token>, where <token> is your auth token.
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 shipping option's details.
The flat-rate shipping option's name.
The ID of the associated service zone.
The ID of the associated shipping profile.
The shipping option's price type. If flat, the shipping option has a fixed price set in prices. Otherwise, the shipping option's price is calculated by the fulfillment provider.
flat, calculated The ID of the fulfillment provider handling this shipping option.
The shipping option's prices.
The price's details.
Show child attributes
The price's currency code.
"usd"
The price's amount.
The flat-rate shipping option's data, useful for the fulfillment provider handling its processing.
The ID of the shipping option type that this shipping option belongs to.
The shipping option's rules.
Show child attributes
The operator used to check whether a rule applies.
gt, lt, eq, ne, in, lte, gte, nin The name of a property or table that the rule applies to.
"customer_group"
A value of the attribute that enables this rule.
"cusgroup_123"
The shipping option's metadata.
OK
The shipping option's details.
The shipping option's details.
Show child attributes
The shipping option's ID.
The shipping option's name.
The shipping option's price type. If it's flat, the price is fixed and is set in the prices property. If it's calculated, the price is calculated on checkout by the associated fulfillment provider.
calculated, flat The ID of the service zone this option belongs to.
The ID of the provider handling fulfillments created from this shipping option.
The ID of the associated shipping option type.
The shipping option's details.
Show child attributes
The shipping option's ID.
The date the shipping option was created.
The date the shipping option was updated.
The date the shipping option was deleted.
The type's label.
The type's description.
The type's code.
The type's shipping option id.
The ID of the associated shipping profile.
The shipping profile's details..
Show child attributes
The shipping profile's ID.
The shipping profile's name.
The shipping profile's type.
The shipping profile's metadata, holds custom key-value pairs.
The date the shipping profile was created.
The date the shipping profile was updated.
The date the shipping profile was deleted.
The shipping option's rules.
Show child attributes
The shipping option rule's ID.
The shipping option rule's attribute.
"is_return"
The rule's operator.
gt, lt, eq, ne, in, lte, gte, nin The shipping option rule's value.
"true"
The ID of the shipping option this rule is for.
The date the shipping option rule was created.
The date the shipping option rule was updated.
The date the shipping option rule was deleted.
The shipping option's prices. If the price_type is calculated, this array will be empty since the price is calculated by the fulfillment provider during checkout.
Show child attributes
The price's rules.
Show child attributes
The price rule's ID.
The price rule's value.
The price rule's operator.
gt, lt, eq, ne, in, lte, gte, nin The price rule's attribute.
The ID of the price this rule applies to.
The price rule's priority.
The date the price rule was created.
The date the price rule was updated.
The date the price rule was deleted.
The number of rules the price has.
The price's ID.
The price's title.
The price's currency code.
"usd"
The price's amount.
The price's raw amount.
The minimum quantity required in the cart for this price to apply.
The maximum quantity that the cart's items must not surpass for this price to apply.
The ID of the price set this price belongs to.
The date the price was created.
The date the price was updated.
The date the price was deleted.
The shipping option's data, useful for the fulfillment provider handling fulfillments created from this option.
The shipping option's metadata, can hold custom key-value pairs.
The date the shipping option was created.
The date the shipping option was updated.
The date the shipping option was deleted.