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.list()
.then(({ promotions, count, limit, offset }) => {
console.log(promotions)
}){
"limit": 123,
"offset": 123,
"count": 123,
"promotions": [
{
"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 list of promotions. The promotions can be filtered by fields such as id. The promotions can also be sorted or paginated.
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.list()
.then(({ promotions, count, limit, offset }) => {
console.log(promotions)
}){
"limit": 123,
"offset": 123,
"count": 123,
"promotions": [
{
"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.
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 number of items to skip when retrieving a list.
Limit the number of items returned in the list.
The field to sort the data by. By default, the sort order is ascending. To change the order to descending, prefix the field name with -.
Search term to filter the promotion's searchable attributes.
Filter by a promotion code.
Filter by a campaign's ID to retrieve its associated promotions.
Filter by a promotion's creation date.
Show child attributes
Join query parameters with an AND condition. Each object's content is the same type as the expected query parameters.
Join query parameters with an OR condition. Each object's content is the same type as the expected query parameters.
Filter by an exact match.
Filter by values not equal to this parameter.
Filter by values in this array.
Filter by values in this array.
Filter by values not in this array.
Filter by values not in this array.
Filter by values not matching the conditions in this parameter.
Filter by values greater than this parameter. Useful for numbers and dates only.
Filter by values greater than or equal to this parameter. Useful for numbers and dates only.
Filter by values less than this parameter. Useful for numbers and dates only.
Filter by values less than or equal to this parameter. Useful for numbers and dates only.
Apply a like filter. Useful for strings only.
Apply a regex filter. Useful for strings only.
Apply a case-insensitive like filter. Useful for strings only.
Filter to apply on full-text properties.
Filter arrays that have overlapping values with this parameter.
Filter arrays that have overlapping values with this parameter.
Filter arrays that contain some of the values of this parameter.
Filter arrays that contain some of the values of this parameter.
Filter arrays that contain all values of this parameter.
Filter arrays that contain all values of this parameter.
Filter by whether a value for this parameter exists (not null).
Filter by a promotion's update date.
Show child attributes
Join query parameters with an AND condition. Each object's content is the same type as the expected query parameters.
Join query parameters with an OR condition. Each object's content is the same type as the expected query parameters.
Filter by an exact match.
Filter by values not equal to this parameter.
Filter by values in this array.
Filter by values in this array.
Filter by values not in this array.
Filter by values not in this array.
Filter by values not matching the conditions in this parameter.
Filter by values greater than this parameter. Useful for numbers and dates only.
Filter by values greater than or equal to this parameter. Useful for numbers and dates only.
Filter by values less than this parameter. Useful for numbers and dates only.
Filter by values less than or equal to this parameter. Useful for numbers and dates only.
Apply a like filter. Useful for strings only.
Apply a regex filter. Useful for strings only.
Apply a case-insensitive like filter. Useful for strings only.
Filter to apply on full-text properties.
Filter arrays that have overlapping values with this parameter.
Filter arrays that have overlapping values with this parameter.
Filter arrays that contain some of the values of this parameter.
Filter arrays that contain some of the values of this parameter.
Filter arrays that contain all values of this parameter.
Filter arrays that contain all values of this parameter.
Filter by whether a value for this parameter exists (not null).
Filter by a promotion's deletion date.
Show child attributes
Join query parameters with an AND condition. Each object's content is the same type as the expected query parameters.
Join query parameters with an OR condition. Each object's content is the same type as the expected query parameters.
Filter by an exact match.
Filter by values not equal to this parameter.
Filter by values in this array.
Filter by values in this array.
Filter by values not in this array.
Filter by values not in this array.
Filter by values not matching the conditions in this parameter.
Filter by values greater than this parameter. Useful for numbers and dates only.
Filter by values greater than or equal to this parameter. Useful for numbers and dates only.
Filter by values less than this parameter. Useful for numbers and dates only.
Filter by values less than or equal to this parameter. Useful for numbers and dates only.
Apply a like filter. Useful for strings only.
Apply a regex filter. Useful for strings only.
Apply a case-insensitive like filter. Useful for strings only.
Filter to apply on full-text properties.
Filter arrays that have overlapping values with this parameter.
Filter arrays that have overlapping values with this parameter.
Filter arrays that contain some of the values of this parameter.
Filter arrays that contain some of the values of this parameter.
Filter arrays that contain all values of this parameter.
Filter arrays that contain all values of this parameter.
Filter by whether a value for this parameter exists (not null).
Join query parameters with an AND condition. Each object's content is the same type as the expected query parameters.
Join query parameters with an OR condition. Each object's content is the same type as the expected query parameters.
Filter by a currency code. The promotions are filtered based on their application method's currency code.
Filter by an application method type. The promotions are filtered based on their application method's type.
Whether to include deleted records in the result.
Filter by a promotion's ID.
OK
The paginated list of promotions. The paginated list of promotions.
The maximum number of items returned.
The number of items skipped before retrieving the returned items.
The total number of items.
The list of promotions.
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.