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.promotion.retrieve("promo_123")
.then(({ promotion }) => {
console.log(promotion)
}){
"promotion": {
"id": "<string>",
"created_at": "2023-11-07T05:31:56Z",
"updated_at": "2023-11-07T05:31:56Z",
"deleted_at": "2023-11-07T05:31:56Z",
"application_method": {
"id": "<string>",
"promotion": {},
"target_rules": [
{
"id": "<string>",
"values": [
"cusgroup_123"
],
"description": "<string>",
"attribute": "customer_group_id",
"operator": "gt"
}
],
"buy_rules": [
{
"id": "<string>",
"values": [
"cusgroup_123"
],
"description": "<string>",
"attribute": "customer_group_id",
"operator": "gt"
}
],
"type": "fixed",
"target_type": "items",
"allocation": "each",
"value": 123,
"currency_code": "usd",
"max_quantity": 123,
"buy_rules_min_quantity": 123,
"apply_to_quantity": 123
},
"rules": [
{
"id": "<string>",
"values": [
"cusgroup_123"
],
"description": "<string>",
"attribute": "customer_group_id",
"operator": "gt"
}
],
"code": "OFF50",
"type": "standard",
"is_automatic": true,
"campaign_id": "<string>",
"campaign": {
"id": "<string>",
"name": "<string>",
"description": "<string>",
"currency": "<string>",
"campaign_identifier": "<string>",
"starts_at": "<string>",
"ends_at": "<string>",
"budget": {
"id": "<string>",
"type": "spend",
"currency_code": "<string>",
"limit": 123,
"used": 123,
"attribute": "<string>"
},
"created_at": "2023-11-07T05:31:56Z",
"updated_at": "2023-11-07T05:31:56Z",
"deleted_at": "2023-11-07T05:31:56Z"
},
"status": "draft",
"is_tax_inclusive": true,
"limit": 123,
"used": 123
}
}Retrieve a promotion by its ID. You can expand the promotion’s relations or select the fields that should be returned.
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.promotion.retrieve("promo_123")
.then(({ promotion }) => {
console.log(promotion)
}){
"promotion": {
"id": "<string>",
"created_at": "2023-11-07T05:31:56Z",
"updated_at": "2023-11-07T05:31:56Z",
"deleted_at": "2023-11-07T05:31:56Z",
"application_method": {
"id": "<string>",
"promotion": {},
"target_rules": [
{
"id": "<string>",
"values": [
"cusgroup_123"
],
"description": "<string>",
"attribute": "customer_group_id",
"operator": "gt"
}
],
"buy_rules": [
{
"id": "<string>",
"values": [
"cusgroup_123"
],
"description": "<string>",
"attribute": "customer_group_id",
"operator": "gt"
}
],
"type": "fixed",
"target_type": "items",
"allocation": "each",
"value": 123,
"currency_code": "usd",
"max_quantity": 123,
"buy_rules_min_quantity": 123,
"apply_to_quantity": 123
},
"rules": [
{
"id": "<string>",
"values": [
"cusgroup_123"
],
"description": "<string>",
"attribute": "customer_group_id",
"operator": "gt"
}
],
"code": "OFF50",
"type": "standard",
"is_automatic": true,
"campaign_id": "<string>",
"campaign": {
"id": "<string>",
"name": "<string>",
"description": "<string>",
"currency": "<string>",
"campaign_identifier": "<string>",
"starts_at": "<string>",
"ends_at": "<string>",
"budget": {
"id": "<string>",
"type": "spend",
"currency_code": "<string>",
"limit": 123,
"used": 123,
"attribute": "<string>"
},
"created_at": "2023-11-07T05:31:56Z",
"updated_at": "2023-11-07T05:31:56Z",
"deleted_at": "2023-11-07T05:31:56Z"
},
"status": "draft",
"is_tax_inclusive": true,
"limit": 123,
"used": 123
}
}Bearer authentication header of the form Bearer <token>, where <token> is your auth token.
The promotion'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.
OK
The promotion's details.
The promotion's details.
Show child attributes
The promotion's ID.
The date the promotion was created.
The date the promotion was updated.
The date the promotion was deleted.
The application method's details.
Show child attributes
The application method's ID.
The application method's target rules.
Show child attributes
The promotion rule's ID.
The promotion rule's description.
The promotion rule's attribute.
"customer_group_id"
The rule's operator.
gt, lt, eq, ne, in, lte, gte The application method's buy rules.
Show child attributes
The promotion rule's ID.
The promotion rule's description.
The promotion rule's attribute.
"customer_group_id"
The rule's operator.
gt, lt, eq, ne, in, lte, gte The application method's type. If it's fixed, the promotion discounts a fixed amount. If it's percentage, the promotion discounts a percentage.
fixed, percentage Which item does the promotion apply to. items mean the promotion applies to the cart's items; shipping_methods means the promotion applies to the cart's shipping methods; order means the promotion applies on the entire order.
items, shipping_methods, order How is the promotion amount discounted. each means the discounted amount is applied on each applicable item; across means the discounted amount is split accross the applicable items.
each, across The amount to be discounted.
The application method's currency code.
"usd"
The max quantity allowed in the cart for the associated promotion to be applied.
The minimum quantity required for a buyget promotion to be applied. For example, if the promotion is a "Buy 2 shirts get 1 free", the value of this attribute is 2.
The quantity that results from matching the buyget promotion's condition. For example, if the promotion is a "Buy 2 shirts get 1 free", the value of this attribute is 1.
The promotion's rules.
Show child attributes
The promotion rule's ID.
The promotion rule's description.
The promotion rule's attribute.
"customer_group_id"
The rule's operator.
gt, lt, eq, ne, in, lte, gte The promotion's code.
"OFF50"
The promotion's type.
standard, buyget Whether the promotion is applied on a cart automatically if it matches the promotion's rules.
The ID of the campaign this promotion belongs to.
The campaign's details.
Show child attributes
The campaign's ID.
The campaign's name.
The campaign's description.
The campaign's currency.
The campaign's identifier.
The date and time that the campaign starts.
The date and time that the campaign ends.
The campaign's budget.
Show child attributes
The budget's ID.
The budget's type. spend means the limit is set on the total amount discounted by the campaign's promotions; usage means the limit is set on the total number of times the campaign's promotions can be used.
spend, usage The budget's currency code.
The budget's limit.
How much of the budget has been used. If the limit is spend, this property holds the total amount discounted so far. If the limit is usage, it holds the number of times the campaign's promotions have been used so far.
The cart attribute to limit the budget by.
The date the campaign was created.
The date the campaign was updated.
The date the campaign was deleted.
The promotion's status.
draft, active, inactive Whether the promotion is tax inclusive. If enabled, the promotion is applied after tax is calculated.
The limit of times the promotion can be used.
The number of times the promotion has been used.