* fixed typedoc plugin's escape strategy * move props comments to the associated property * regenerate references
4682 lines
156 KiB
Plaintext
4682 lines
156 KiB
Plaintext
---
|
|
displayed_sidebar: jsClientSidebar
|
|
slug: /references/js-client/AdminDiscountsResource
|
|
---
|
|
|
|
import ParameterTypes from "@site/src/components/ParameterTypes"
|
|
|
|
# AdminDiscountsResource
|
|
|
|
This class is used to send requests to [Admin Discount API Routes](https://docs.medusajs.com/api/admin#discounts). All its method
|
|
are available in the JS Client under the `medusa.admin.discounts` property.
|
|
|
|
All methods in this class require [user authentication](AdminAuthResource.mdx#createsession).
|
|
|
|
Admins can create discounts with conditions and rules, providing them with advanced settings for variety of cases.
|
|
The methods in this class can be used to manage discounts, their conditions, resources, and more.
|
|
|
|
Related Guide: [How to manage discounts](https://docs.medusajs.com/modules/discounts/admin/manage-discounts).
|
|
|
|
## Methods
|
|
|
|
### addConditionResourceBatch
|
|
|
|
Add a batch of resources to a discount condition. The type of resource depends on the type of discount condition. For example, if the discount condition's type is `products`,
|
|
the resources being added should be products.
|
|
|
|
#### Example
|
|
|
|
To add resources to a discount condition:
|
|
|
|
```ts
|
|
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.discounts
|
|
.addConditionResourceBatch(discountId, conditionId, {
|
|
resources: [{ id: itemId }],
|
|
})
|
|
.then(({ discount }) => {
|
|
console.log(discount.id)
|
|
})
|
|
```
|
|
|
|
To specify relations to include in the returned discount:
|
|
|
|
```ts
|
|
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.discounts
|
|
.addConditionResourceBatch(
|
|
discountId,
|
|
conditionId,
|
|
{
|
|
resources: [{ id: itemId }],
|
|
},
|
|
{
|
|
expand: "rule",
|
|
}
|
|
)
|
|
.then(({ discount }) => {
|
|
console.log(discount.id)
|
|
})
|
|
```
|
|
|
|
#### Parameters
|
|
|
|
<ParameterTypes parameters={[
|
|
{
|
|
"name": "discountId",
|
|
"type": "`string`",
|
|
"description": "The ID of the discount the condition belongs to.",
|
|
"optional": false,
|
|
"defaultValue": "",
|
|
"expandable": false,
|
|
"children": []
|
|
},
|
|
{
|
|
"name": "conditionId",
|
|
"type": "`string`",
|
|
"description": "The ID of the discount condition.",
|
|
"optional": false,
|
|
"defaultValue": "",
|
|
"expandable": false,
|
|
"children": []
|
|
},
|
|
{
|
|
"name": "payload",
|
|
"type": "[AdminPostDiscountsDiscountConditionsConditionBatchReq](../internal/classes/internal.AdminPostDiscountsDiscountConditionsConditionBatchReq.mdx)",
|
|
"description": "The resources to add to the discount condition.",
|
|
"optional": false,
|
|
"defaultValue": "",
|
|
"expandable": false,
|
|
"children": [
|
|
{
|
|
"name": "resources",
|
|
"type": "``{ id: string }``[]",
|
|
"description": "The resources to be added to the discount condition",
|
|
"optional": false,
|
|
"defaultValue": "",
|
|
"expandable": false,
|
|
"children": [
|
|
{
|
|
"name": "id",
|
|
"type": "`string`",
|
|
"description": "The ID of the item",
|
|
"optional": false,
|
|
"defaultValue": "",
|
|
"expandable": false,
|
|
"children": []
|
|
}
|
|
]
|
|
}
|
|
]
|
|
},
|
|
{
|
|
"name": "query",
|
|
"type": "[AdminPostDiscountsDiscountConditionsConditionBatchParams](../internal/classes/internal.AdminPostDiscountsDiscountConditionsConditionBatchParams.mdx)",
|
|
"description": "Configurations to apply on the retrieved discount.",
|
|
"optional": true,
|
|
"defaultValue": "",
|
|
"expandable": false,
|
|
"children": [
|
|
{
|
|
"name": "expand",
|
|
"type": "`string`",
|
|
"description": "Comma-separated relations that should be expanded in the returned data.",
|
|
"optional": true,
|
|
"defaultValue": "",
|
|
"expandable": false,
|
|
"children": []
|
|
},
|
|
{
|
|
"name": "fields",
|
|
"type": "`string`",
|
|
"description": "Comma-separated fields that should be included in the returned data.",
|
|
"optional": true,
|
|
"defaultValue": "",
|
|
"expandable": false,
|
|
"children": []
|
|
}
|
|
]
|
|
},
|
|
{
|
|
"name": "customHeaders",
|
|
"type": "`Record<string, any>`",
|
|
"description": "Custom headers to attach to the request.",
|
|
"optional": false,
|
|
"defaultValue": "{}",
|
|
"expandable": false,
|
|
"children": []
|
|
}
|
|
]} />
|
|
|
|
#### Returns
|
|
|
|
<ParameterTypes parameters={[
|
|
{
|
|
"name": "ResponsePromise",
|
|
"type": "[ResponsePromise](../internal/types/internal.ResponsePromise.mdx)<[AdminDiscountsRes](../internal/types/internal.AdminDiscountsRes.mdx)>",
|
|
"optional": false,
|
|
"defaultValue": "",
|
|
"description": "Resolves to the details of the discount.",
|
|
"expandable": false,
|
|
"children": [
|
|
{
|
|
"name": "AdminDiscountsRes",
|
|
"type": "`object`",
|
|
"description": "The discount's details.",
|
|
"optional": false,
|
|
"defaultValue": "",
|
|
"expandable": false,
|
|
"children": [
|
|
{
|
|
"name": "discount",
|
|
"type": "[Discount](../internal/classes/internal.Discount-1.mdx)",
|
|
"description": "Discount details.",
|
|
"optional": false,
|
|
"defaultValue": "",
|
|
"expandable": false,
|
|
"children": [
|
|
{
|
|
"name": "code",
|
|
"type": "`string`",
|
|
"description": "A unique code for the discount - this will be used by the customer to apply the discount",
|
|
"optional": false,
|
|
"defaultValue": "",
|
|
"expandable": false,
|
|
"children": []
|
|
},
|
|
{
|
|
"name": "created_at",
|
|
"type": "`Date`",
|
|
"description": "The date with timezone at which the resource was created.",
|
|
"optional": false,
|
|
"defaultValue": "",
|
|
"expandable": false,
|
|
"children": []
|
|
},
|
|
{
|
|
"name": "deleted_at",
|
|
"type": "`null` \\| `Date`",
|
|
"description": "The date with timezone at which the resource was deleted.",
|
|
"optional": false,
|
|
"defaultValue": "",
|
|
"expandable": false,
|
|
"children": []
|
|
},
|
|
{
|
|
"name": "ends_at",
|
|
"type": "`null` \\| `Date`",
|
|
"description": "The time at which the discount can no longer be used.",
|
|
"optional": false,
|
|
"defaultValue": "",
|
|
"expandable": false,
|
|
"children": []
|
|
},
|
|
{
|
|
"name": "id",
|
|
"type": "`string`",
|
|
"description": "The discount's ID",
|
|
"optional": false,
|
|
"defaultValue": "",
|
|
"expandable": false,
|
|
"children": []
|
|
},
|
|
{
|
|
"name": "is_disabled",
|
|
"type": "`boolean`",
|
|
"description": "Whether the Discount has been disabled. Disabled discounts cannot be applied to carts",
|
|
"optional": false,
|
|
"defaultValue": "",
|
|
"expandable": false,
|
|
"children": []
|
|
},
|
|
{
|
|
"name": "is_dynamic",
|
|
"type": "`boolean`",
|
|
"description": "A flag to indicate if multiple instances of the discount can be generated. I.e. for newsletter discounts",
|
|
"optional": false,
|
|
"defaultValue": "",
|
|
"expandable": false,
|
|
"children": []
|
|
},
|
|
{
|
|
"name": "metadata",
|
|
"type": "`Record<string, unknown>`",
|
|
"description": "An optional key-value map with additional details",
|
|
"optional": false,
|
|
"defaultValue": "",
|
|
"expandable": false,
|
|
"children": []
|
|
},
|
|
{
|
|
"name": "parent_discount",
|
|
"type": "[Discount](../internal/classes/internal.Discount-1.mdx)",
|
|
"description": "The details of the parent discount that this discount was created from.",
|
|
"optional": false,
|
|
"defaultValue": "",
|
|
"expandable": true,
|
|
"children": []
|
|
},
|
|
{
|
|
"name": "parent_discount_id",
|
|
"type": "`string`",
|
|
"description": "The Discount that the discount was created from. This will always be a dynamic discount",
|
|
"optional": false,
|
|
"defaultValue": "",
|
|
"expandable": false,
|
|
"children": []
|
|
},
|
|
{
|
|
"name": "regions",
|
|
"type": "[Region](../internal/classes/internal.Region.mdx)[]",
|
|
"description": "The details of the regions in which the Discount can be used.",
|
|
"optional": false,
|
|
"defaultValue": "",
|
|
"expandable": true,
|
|
"children": []
|
|
},
|
|
{
|
|
"name": "rule",
|
|
"type": "[DiscountRule](../internal/classes/internal.internal.DiscountRule.mdx)",
|
|
"description": "The details of the discount rule that defines how the discount will be applied to a cart..",
|
|
"optional": false,
|
|
"defaultValue": "",
|
|
"expandable": true,
|
|
"children": []
|
|
},
|
|
{
|
|
"name": "rule_id",
|
|
"type": "`string`",
|
|
"description": "The ID of the discount rule that defines how the discount will be applied to a cart.",
|
|
"optional": false,
|
|
"defaultValue": "",
|
|
"expandable": false,
|
|
"children": []
|
|
},
|
|
{
|
|
"name": "starts_at",
|
|
"type": "`Date`",
|
|
"description": "The time at which the discount can be used.",
|
|
"optional": false,
|
|
"defaultValue": "",
|
|
"expandable": false,
|
|
"children": []
|
|
},
|
|
{
|
|
"name": "updated_at",
|
|
"type": "`Date`",
|
|
"description": "The date with timezone at which the resource was updated.",
|
|
"optional": false,
|
|
"defaultValue": "",
|
|
"expandable": false,
|
|
"children": []
|
|
},
|
|
{
|
|
"name": "usage_count",
|
|
"type": "`number`",
|
|
"description": "The number of times a discount has been used.",
|
|
"optional": false,
|
|
"defaultValue": "0",
|
|
"expandable": false,
|
|
"children": []
|
|
},
|
|
{
|
|
"name": "usage_limit",
|
|
"type": "`null` \\| `number`",
|
|
"description": "The maximum number of times that a discount can be used.",
|
|
"optional": false,
|
|
"defaultValue": "",
|
|
"expandable": false,
|
|
"children": []
|
|
},
|
|
{
|
|
"name": "valid_duration",
|
|
"type": "`null` \\| `string`",
|
|
"description": "Duration the discount runs between",
|
|
"optional": false,
|
|
"defaultValue": "",
|
|
"expandable": false,
|
|
"children": []
|
|
}
|
|
]
|
|
}
|
|
]
|
|
}
|
|
]
|
|
}
|
|
]} />
|
|
|
|
___
|
|
|
|
### addRegion
|
|
|
|
Add a Region to the list of Regions a Discount can be used in.
|
|
|
|
#### Example
|
|
|
|
```ts
|
|
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.discounts.addRegion(discountId, regionId).then(({ discount }) => {
|
|
console.log(discount.id)
|
|
})
|
|
```
|
|
|
|
#### Parameters
|
|
|
|
<ParameterTypes parameters={[
|
|
{
|
|
"name": "id",
|
|
"type": "`string`",
|
|
"description": "The discount's ID.",
|
|
"optional": false,
|
|
"defaultValue": "",
|
|
"expandable": false,
|
|
"children": []
|
|
},
|
|
{
|
|
"name": "regionId",
|
|
"type": "`string`",
|
|
"description": "The ID of the region to add.",
|
|
"optional": false,
|
|
"defaultValue": "",
|
|
"expandable": false,
|
|
"children": []
|
|
},
|
|
{
|
|
"name": "customHeaders",
|
|
"type": "`Record<string, any>`",
|
|
"description": "Custom headers to attach to the request.",
|
|
"optional": false,
|
|
"defaultValue": "{}",
|
|
"expandable": false,
|
|
"children": []
|
|
}
|
|
]} />
|
|
|
|
#### Returns
|
|
|
|
<ParameterTypes parameters={[
|
|
{
|
|
"name": "ResponsePromise",
|
|
"type": "[ResponsePromise](../internal/types/internal.ResponsePromise.mdx)<[AdminDiscountsRes](../internal/types/internal.AdminDiscountsRes.mdx)>",
|
|
"optional": false,
|
|
"defaultValue": "",
|
|
"description": "Resolves to the discount's details.",
|
|
"expandable": false,
|
|
"children": [
|
|
{
|
|
"name": "AdminDiscountsRes",
|
|
"type": "`object`",
|
|
"description": "The discount's details.",
|
|
"optional": false,
|
|
"defaultValue": "",
|
|
"expandable": false,
|
|
"children": [
|
|
{
|
|
"name": "discount",
|
|
"type": "[Discount](../internal/classes/internal.Discount-1.mdx)",
|
|
"description": "Discount details.",
|
|
"optional": false,
|
|
"defaultValue": "",
|
|
"expandable": false,
|
|
"children": [
|
|
{
|
|
"name": "code",
|
|
"type": "`string`",
|
|
"description": "A unique code for the discount - this will be used by the customer to apply the discount",
|
|
"optional": false,
|
|
"defaultValue": "",
|
|
"expandable": false,
|
|
"children": []
|
|
},
|
|
{
|
|
"name": "created_at",
|
|
"type": "`Date`",
|
|
"description": "The date with timezone at which the resource was created.",
|
|
"optional": false,
|
|
"defaultValue": "",
|
|
"expandable": false,
|
|
"children": []
|
|
},
|
|
{
|
|
"name": "deleted_at",
|
|
"type": "`null` \\| `Date`",
|
|
"description": "The date with timezone at which the resource was deleted.",
|
|
"optional": false,
|
|
"defaultValue": "",
|
|
"expandable": false,
|
|
"children": []
|
|
},
|
|
{
|
|
"name": "ends_at",
|
|
"type": "`null` \\| `Date`",
|
|
"description": "The time at which the discount can no longer be used.",
|
|
"optional": false,
|
|
"defaultValue": "",
|
|
"expandable": false,
|
|
"children": []
|
|
},
|
|
{
|
|
"name": "id",
|
|
"type": "`string`",
|
|
"description": "The discount's ID",
|
|
"optional": false,
|
|
"defaultValue": "",
|
|
"expandable": false,
|
|
"children": []
|
|
},
|
|
{
|
|
"name": "is_disabled",
|
|
"type": "`boolean`",
|
|
"description": "Whether the Discount has been disabled. Disabled discounts cannot be applied to carts",
|
|
"optional": false,
|
|
"defaultValue": "",
|
|
"expandable": false,
|
|
"children": []
|
|
},
|
|
{
|
|
"name": "is_dynamic",
|
|
"type": "`boolean`",
|
|
"description": "A flag to indicate if multiple instances of the discount can be generated. I.e. for newsletter discounts",
|
|
"optional": false,
|
|
"defaultValue": "",
|
|
"expandable": false,
|
|
"children": []
|
|
},
|
|
{
|
|
"name": "metadata",
|
|
"type": "`Record<string, unknown>`",
|
|
"description": "An optional key-value map with additional details",
|
|
"optional": false,
|
|
"defaultValue": "",
|
|
"expandable": false,
|
|
"children": []
|
|
},
|
|
{
|
|
"name": "parent_discount",
|
|
"type": "[Discount](../internal/classes/internal.Discount-1.mdx)",
|
|
"description": "The details of the parent discount that this discount was created from.",
|
|
"optional": false,
|
|
"defaultValue": "",
|
|
"expandable": true,
|
|
"children": []
|
|
},
|
|
{
|
|
"name": "parent_discount_id",
|
|
"type": "`string`",
|
|
"description": "The Discount that the discount was created from. This will always be a dynamic discount",
|
|
"optional": false,
|
|
"defaultValue": "",
|
|
"expandable": false,
|
|
"children": []
|
|
},
|
|
{
|
|
"name": "regions",
|
|
"type": "[Region](../internal/classes/internal.Region.mdx)[]",
|
|
"description": "The details of the regions in which the Discount can be used.",
|
|
"optional": false,
|
|
"defaultValue": "",
|
|
"expandable": true,
|
|
"children": []
|
|
},
|
|
{
|
|
"name": "rule",
|
|
"type": "[DiscountRule](../internal/classes/internal.internal.DiscountRule.mdx)",
|
|
"description": "The details of the discount rule that defines how the discount will be applied to a cart..",
|
|
"optional": false,
|
|
"defaultValue": "",
|
|
"expandable": true,
|
|
"children": []
|
|
},
|
|
{
|
|
"name": "rule_id",
|
|
"type": "`string`",
|
|
"description": "The ID of the discount rule that defines how the discount will be applied to a cart.",
|
|
"optional": false,
|
|
"defaultValue": "",
|
|
"expandable": false,
|
|
"children": []
|
|
},
|
|
{
|
|
"name": "starts_at",
|
|
"type": "`Date`",
|
|
"description": "The time at which the discount can be used.",
|
|
"optional": false,
|
|
"defaultValue": "",
|
|
"expandable": false,
|
|
"children": []
|
|
},
|
|
{
|
|
"name": "updated_at",
|
|
"type": "`Date`",
|
|
"description": "The date with timezone at which the resource was updated.",
|
|
"optional": false,
|
|
"defaultValue": "",
|
|
"expandable": false,
|
|
"children": []
|
|
},
|
|
{
|
|
"name": "usage_count",
|
|
"type": "`number`",
|
|
"description": "The number of times a discount has been used.",
|
|
"optional": false,
|
|
"defaultValue": "0",
|
|
"expandable": false,
|
|
"children": []
|
|
},
|
|
{
|
|
"name": "usage_limit",
|
|
"type": "`null` \\| `number`",
|
|
"description": "The maximum number of times that a discount can be used.",
|
|
"optional": false,
|
|
"defaultValue": "",
|
|
"expandable": false,
|
|
"children": []
|
|
},
|
|
{
|
|
"name": "valid_duration",
|
|
"type": "`null` \\| `string`",
|
|
"description": "Duration the discount runs between",
|
|
"optional": false,
|
|
"defaultValue": "",
|
|
"expandable": false,
|
|
"children": []
|
|
}
|
|
]
|
|
}
|
|
]
|
|
}
|
|
]
|
|
}
|
|
]} />
|
|
|
|
___
|
|
|
|
### create
|
|
|
|
Create a discount with a given set of rules that defines how the discount is applied.
|
|
|
|
#### Example
|
|
|
|
```ts
|
|
import Medusa from "@medusajs/medusa-js"
|
|
import { AllocationType, DiscountRuleType } from "@medusajs/medusa"
|
|
const medusa = new Medusa({ baseUrl: MEDUSA_BACKEND_URL, maxRetries: 3 })
|
|
// must be previously logged in or use api token
|
|
medusa.admin.discounts
|
|
.create({
|
|
code: "TEST",
|
|
rule: {
|
|
type: DiscountRuleType.FIXED,
|
|
value: 10,
|
|
allocation: AllocationType.ITEM,
|
|
},
|
|
regions: ["reg_XXXXXXXX"],
|
|
is_dynamic: false,
|
|
is_disabled: false,
|
|
})
|
|
.then(({ discount }) => {
|
|
console.log(discount.id)
|
|
})
|
|
```
|
|
|
|
#### Parameters
|
|
|
|
<ParameterTypes parameters={[
|
|
{
|
|
"name": "payload",
|
|
"type": "[AdminPostDiscountsReq](../internal/classes/internal.AdminPostDiscountsReq.mdx)",
|
|
"description": "The discount to create.",
|
|
"optional": false,
|
|
"defaultValue": "",
|
|
"expandable": false,
|
|
"children": [
|
|
{
|
|
"name": "code",
|
|
"type": "`string`",
|
|
"description": "A unique code that will be used to redeem the discount",
|
|
"optional": false,
|
|
"defaultValue": "",
|
|
"expandable": false,
|
|
"children": []
|
|
},
|
|
{
|
|
"name": "ends_at",
|
|
"type": "`Date`",
|
|
"description": "The date and time at which the discount should no longer be available.",
|
|
"optional": true,
|
|
"defaultValue": "",
|
|
"expandable": false,
|
|
"children": []
|
|
},
|
|
{
|
|
"name": "is_disabled",
|
|
"type": "`boolean`",
|
|
"description": "Whether the discount code is disabled on creation. If set to `true`, it will not be available for customers.",
|
|
"optional": false,
|
|
"defaultValue": "false",
|
|
"expandable": false,
|
|
"children": []
|
|
},
|
|
{
|
|
"name": "is_dynamic",
|
|
"type": "`boolean`",
|
|
"description": "Whether the discount should have multiple instances of itself, each with a different code. This can be useful for automatically generated discount codes that all have to follow a common set of rules.",
|
|
"optional": false,
|
|
"defaultValue": "false",
|
|
"expandable": false,
|
|
"children": []
|
|
},
|
|
{
|
|
"name": "metadata",
|
|
"type": "`Record<string, unknown>`",
|
|
"description": "An optional set of key-value pairs to hold additional information.",
|
|
"optional": true,
|
|
"defaultValue": "",
|
|
"expandable": false,
|
|
"children": []
|
|
},
|
|
{
|
|
"name": "regions",
|
|
"type": "`string`[]",
|
|
"description": "A list of region IDs representing the Regions in which the Discount can be used.",
|
|
"optional": false,
|
|
"defaultValue": "",
|
|
"expandable": false,
|
|
"children": []
|
|
},
|
|
{
|
|
"name": "rule",
|
|
"type": "[AdminPostDiscountsDiscountRule](../internal/classes/internal.AdminPostDiscountsDiscountRule.mdx)",
|
|
"description": "The discount rule that defines how discounts are calculated",
|
|
"optional": false,
|
|
"defaultValue": "",
|
|
"expandable": false,
|
|
"children": [
|
|
{
|
|
"name": "allocation",
|
|
"type": "[AllocationType](../internal/enums/internal.internal.AllocationType.mdx)",
|
|
"description": "The discount rule's allocation.",
|
|
"optional": false,
|
|
"defaultValue": "",
|
|
"expandable": false,
|
|
"children": [
|
|
{
|
|
"name": "ITEM",
|
|
"type": "`\"item\"`",
|
|
"description": "The discount should be applied to applicable items in the cart.",
|
|
"optional": true,
|
|
"defaultValue": "",
|
|
"expandable": false,
|
|
"children": []
|
|
},
|
|
{
|
|
"name": "TOTAL",
|
|
"type": "`\"total\"`",
|
|
"description": "The discount should be applied to the checkout total.",
|
|
"optional": true,
|
|
"defaultValue": "",
|
|
"expandable": false,
|
|
"children": []
|
|
}
|
|
]
|
|
},
|
|
{
|
|
"name": "conditions",
|
|
"type": "[AdminCreateCondition](../internal/classes/internal.internal.AdminCreateCondition.mdx)[]",
|
|
"description": "The discount rule's conditions.",
|
|
"optional": true,
|
|
"defaultValue": "",
|
|
"expandable": false,
|
|
"children": [
|
|
{
|
|
"name": "customer_groups",
|
|
"type": "`string`[]",
|
|
"description": "The customer groups associated with the discount condition, if the discount condition's type is `customer_groups`.",
|
|
"optional": true,
|
|
"defaultValue": "",
|
|
"expandable": false,
|
|
"children": []
|
|
},
|
|
{
|
|
"name": "operator",
|
|
"type": "[DiscountConditionOperator](../internal/enums/internal.DiscountConditionOperator.mdx)",
|
|
"description": "The operator of the discount condition.",
|
|
"optional": false,
|
|
"defaultValue": "",
|
|
"expandable": false,
|
|
"children": []
|
|
},
|
|
{
|
|
"name": "product_collections",
|
|
"type": "`string`[]",
|
|
"description": "The product collections associated with the discount condition, if the discount condition's type is `product_collections`.",
|
|
"optional": true,
|
|
"defaultValue": "",
|
|
"expandable": false,
|
|
"children": []
|
|
},
|
|
{
|
|
"name": "product_tags",
|
|
"type": "`string`[]",
|
|
"description": "The product tags associated with the discount condition, if the discount condition's type is `product_tags`.",
|
|
"optional": true,
|
|
"defaultValue": "",
|
|
"expandable": false,
|
|
"children": []
|
|
},
|
|
{
|
|
"name": "product_types",
|
|
"type": "`string`[]",
|
|
"description": "The product types associated with the discount condition, if the discount condition's type is `product_types`.",
|
|
"optional": true,
|
|
"defaultValue": "",
|
|
"expandable": false,
|
|
"children": []
|
|
},
|
|
{
|
|
"name": "products",
|
|
"type": "`string`[]",
|
|
"description": "The products associated with the discount condition, if the discount condition's type is `products`.",
|
|
"optional": true,
|
|
"defaultValue": "",
|
|
"expandable": false,
|
|
"children": []
|
|
}
|
|
]
|
|
},
|
|
{
|
|
"name": "description",
|
|
"type": "`string`",
|
|
"description": "The discount rule's description.",
|
|
"optional": true,
|
|
"defaultValue": "",
|
|
"expandable": false,
|
|
"children": []
|
|
},
|
|
{
|
|
"name": "type",
|
|
"type": "[DiscountRuleType](../internal/enums/internal.internal.DiscountRuleType.mdx)",
|
|
"description": "The discount rule's type.",
|
|
"optional": false,
|
|
"defaultValue": "",
|
|
"expandable": false,
|
|
"children": [
|
|
{
|
|
"name": "FIXED",
|
|
"type": "`\"fixed\"`",
|
|
"description": "Discounts that reduce the price by a fixed amount.",
|
|
"optional": true,
|
|
"defaultValue": "",
|
|
"expandable": false,
|
|
"children": []
|
|
},
|
|
{
|
|
"name": "FREE_SHIPPING",
|
|
"type": "`\"free_shipping\"`",
|
|
"description": "Discounts that sets the shipping price to `0`.",
|
|
"optional": true,
|
|
"defaultValue": "",
|
|
"expandable": false,
|
|
"children": []
|
|
},
|
|
{
|
|
"name": "PERCENTAGE",
|
|
"type": "`\"percentage\"`",
|
|
"description": "Discounts that reduce the price by a percentage reduction.",
|
|
"optional": true,
|
|
"defaultValue": "",
|
|
"expandable": false,
|
|
"children": []
|
|
}
|
|
]
|
|
},
|
|
{
|
|
"name": "value",
|
|
"type": "`number`",
|
|
"description": "The discount rule's value.",
|
|
"optional": false,
|
|
"defaultValue": "",
|
|
"expandable": false,
|
|
"children": []
|
|
}
|
|
]
|
|
},
|
|
{
|
|
"name": "starts_at",
|
|
"type": "`Date`",
|
|
"description": "The date and time at which the discount should be available.",
|
|
"optional": true,
|
|
"defaultValue": "",
|
|
"expandable": false,
|
|
"children": []
|
|
},
|
|
{
|
|
"name": "usage_limit",
|
|
"type": "`number`",
|
|
"description": "Maximum number of times the discount can be used",
|
|
"optional": true,
|
|
"defaultValue": "",
|
|
"expandable": false,
|
|
"children": []
|
|
},
|
|
{
|
|
"name": "valid_duration",
|
|
"type": "`string`",
|
|
"description": "The duration the discount runs between",
|
|
"optional": true,
|
|
"defaultValue": "",
|
|
"expandable": false,
|
|
"children": []
|
|
}
|
|
]
|
|
},
|
|
{
|
|
"name": "customHeaders",
|
|
"type": "`Record<string, any>`",
|
|
"description": "Custom headers to attach to the request.",
|
|
"optional": false,
|
|
"defaultValue": "{}",
|
|
"expandable": false,
|
|
"children": []
|
|
}
|
|
]} />
|
|
|
|
#### Returns
|
|
|
|
<ParameterTypes parameters={[
|
|
{
|
|
"name": "ResponsePromise",
|
|
"type": "[ResponsePromise](../internal/types/internal.ResponsePromise.mdx)<[AdminDiscountsRes](../internal/types/internal.AdminDiscountsRes.mdx)>",
|
|
"optional": false,
|
|
"defaultValue": "",
|
|
"description": "Resolves to the discount's details.",
|
|
"expandable": false,
|
|
"children": [
|
|
{
|
|
"name": "AdminDiscountsRes",
|
|
"type": "`object`",
|
|
"description": "The discount's details.",
|
|
"optional": false,
|
|
"defaultValue": "",
|
|
"expandable": false,
|
|
"children": [
|
|
{
|
|
"name": "discount",
|
|
"type": "[Discount](../internal/classes/internal.Discount-1.mdx)",
|
|
"description": "Discount details.",
|
|
"optional": false,
|
|
"defaultValue": "",
|
|
"expandable": false,
|
|
"children": [
|
|
{
|
|
"name": "code",
|
|
"type": "`string`",
|
|
"description": "A unique code for the discount - this will be used by the customer to apply the discount",
|
|
"optional": false,
|
|
"defaultValue": "",
|
|
"expandable": false,
|
|
"children": []
|
|
},
|
|
{
|
|
"name": "created_at",
|
|
"type": "`Date`",
|
|
"description": "The date with timezone at which the resource was created.",
|
|
"optional": false,
|
|
"defaultValue": "",
|
|
"expandable": false,
|
|
"children": []
|
|
},
|
|
{
|
|
"name": "deleted_at",
|
|
"type": "`null` \\| `Date`",
|
|
"description": "The date with timezone at which the resource was deleted.",
|
|
"optional": false,
|
|
"defaultValue": "",
|
|
"expandable": false,
|
|
"children": []
|
|
},
|
|
{
|
|
"name": "ends_at",
|
|
"type": "`null` \\| `Date`",
|
|
"description": "The time at which the discount can no longer be used.",
|
|
"optional": false,
|
|
"defaultValue": "",
|
|
"expandable": false,
|
|
"children": []
|
|
},
|
|
{
|
|
"name": "id",
|
|
"type": "`string`",
|
|
"description": "The discount's ID",
|
|
"optional": false,
|
|
"defaultValue": "",
|
|
"expandable": false,
|
|
"children": []
|
|
},
|
|
{
|
|
"name": "is_disabled",
|
|
"type": "`boolean`",
|
|
"description": "Whether the Discount has been disabled. Disabled discounts cannot be applied to carts",
|
|
"optional": false,
|
|
"defaultValue": "",
|
|
"expandable": false,
|
|
"children": []
|
|
},
|
|
{
|
|
"name": "is_dynamic",
|
|
"type": "`boolean`",
|
|
"description": "A flag to indicate if multiple instances of the discount can be generated. I.e. for newsletter discounts",
|
|
"optional": false,
|
|
"defaultValue": "",
|
|
"expandable": false,
|
|
"children": []
|
|
},
|
|
{
|
|
"name": "metadata",
|
|
"type": "`Record<string, unknown>`",
|
|
"description": "An optional key-value map with additional details",
|
|
"optional": false,
|
|
"defaultValue": "",
|
|
"expandable": false,
|
|
"children": []
|
|
},
|
|
{
|
|
"name": "parent_discount",
|
|
"type": "[Discount](../internal/classes/internal.Discount-1.mdx)",
|
|
"description": "The details of the parent discount that this discount was created from.",
|
|
"optional": false,
|
|
"defaultValue": "",
|
|
"expandable": true,
|
|
"children": []
|
|
},
|
|
{
|
|
"name": "parent_discount_id",
|
|
"type": "`string`",
|
|
"description": "The Discount that the discount was created from. This will always be a dynamic discount",
|
|
"optional": false,
|
|
"defaultValue": "",
|
|
"expandable": false,
|
|
"children": []
|
|
},
|
|
{
|
|
"name": "regions",
|
|
"type": "[Region](../internal/classes/internal.Region.mdx)[]",
|
|
"description": "The details of the regions in which the Discount can be used.",
|
|
"optional": false,
|
|
"defaultValue": "",
|
|
"expandable": true,
|
|
"children": []
|
|
},
|
|
{
|
|
"name": "rule",
|
|
"type": "[DiscountRule](../internal/classes/internal.internal.DiscountRule.mdx)",
|
|
"description": "The details of the discount rule that defines how the discount will be applied to a cart..",
|
|
"optional": false,
|
|
"defaultValue": "",
|
|
"expandable": true,
|
|
"children": []
|
|
},
|
|
{
|
|
"name": "rule_id",
|
|
"type": "`string`",
|
|
"description": "The ID of the discount rule that defines how the discount will be applied to a cart.",
|
|
"optional": false,
|
|
"defaultValue": "",
|
|
"expandable": false,
|
|
"children": []
|
|
},
|
|
{
|
|
"name": "starts_at",
|
|
"type": "`Date`",
|
|
"description": "The time at which the discount can be used.",
|
|
"optional": false,
|
|
"defaultValue": "",
|
|
"expandable": false,
|
|
"children": []
|
|
},
|
|
{
|
|
"name": "updated_at",
|
|
"type": "`Date`",
|
|
"description": "The date with timezone at which the resource was updated.",
|
|
"optional": false,
|
|
"defaultValue": "",
|
|
"expandable": false,
|
|
"children": []
|
|
},
|
|
{
|
|
"name": "usage_count",
|
|
"type": "`number`",
|
|
"description": "The number of times a discount has been used.",
|
|
"optional": false,
|
|
"defaultValue": "0",
|
|
"expandable": false,
|
|
"children": []
|
|
},
|
|
{
|
|
"name": "usage_limit",
|
|
"type": "`null` \\| `number`",
|
|
"description": "The maximum number of times that a discount can be used.",
|
|
"optional": false,
|
|
"defaultValue": "",
|
|
"expandable": false,
|
|
"children": []
|
|
},
|
|
{
|
|
"name": "valid_duration",
|
|
"type": "`null` \\| `string`",
|
|
"description": "Duration the discount runs between",
|
|
"optional": false,
|
|
"defaultValue": "",
|
|
"expandable": false,
|
|
"children": []
|
|
}
|
|
]
|
|
}
|
|
]
|
|
}
|
|
]
|
|
}
|
|
]} />
|
|
|
|
___
|
|
|
|
### createCondition
|
|
|
|
Create a discount condition. Only one of `products`, `product_types`, `product_collections`, `product_tags`, and `customer_groups` should be provided in the `payload` parameter,
|
|
based on the type of discount condition. For example, if the discount condition's type is `products`, the `products` field should be provided in the `payload` parameter.
|
|
|
|
#### Example
|
|
|
|
To create a condition in a discount:
|
|
|
|
```ts
|
|
import Medusa from "@medusajs/medusa-js"
|
|
import { DiscountConditionOperator } from "@medusajs/medusa"
|
|
const medusa = new Medusa({ baseUrl: MEDUSA_BACKEND_URL, maxRetries: 3 })
|
|
// must be previously logged in or use api token
|
|
medusa.admin.discounts
|
|
.createCondition(discountId, {
|
|
operator: DiscountConditionOperator.IN,
|
|
products: [productId],
|
|
})
|
|
.then(({ discount }) => {
|
|
console.log(discount.id)
|
|
})
|
|
```
|
|
|
|
To specify relations that should be retrieved as part of the response:
|
|
|
|
```ts
|
|
import Medusa from "@medusajs/medusa-js"
|
|
import { DiscountConditionOperator } from "@medusajs/medusa"
|
|
const medusa = new Medusa({ baseUrl: MEDUSA_BACKEND_URL, maxRetries: 3 })
|
|
// must be previously logged in or use api token
|
|
medusa.admin.discounts
|
|
.createCondition(
|
|
discountId,
|
|
{
|
|
operator: DiscountConditionOperator.IN,
|
|
products: [productId],
|
|
},
|
|
{
|
|
expand: "rule",
|
|
}
|
|
)
|
|
.then(({ discount }) => {
|
|
console.log(discount.id)
|
|
})
|
|
```
|
|
|
|
#### Parameters
|
|
|
|
<ParameterTypes parameters={[
|
|
{
|
|
"name": "discountId",
|
|
"type": "`string`",
|
|
"description": "The discount's ID.",
|
|
"optional": false,
|
|
"defaultValue": "",
|
|
"expandable": false,
|
|
"children": []
|
|
},
|
|
{
|
|
"name": "payload",
|
|
"type": "[AdminPostDiscountsDiscountConditions](../internal/classes/internal.AdminPostDiscountsDiscountConditions.mdx)",
|
|
"description": "The discount condition to create.",
|
|
"optional": false,
|
|
"defaultValue": "",
|
|
"expandable": false,
|
|
"children": [
|
|
{
|
|
"name": "customer_groups",
|
|
"type": "`string`[]",
|
|
"description": "The customer groups associated with the discount condition, if the discount condition's type is `customer_groups`.",
|
|
"optional": true,
|
|
"defaultValue": "",
|
|
"expandable": false,
|
|
"children": []
|
|
},
|
|
{
|
|
"name": "operator",
|
|
"type": "[DiscountConditionOperator](../internal/enums/internal.DiscountConditionOperator.mdx)",
|
|
"description": "Operator of the condition. `in` indicates that discountable resources are within the specified resources. `not\\_in` indicates that discountable resources are everything but the specified resources.",
|
|
"optional": false,
|
|
"defaultValue": "",
|
|
"expandable": false,
|
|
"children": [
|
|
{
|
|
"name": "IN",
|
|
"type": "`\"in\"`",
|
|
"description": "The discountable resources are within the specified resources.",
|
|
"optional": true,
|
|
"defaultValue": "",
|
|
"expandable": false,
|
|
"children": []
|
|
},
|
|
{
|
|
"name": "NOT_IN",
|
|
"type": "`\"not_in\"`",
|
|
"description": "The discountable resources are everything but the specified resources.",
|
|
"optional": true,
|
|
"defaultValue": "",
|
|
"expandable": false,
|
|
"children": []
|
|
}
|
|
]
|
|
},
|
|
{
|
|
"name": "product_collections",
|
|
"type": "`string`[]",
|
|
"description": "The product collections associated with the discount condition, if the discount condition's type is `product_collections`.",
|
|
"optional": true,
|
|
"defaultValue": "",
|
|
"expandable": false,
|
|
"children": []
|
|
},
|
|
{
|
|
"name": "product_tags",
|
|
"type": "`string`[]",
|
|
"description": "The product tags associated with the discount condition, if the discount condition's type is `product_tags`.",
|
|
"optional": true,
|
|
"defaultValue": "",
|
|
"expandable": false,
|
|
"children": []
|
|
},
|
|
{
|
|
"name": "product_types",
|
|
"type": "`string`[]",
|
|
"description": "The product types associated with the discount condition, if the discount condition's type is `product_types`.",
|
|
"optional": true,
|
|
"defaultValue": "",
|
|
"expandable": false,
|
|
"children": []
|
|
},
|
|
{
|
|
"name": "products",
|
|
"type": "`string`[]",
|
|
"description": "The products associated with the discount condition, if the discount condition's type is `products`.",
|
|
"optional": true,
|
|
"defaultValue": "",
|
|
"expandable": false,
|
|
"children": []
|
|
}
|
|
]
|
|
},
|
|
{
|
|
"name": "query",
|
|
"type": "[AdminPostDiscountsDiscountConditionsParams](../internal/classes/internal.AdminPostDiscountsDiscountConditionsParams.mdx)",
|
|
"description": "Configurations to apply on the returned discount.",
|
|
"optional": false,
|
|
"defaultValue": "{}",
|
|
"expandable": false,
|
|
"children": [
|
|
{
|
|
"name": "expand",
|
|
"type": "`string`",
|
|
"description": "Comma-separated relations that should be expanded in the returned data.",
|
|
"optional": true,
|
|
"defaultValue": "",
|
|
"expandable": false,
|
|
"children": []
|
|
},
|
|
{
|
|
"name": "fields",
|
|
"type": "`string`",
|
|
"description": "Comma-separated fields that should be included in the returned data.",
|
|
"optional": true,
|
|
"defaultValue": "",
|
|
"expandable": false,
|
|
"children": []
|
|
}
|
|
]
|
|
},
|
|
{
|
|
"name": "customHeaders",
|
|
"type": "`Record<string, any>`",
|
|
"description": "Custom headers to attach to the request.",
|
|
"optional": false,
|
|
"defaultValue": "{}",
|
|
"expandable": false,
|
|
"children": []
|
|
}
|
|
]} />
|
|
|
|
#### Returns
|
|
|
|
<ParameterTypes parameters={[
|
|
{
|
|
"name": "ResponsePromise",
|
|
"type": "[ResponsePromise](../internal/types/internal.ResponsePromise.mdx)<[AdminDiscountsRes](../internal/types/internal.AdminDiscountsRes.mdx)>",
|
|
"optional": false,
|
|
"defaultValue": "",
|
|
"description": "Resolves to the details of the discount.",
|
|
"expandable": false,
|
|
"children": [
|
|
{
|
|
"name": "AdminDiscountsRes",
|
|
"type": "`object`",
|
|
"description": "The discount's details.",
|
|
"optional": false,
|
|
"defaultValue": "",
|
|
"expandable": false,
|
|
"children": [
|
|
{
|
|
"name": "discount",
|
|
"type": "[Discount](../internal/classes/internal.Discount-1.mdx)",
|
|
"description": "Discount details.",
|
|
"optional": false,
|
|
"defaultValue": "",
|
|
"expandable": false,
|
|
"children": [
|
|
{
|
|
"name": "code",
|
|
"type": "`string`",
|
|
"description": "A unique code for the discount - this will be used by the customer to apply the discount",
|
|
"optional": false,
|
|
"defaultValue": "",
|
|
"expandable": false,
|
|
"children": []
|
|
},
|
|
{
|
|
"name": "created_at",
|
|
"type": "`Date`",
|
|
"description": "The date with timezone at which the resource was created.",
|
|
"optional": false,
|
|
"defaultValue": "",
|
|
"expandable": false,
|
|
"children": []
|
|
},
|
|
{
|
|
"name": "deleted_at",
|
|
"type": "`null` \\| `Date`",
|
|
"description": "The date with timezone at which the resource was deleted.",
|
|
"optional": false,
|
|
"defaultValue": "",
|
|
"expandable": false,
|
|
"children": []
|
|
},
|
|
{
|
|
"name": "ends_at",
|
|
"type": "`null` \\| `Date`",
|
|
"description": "The time at which the discount can no longer be used.",
|
|
"optional": false,
|
|
"defaultValue": "",
|
|
"expandable": false,
|
|
"children": []
|
|
},
|
|
{
|
|
"name": "id",
|
|
"type": "`string`",
|
|
"description": "The discount's ID",
|
|
"optional": false,
|
|
"defaultValue": "",
|
|
"expandable": false,
|
|
"children": []
|
|
},
|
|
{
|
|
"name": "is_disabled",
|
|
"type": "`boolean`",
|
|
"description": "Whether the Discount has been disabled. Disabled discounts cannot be applied to carts",
|
|
"optional": false,
|
|
"defaultValue": "",
|
|
"expandable": false,
|
|
"children": []
|
|
},
|
|
{
|
|
"name": "is_dynamic",
|
|
"type": "`boolean`",
|
|
"description": "A flag to indicate if multiple instances of the discount can be generated. I.e. for newsletter discounts",
|
|
"optional": false,
|
|
"defaultValue": "",
|
|
"expandable": false,
|
|
"children": []
|
|
},
|
|
{
|
|
"name": "metadata",
|
|
"type": "`Record<string, unknown>`",
|
|
"description": "An optional key-value map with additional details",
|
|
"optional": false,
|
|
"defaultValue": "",
|
|
"expandable": false,
|
|
"children": []
|
|
},
|
|
{
|
|
"name": "parent_discount",
|
|
"type": "[Discount](../internal/classes/internal.Discount-1.mdx)",
|
|
"description": "The details of the parent discount that this discount was created from.",
|
|
"optional": false,
|
|
"defaultValue": "",
|
|
"expandable": true,
|
|
"children": []
|
|
},
|
|
{
|
|
"name": "parent_discount_id",
|
|
"type": "`string`",
|
|
"description": "The Discount that the discount was created from. This will always be a dynamic discount",
|
|
"optional": false,
|
|
"defaultValue": "",
|
|
"expandable": false,
|
|
"children": []
|
|
},
|
|
{
|
|
"name": "regions",
|
|
"type": "[Region](../internal/classes/internal.Region.mdx)[]",
|
|
"description": "The details of the regions in which the Discount can be used.",
|
|
"optional": false,
|
|
"defaultValue": "",
|
|
"expandable": true,
|
|
"children": []
|
|
},
|
|
{
|
|
"name": "rule",
|
|
"type": "[DiscountRule](../internal/classes/internal.internal.DiscountRule.mdx)",
|
|
"description": "The details of the discount rule that defines how the discount will be applied to a cart..",
|
|
"optional": false,
|
|
"defaultValue": "",
|
|
"expandable": true,
|
|
"children": []
|
|
},
|
|
{
|
|
"name": "rule_id",
|
|
"type": "`string`",
|
|
"description": "The ID of the discount rule that defines how the discount will be applied to a cart.",
|
|
"optional": false,
|
|
"defaultValue": "",
|
|
"expandable": false,
|
|
"children": []
|
|
},
|
|
{
|
|
"name": "starts_at",
|
|
"type": "`Date`",
|
|
"description": "The time at which the discount can be used.",
|
|
"optional": false,
|
|
"defaultValue": "",
|
|
"expandable": false,
|
|
"children": []
|
|
},
|
|
{
|
|
"name": "updated_at",
|
|
"type": "`Date`",
|
|
"description": "The date with timezone at which the resource was updated.",
|
|
"optional": false,
|
|
"defaultValue": "",
|
|
"expandable": false,
|
|
"children": []
|
|
},
|
|
{
|
|
"name": "usage_count",
|
|
"type": "`number`",
|
|
"description": "The number of times a discount has been used.",
|
|
"optional": false,
|
|
"defaultValue": "0",
|
|
"expandable": false,
|
|
"children": []
|
|
},
|
|
{
|
|
"name": "usage_limit",
|
|
"type": "`null` \\| `number`",
|
|
"description": "The maximum number of times that a discount can be used.",
|
|
"optional": false,
|
|
"defaultValue": "",
|
|
"expandable": false,
|
|
"children": []
|
|
},
|
|
{
|
|
"name": "valid_duration",
|
|
"type": "`null` \\| `string`",
|
|
"description": "Duration the discount runs between",
|
|
"optional": false,
|
|
"defaultValue": "",
|
|
"expandable": false,
|
|
"children": []
|
|
}
|
|
]
|
|
}
|
|
]
|
|
}
|
|
]
|
|
}
|
|
]} />
|
|
|
|
___
|
|
|
|
### createDynamicCode
|
|
|
|
Create a dynamic unique code that can map to a parent discount. This is useful if you want to automatically generate codes with the same rules and conditions.
|
|
|
|
#### Example
|
|
|
|
```ts
|
|
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.discounts
|
|
.createDynamicCode(discountId, {
|
|
code: "TEST",
|
|
usage_limit: 1,
|
|
})
|
|
.then(({ discount }) => {
|
|
console.log(discount.id)
|
|
})
|
|
```
|
|
|
|
#### Parameters
|
|
|
|
<ParameterTypes parameters={[
|
|
{
|
|
"name": "id",
|
|
"type": "`string`",
|
|
"description": "The discount's ID.",
|
|
"optional": false,
|
|
"defaultValue": "",
|
|
"expandable": false,
|
|
"children": []
|
|
},
|
|
{
|
|
"name": "payload",
|
|
"type": "[AdminPostDiscountsDiscountDynamicCodesReq](../internal/classes/internal.AdminPostDiscountsDiscountDynamicCodesReq.mdx)",
|
|
"description": "The dynamic code to create.",
|
|
"optional": false,
|
|
"defaultValue": "",
|
|
"expandable": false,
|
|
"children": [
|
|
{
|
|
"name": "code",
|
|
"type": "`string`",
|
|
"description": "A unique code that will be used to redeem the Discount",
|
|
"optional": false,
|
|
"defaultValue": "",
|
|
"expandable": false,
|
|
"children": []
|
|
},
|
|
{
|
|
"name": "metadata",
|
|
"type": "`Record<string, unknown>`",
|
|
"description": "An optional set of key-value pairs to hold additional information.",
|
|
"optional": true,
|
|
"defaultValue": "",
|
|
"expandable": false,
|
|
"children": []
|
|
},
|
|
{
|
|
"name": "usage_limit",
|
|
"type": "`number`",
|
|
"description": "Maximum number of times the discount code can be used",
|
|
"optional": false,
|
|
"defaultValue": "1",
|
|
"expandable": false,
|
|
"children": []
|
|
}
|
|
]
|
|
},
|
|
{
|
|
"name": "customHeaders",
|
|
"type": "`Record<string, any>`",
|
|
"description": "Custom headers to attach to the request.",
|
|
"optional": false,
|
|
"defaultValue": "{}",
|
|
"expandable": false,
|
|
"children": []
|
|
}
|
|
]} />
|
|
|
|
#### Returns
|
|
|
|
<ParameterTypes parameters={[
|
|
{
|
|
"name": "ResponsePromise",
|
|
"type": "[ResponsePromise](../internal/types/internal.ResponsePromise.mdx)<[AdminDiscountsRes](../internal/types/internal.AdminDiscountsRes.mdx)>",
|
|
"optional": false,
|
|
"defaultValue": "",
|
|
"description": "Resolves to the details of the discount.",
|
|
"expandable": false,
|
|
"children": [
|
|
{
|
|
"name": "AdminDiscountsRes",
|
|
"type": "`object`",
|
|
"description": "The discount's details.",
|
|
"optional": false,
|
|
"defaultValue": "",
|
|
"expandable": false,
|
|
"children": [
|
|
{
|
|
"name": "discount",
|
|
"type": "[Discount](../internal/classes/internal.Discount-1.mdx)",
|
|
"description": "Discount details.",
|
|
"optional": false,
|
|
"defaultValue": "",
|
|
"expandable": false,
|
|
"children": [
|
|
{
|
|
"name": "code",
|
|
"type": "`string`",
|
|
"description": "A unique code for the discount - this will be used by the customer to apply the discount",
|
|
"optional": false,
|
|
"defaultValue": "",
|
|
"expandable": false,
|
|
"children": []
|
|
},
|
|
{
|
|
"name": "created_at",
|
|
"type": "`Date`",
|
|
"description": "The date with timezone at which the resource was created.",
|
|
"optional": false,
|
|
"defaultValue": "",
|
|
"expandable": false,
|
|
"children": []
|
|
},
|
|
{
|
|
"name": "deleted_at",
|
|
"type": "`null` \\| `Date`",
|
|
"description": "The date with timezone at which the resource was deleted.",
|
|
"optional": false,
|
|
"defaultValue": "",
|
|
"expandable": false,
|
|
"children": []
|
|
},
|
|
{
|
|
"name": "ends_at",
|
|
"type": "`null` \\| `Date`",
|
|
"description": "The time at which the discount can no longer be used.",
|
|
"optional": false,
|
|
"defaultValue": "",
|
|
"expandable": false,
|
|
"children": []
|
|
},
|
|
{
|
|
"name": "id",
|
|
"type": "`string`",
|
|
"description": "The discount's ID",
|
|
"optional": false,
|
|
"defaultValue": "",
|
|
"expandable": false,
|
|
"children": []
|
|
},
|
|
{
|
|
"name": "is_disabled",
|
|
"type": "`boolean`",
|
|
"description": "Whether the Discount has been disabled. Disabled discounts cannot be applied to carts",
|
|
"optional": false,
|
|
"defaultValue": "",
|
|
"expandable": false,
|
|
"children": []
|
|
},
|
|
{
|
|
"name": "is_dynamic",
|
|
"type": "`boolean`",
|
|
"description": "A flag to indicate if multiple instances of the discount can be generated. I.e. for newsletter discounts",
|
|
"optional": false,
|
|
"defaultValue": "",
|
|
"expandable": false,
|
|
"children": []
|
|
},
|
|
{
|
|
"name": "metadata",
|
|
"type": "`Record<string, unknown>`",
|
|
"description": "An optional key-value map with additional details",
|
|
"optional": false,
|
|
"defaultValue": "",
|
|
"expandable": false,
|
|
"children": []
|
|
},
|
|
{
|
|
"name": "parent_discount",
|
|
"type": "[Discount](../internal/classes/internal.Discount-1.mdx)",
|
|
"description": "The details of the parent discount that this discount was created from.",
|
|
"optional": false,
|
|
"defaultValue": "",
|
|
"expandable": true,
|
|
"children": []
|
|
},
|
|
{
|
|
"name": "parent_discount_id",
|
|
"type": "`string`",
|
|
"description": "The Discount that the discount was created from. This will always be a dynamic discount",
|
|
"optional": false,
|
|
"defaultValue": "",
|
|
"expandable": false,
|
|
"children": []
|
|
},
|
|
{
|
|
"name": "regions",
|
|
"type": "[Region](../internal/classes/internal.Region.mdx)[]",
|
|
"description": "The details of the regions in which the Discount can be used.",
|
|
"optional": false,
|
|
"defaultValue": "",
|
|
"expandable": true,
|
|
"children": []
|
|
},
|
|
{
|
|
"name": "rule",
|
|
"type": "[DiscountRule](../internal/classes/internal.internal.DiscountRule.mdx)",
|
|
"description": "The details of the discount rule that defines how the discount will be applied to a cart..",
|
|
"optional": false,
|
|
"defaultValue": "",
|
|
"expandable": true,
|
|
"children": []
|
|
},
|
|
{
|
|
"name": "rule_id",
|
|
"type": "`string`",
|
|
"description": "The ID of the discount rule that defines how the discount will be applied to a cart.",
|
|
"optional": false,
|
|
"defaultValue": "",
|
|
"expandable": false,
|
|
"children": []
|
|
},
|
|
{
|
|
"name": "starts_at",
|
|
"type": "`Date`",
|
|
"description": "The time at which the discount can be used.",
|
|
"optional": false,
|
|
"defaultValue": "",
|
|
"expandable": false,
|
|
"children": []
|
|
},
|
|
{
|
|
"name": "updated_at",
|
|
"type": "`Date`",
|
|
"description": "The date with timezone at which the resource was updated.",
|
|
"optional": false,
|
|
"defaultValue": "",
|
|
"expandable": false,
|
|
"children": []
|
|
},
|
|
{
|
|
"name": "usage_count",
|
|
"type": "`number`",
|
|
"description": "The number of times a discount has been used.",
|
|
"optional": false,
|
|
"defaultValue": "0",
|
|
"expandable": false,
|
|
"children": []
|
|
},
|
|
{
|
|
"name": "usage_limit",
|
|
"type": "`null` \\| `number`",
|
|
"description": "The maximum number of times that a discount can be used.",
|
|
"optional": false,
|
|
"defaultValue": "",
|
|
"expandable": false,
|
|
"children": []
|
|
},
|
|
{
|
|
"name": "valid_duration",
|
|
"type": "`null` \\| `string`",
|
|
"description": "Duration the discount runs between",
|
|
"optional": false,
|
|
"defaultValue": "",
|
|
"expandable": false,
|
|
"children": []
|
|
}
|
|
]
|
|
}
|
|
]
|
|
}
|
|
]
|
|
}
|
|
]} />
|
|
|
|
___
|
|
|
|
### delete
|
|
|
|
Delete a discount. Deleting the discount will make it unavailable for customers to use.
|
|
|
|
#### Example
|
|
|
|
```ts
|
|
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.discounts.delete(discountId).then(({ id, object, deleted }) => {
|
|
console.log(id)
|
|
})
|
|
```
|
|
|
|
#### Parameters
|
|
|
|
<ParameterTypes parameters={[
|
|
{
|
|
"name": "id",
|
|
"type": "`string`",
|
|
"description": "The discount's ID.",
|
|
"optional": false,
|
|
"defaultValue": "",
|
|
"expandable": false,
|
|
"children": []
|
|
},
|
|
{
|
|
"name": "customHeaders",
|
|
"type": "`Record<string, any>`",
|
|
"description": "Custom headers to attach to the request.",
|
|
"optional": false,
|
|
"defaultValue": "{}",
|
|
"expandable": false,
|
|
"children": []
|
|
}
|
|
]} />
|
|
|
|
#### Returns
|
|
|
|
<ParameterTypes parameters={[
|
|
{
|
|
"name": "ResponsePromise",
|
|
"type": "[ResponsePromise](../internal/types/internal.ResponsePromise.mdx)<[DeleteResponse](../internal/interfaces/internal.DeleteResponse.mdx)>",
|
|
"optional": false,
|
|
"defaultValue": "",
|
|
"description": "Resolves to the delete operation details.",
|
|
"expandable": false,
|
|
"children": [
|
|
{
|
|
"name": "deleted",
|
|
"type": "`boolean`",
|
|
"description": "Whether the item was deleted successfully.",
|
|
"optional": false,
|
|
"defaultValue": "true",
|
|
"expandable": false,
|
|
"children": []
|
|
},
|
|
{
|
|
"name": "id",
|
|
"type": "`string`",
|
|
"description": "The ID of the deleted item.",
|
|
"optional": false,
|
|
"defaultValue": "",
|
|
"expandable": false,
|
|
"children": []
|
|
},
|
|
{
|
|
"name": "object",
|
|
"type": "`string`",
|
|
"description": "The type of the deleted item.",
|
|
"optional": false,
|
|
"defaultValue": "product-collection",
|
|
"expandable": false,
|
|
"children": []
|
|
}
|
|
]
|
|
}
|
|
]} />
|
|
|
|
___
|
|
|
|
### deleteCondition
|
|
|
|
Delete a discount condition. This doesn't delete resources associated to the discount condition.
|
|
|
|
#### Example
|
|
|
|
```ts
|
|
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.discounts
|
|
.deleteCondition(discountId, conditionId)
|
|
.then(({ id, object, deleted }) => {
|
|
console.log(id)
|
|
})
|
|
```
|
|
|
|
#### Parameters
|
|
|
|
<ParameterTypes parameters={[
|
|
{
|
|
"name": "discountId",
|
|
"type": "`string`",
|
|
"description": "The discount's ID.",
|
|
"optional": false,
|
|
"defaultValue": "",
|
|
"expandable": false,
|
|
"children": []
|
|
},
|
|
{
|
|
"name": "conditionId",
|
|
"type": "`string`",
|
|
"description": "The ID of the discount condition.",
|
|
"optional": false,
|
|
"defaultValue": "",
|
|
"expandable": false,
|
|
"children": []
|
|
},
|
|
{
|
|
"name": "customHeaders",
|
|
"type": "`Record<string, any>`",
|
|
"description": "Custom headers to attach to the request.",
|
|
"optional": false,
|
|
"defaultValue": "{}",
|
|
"expandable": false,
|
|
"children": []
|
|
}
|
|
]} />
|
|
|
|
#### Returns
|
|
|
|
<ParameterTypes parameters={[
|
|
{
|
|
"name": "ResponsePromise",
|
|
"type": "[ResponsePromise](../internal/types/internal.ResponsePromise.mdx)<[DeleteResponse](../internal/interfaces/internal.DeleteResponse.mdx)>",
|
|
"optional": false,
|
|
"defaultValue": "",
|
|
"description": "Resolves to the deletion operation details.",
|
|
"expandable": false,
|
|
"children": [
|
|
{
|
|
"name": "deleted",
|
|
"type": "`boolean`",
|
|
"description": "Whether the item was deleted successfully.",
|
|
"optional": false,
|
|
"defaultValue": "true",
|
|
"expandable": false,
|
|
"children": []
|
|
},
|
|
{
|
|
"name": "id",
|
|
"type": "`string`",
|
|
"description": "The ID of the deleted item.",
|
|
"optional": false,
|
|
"defaultValue": "",
|
|
"expandable": false,
|
|
"children": []
|
|
},
|
|
{
|
|
"name": "object",
|
|
"type": "`string`",
|
|
"description": "The type of the deleted item.",
|
|
"optional": false,
|
|
"defaultValue": "product-collection",
|
|
"expandable": false,
|
|
"children": []
|
|
}
|
|
]
|
|
}
|
|
]} />
|
|
|
|
___
|
|
|
|
### deleteConditionResourceBatch
|
|
|
|
Remove a batch of resources from a discount condition. This will only remove the association between the resource and the discount condition, not the resource itself.
|
|
|
|
#### Example
|
|
|
|
```ts
|
|
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.discounts
|
|
.deleteConditionResourceBatch(discountId, conditionId, {
|
|
resources: [{ id: itemId }],
|
|
})
|
|
.then(({ discount }) => {
|
|
console.log(discount.id)
|
|
})
|
|
```
|
|
|
|
#### Parameters
|
|
|
|
<ParameterTypes parameters={[
|
|
{
|
|
"name": "discountId",
|
|
"type": "`string`",
|
|
"description": "The ID of the discount the condition belongs to.",
|
|
"optional": false,
|
|
"defaultValue": "",
|
|
"expandable": false,
|
|
"children": []
|
|
},
|
|
{
|
|
"name": "conditionId",
|
|
"type": "`string`",
|
|
"description": "The ID of the discount condition.",
|
|
"optional": false,
|
|
"defaultValue": "",
|
|
"expandable": false,
|
|
"children": []
|
|
},
|
|
{
|
|
"name": "payload",
|
|
"type": "[AdminDeleteDiscountsDiscountConditionsConditionBatchReq](../internal/classes/internal.AdminDeleteDiscountsDiscountConditionsConditionBatchReq.mdx)",
|
|
"description": "The resources to remove.",
|
|
"optional": false,
|
|
"defaultValue": "",
|
|
"expandable": false,
|
|
"children": [
|
|
{
|
|
"name": "resources",
|
|
"type": "``{ id: string }``[]",
|
|
"description": "The resources to be removed from the discount condition",
|
|
"optional": false,
|
|
"defaultValue": "",
|
|
"expandable": false,
|
|
"children": [
|
|
{
|
|
"name": "id",
|
|
"type": "`string`",
|
|
"description": "The id of the item",
|
|
"optional": false,
|
|
"defaultValue": "",
|
|
"expandable": false,
|
|
"children": []
|
|
}
|
|
]
|
|
}
|
|
]
|
|
},
|
|
{
|
|
"name": "customHeaders",
|
|
"type": "`Record<string, any>`",
|
|
"description": "Custom headers to attach to the request.",
|
|
"optional": false,
|
|
"defaultValue": "{}",
|
|
"expandable": false,
|
|
"children": []
|
|
}
|
|
]} />
|
|
|
|
#### Returns
|
|
|
|
<ParameterTypes parameters={[
|
|
{
|
|
"name": "ResponsePromise",
|
|
"type": "[ResponsePromise](../internal/types/internal.ResponsePromise.mdx)<[AdminDiscountsRes](../internal/types/internal.AdminDiscountsRes.mdx)>",
|
|
"optional": false,
|
|
"defaultValue": "",
|
|
"description": "Resolves to the details of the discount.",
|
|
"expandable": false,
|
|
"children": [
|
|
{
|
|
"name": "AdminDiscountsRes",
|
|
"type": "`object`",
|
|
"description": "The discount's details.",
|
|
"optional": false,
|
|
"defaultValue": "",
|
|
"expandable": false,
|
|
"children": [
|
|
{
|
|
"name": "discount",
|
|
"type": "[Discount](../internal/classes/internal.Discount-1.mdx)",
|
|
"description": "Discount details.",
|
|
"optional": false,
|
|
"defaultValue": "",
|
|
"expandable": false,
|
|
"children": [
|
|
{
|
|
"name": "code",
|
|
"type": "`string`",
|
|
"description": "A unique code for the discount - this will be used by the customer to apply the discount",
|
|
"optional": false,
|
|
"defaultValue": "",
|
|
"expandable": false,
|
|
"children": []
|
|
},
|
|
{
|
|
"name": "created_at",
|
|
"type": "`Date`",
|
|
"description": "The date with timezone at which the resource was created.",
|
|
"optional": false,
|
|
"defaultValue": "",
|
|
"expandable": false,
|
|
"children": []
|
|
},
|
|
{
|
|
"name": "deleted_at",
|
|
"type": "`null` \\| `Date`",
|
|
"description": "The date with timezone at which the resource was deleted.",
|
|
"optional": false,
|
|
"defaultValue": "",
|
|
"expandable": false,
|
|
"children": []
|
|
},
|
|
{
|
|
"name": "ends_at",
|
|
"type": "`null` \\| `Date`",
|
|
"description": "The time at which the discount can no longer be used.",
|
|
"optional": false,
|
|
"defaultValue": "",
|
|
"expandable": false,
|
|
"children": []
|
|
},
|
|
{
|
|
"name": "id",
|
|
"type": "`string`",
|
|
"description": "The discount's ID",
|
|
"optional": false,
|
|
"defaultValue": "",
|
|
"expandable": false,
|
|
"children": []
|
|
},
|
|
{
|
|
"name": "is_disabled",
|
|
"type": "`boolean`",
|
|
"description": "Whether the Discount has been disabled. Disabled discounts cannot be applied to carts",
|
|
"optional": false,
|
|
"defaultValue": "",
|
|
"expandable": false,
|
|
"children": []
|
|
},
|
|
{
|
|
"name": "is_dynamic",
|
|
"type": "`boolean`",
|
|
"description": "A flag to indicate if multiple instances of the discount can be generated. I.e. for newsletter discounts",
|
|
"optional": false,
|
|
"defaultValue": "",
|
|
"expandable": false,
|
|
"children": []
|
|
},
|
|
{
|
|
"name": "metadata",
|
|
"type": "`Record<string, unknown>`",
|
|
"description": "An optional key-value map with additional details",
|
|
"optional": false,
|
|
"defaultValue": "",
|
|
"expandable": false,
|
|
"children": []
|
|
},
|
|
{
|
|
"name": "parent_discount",
|
|
"type": "[Discount](../internal/classes/internal.Discount-1.mdx)",
|
|
"description": "The details of the parent discount that this discount was created from.",
|
|
"optional": false,
|
|
"defaultValue": "",
|
|
"expandable": true,
|
|
"children": []
|
|
},
|
|
{
|
|
"name": "parent_discount_id",
|
|
"type": "`string`",
|
|
"description": "The Discount that the discount was created from. This will always be a dynamic discount",
|
|
"optional": false,
|
|
"defaultValue": "",
|
|
"expandable": false,
|
|
"children": []
|
|
},
|
|
{
|
|
"name": "regions",
|
|
"type": "[Region](../internal/classes/internal.Region.mdx)[]",
|
|
"description": "The details of the regions in which the Discount can be used.",
|
|
"optional": false,
|
|
"defaultValue": "",
|
|
"expandable": true,
|
|
"children": []
|
|
},
|
|
{
|
|
"name": "rule",
|
|
"type": "[DiscountRule](../internal/classes/internal.internal.DiscountRule.mdx)",
|
|
"description": "The details of the discount rule that defines how the discount will be applied to a cart..",
|
|
"optional": false,
|
|
"defaultValue": "",
|
|
"expandable": true,
|
|
"children": []
|
|
},
|
|
{
|
|
"name": "rule_id",
|
|
"type": "`string`",
|
|
"description": "The ID of the discount rule that defines how the discount will be applied to a cart.",
|
|
"optional": false,
|
|
"defaultValue": "",
|
|
"expandable": false,
|
|
"children": []
|
|
},
|
|
{
|
|
"name": "starts_at",
|
|
"type": "`Date`",
|
|
"description": "The time at which the discount can be used.",
|
|
"optional": false,
|
|
"defaultValue": "",
|
|
"expandable": false,
|
|
"children": []
|
|
},
|
|
{
|
|
"name": "updated_at",
|
|
"type": "`Date`",
|
|
"description": "The date with timezone at which the resource was updated.",
|
|
"optional": false,
|
|
"defaultValue": "",
|
|
"expandable": false,
|
|
"children": []
|
|
},
|
|
{
|
|
"name": "usage_count",
|
|
"type": "`number`",
|
|
"description": "The number of times a discount has been used.",
|
|
"optional": false,
|
|
"defaultValue": "0",
|
|
"expandable": false,
|
|
"children": []
|
|
},
|
|
{
|
|
"name": "usage_limit",
|
|
"type": "`null` \\| `number`",
|
|
"description": "The maximum number of times that a discount can be used.",
|
|
"optional": false,
|
|
"defaultValue": "",
|
|
"expandable": false,
|
|
"children": []
|
|
},
|
|
{
|
|
"name": "valid_duration",
|
|
"type": "`null` \\| `string`",
|
|
"description": "Duration the discount runs between",
|
|
"optional": false,
|
|
"defaultValue": "",
|
|
"expandable": false,
|
|
"children": []
|
|
}
|
|
]
|
|
}
|
|
]
|
|
}
|
|
]
|
|
}
|
|
]} />
|
|
|
|
___
|
|
|
|
### deleteDynamicCode
|
|
|
|
Delete a dynamic code from a discount.
|
|
|
|
#### Example
|
|
|
|
```ts
|
|
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.discounts
|
|
.deleteDynamicCode(discountId, code)
|
|
.then(({ discount }) => {
|
|
console.log(discount.id)
|
|
})
|
|
```
|
|
|
|
#### Parameters
|
|
|
|
<ParameterTypes parameters={[
|
|
{
|
|
"name": "id",
|
|
"type": "`string`",
|
|
"description": "The discount's ID.",
|
|
"optional": false,
|
|
"defaultValue": "",
|
|
"expandable": false,
|
|
"children": []
|
|
},
|
|
{
|
|
"name": "code",
|
|
"type": "`string`",
|
|
"description": "The code of the dynamic code to delete.",
|
|
"optional": false,
|
|
"defaultValue": "",
|
|
"expandable": false,
|
|
"children": []
|
|
},
|
|
{
|
|
"name": "customHeaders",
|
|
"type": "`Record<string, any>`",
|
|
"description": "Custom headers to attach to the request.",
|
|
"optional": false,
|
|
"defaultValue": "{}",
|
|
"expandable": false,
|
|
"children": []
|
|
}
|
|
]} />
|
|
|
|
#### Returns
|
|
|
|
<ParameterTypes parameters={[
|
|
{
|
|
"name": "ResponsePromise",
|
|
"type": "[ResponsePromise](../internal/types/internal.ResponsePromise.mdx)<[AdminDiscountsRes](../internal/types/internal.AdminDiscountsRes.mdx)>",
|
|
"optional": false,
|
|
"defaultValue": "",
|
|
"description": "Resolves to the details of the discount.",
|
|
"expandable": false,
|
|
"children": [
|
|
{
|
|
"name": "AdminDiscountsRes",
|
|
"type": "`object`",
|
|
"description": "The discount's details.",
|
|
"optional": false,
|
|
"defaultValue": "",
|
|
"expandable": false,
|
|
"children": [
|
|
{
|
|
"name": "discount",
|
|
"type": "[Discount](../internal/classes/internal.Discount-1.mdx)",
|
|
"description": "Discount details.",
|
|
"optional": false,
|
|
"defaultValue": "",
|
|
"expandable": false,
|
|
"children": [
|
|
{
|
|
"name": "code",
|
|
"type": "`string`",
|
|
"description": "A unique code for the discount - this will be used by the customer to apply the discount",
|
|
"optional": false,
|
|
"defaultValue": "",
|
|
"expandable": false,
|
|
"children": []
|
|
},
|
|
{
|
|
"name": "created_at",
|
|
"type": "`Date`",
|
|
"description": "The date with timezone at which the resource was created.",
|
|
"optional": false,
|
|
"defaultValue": "",
|
|
"expandable": false,
|
|
"children": []
|
|
},
|
|
{
|
|
"name": "deleted_at",
|
|
"type": "`null` \\| `Date`",
|
|
"description": "The date with timezone at which the resource was deleted.",
|
|
"optional": false,
|
|
"defaultValue": "",
|
|
"expandable": false,
|
|
"children": []
|
|
},
|
|
{
|
|
"name": "ends_at",
|
|
"type": "`null` \\| `Date`",
|
|
"description": "The time at which the discount can no longer be used.",
|
|
"optional": false,
|
|
"defaultValue": "",
|
|
"expandable": false,
|
|
"children": []
|
|
},
|
|
{
|
|
"name": "id",
|
|
"type": "`string`",
|
|
"description": "The discount's ID",
|
|
"optional": false,
|
|
"defaultValue": "",
|
|
"expandable": false,
|
|
"children": []
|
|
},
|
|
{
|
|
"name": "is_disabled",
|
|
"type": "`boolean`",
|
|
"description": "Whether the Discount has been disabled. Disabled discounts cannot be applied to carts",
|
|
"optional": false,
|
|
"defaultValue": "",
|
|
"expandable": false,
|
|
"children": []
|
|
},
|
|
{
|
|
"name": "is_dynamic",
|
|
"type": "`boolean`",
|
|
"description": "A flag to indicate if multiple instances of the discount can be generated. I.e. for newsletter discounts",
|
|
"optional": false,
|
|
"defaultValue": "",
|
|
"expandable": false,
|
|
"children": []
|
|
},
|
|
{
|
|
"name": "metadata",
|
|
"type": "`Record<string, unknown>`",
|
|
"description": "An optional key-value map with additional details",
|
|
"optional": false,
|
|
"defaultValue": "",
|
|
"expandable": false,
|
|
"children": []
|
|
},
|
|
{
|
|
"name": "parent_discount",
|
|
"type": "[Discount](../internal/classes/internal.Discount-1.mdx)",
|
|
"description": "The details of the parent discount that this discount was created from.",
|
|
"optional": false,
|
|
"defaultValue": "",
|
|
"expandable": true,
|
|
"children": []
|
|
},
|
|
{
|
|
"name": "parent_discount_id",
|
|
"type": "`string`",
|
|
"description": "The Discount that the discount was created from. This will always be a dynamic discount",
|
|
"optional": false,
|
|
"defaultValue": "",
|
|
"expandable": false,
|
|
"children": []
|
|
},
|
|
{
|
|
"name": "regions",
|
|
"type": "[Region](../internal/classes/internal.Region.mdx)[]",
|
|
"description": "The details of the regions in which the Discount can be used.",
|
|
"optional": false,
|
|
"defaultValue": "",
|
|
"expandable": true,
|
|
"children": []
|
|
},
|
|
{
|
|
"name": "rule",
|
|
"type": "[DiscountRule](../internal/classes/internal.internal.DiscountRule.mdx)",
|
|
"description": "The details of the discount rule that defines how the discount will be applied to a cart..",
|
|
"optional": false,
|
|
"defaultValue": "",
|
|
"expandable": true,
|
|
"children": []
|
|
},
|
|
{
|
|
"name": "rule_id",
|
|
"type": "`string`",
|
|
"description": "The ID of the discount rule that defines how the discount will be applied to a cart.",
|
|
"optional": false,
|
|
"defaultValue": "",
|
|
"expandable": false,
|
|
"children": []
|
|
},
|
|
{
|
|
"name": "starts_at",
|
|
"type": "`Date`",
|
|
"description": "The time at which the discount can be used.",
|
|
"optional": false,
|
|
"defaultValue": "",
|
|
"expandable": false,
|
|
"children": []
|
|
},
|
|
{
|
|
"name": "updated_at",
|
|
"type": "`Date`",
|
|
"description": "The date with timezone at which the resource was updated.",
|
|
"optional": false,
|
|
"defaultValue": "",
|
|
"expandable": false,
|
|
"children": []
|
|
},
|
|
{
|
|
"name": "usage_count",
|
|
"type": "`number`",
|
|
"description": "The number of times a discount has been used.",
|
|
"optional": false,
|
|
"defaultValue": "0",
|
|
"expandable": false,
|
|
"children": []
|
|
},
|
|
{
|
|
"name": "usage_limit",
|
|
"type": "`null` \\| `number`",
|
|
"description": "The maximum number of times that a discount can be used.",
|
|
"optional": false,
|
|
"defaultValue": "",
|
|
"expandable": false,
|
|
"children": []
|
|
},
|
|
{
|
|
"name": "valid_duration",
|
|
"type": "`null` \\| `string`",
|
|
"description": "Duration the discount runs between",
|
|
"optional": false,
|
|
"defaultValue": "",
|
|
"expandable": false,
|
|
"children": []
|
|
}
|
|
]
|
|
}
|
|
]
|
|
}
|
|
]
|
|
}
|
|
]} />
|
|
|
|
___
|
|
|
|
### getCondition
|
|
|
|
Retrieve a Discount Condition's details.
|
|
|
|
#### Example
|
|
|
|
A simple example that retrieves a discount condition by its ID:
|
|
|
|
```ts
|
|
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.discounts
|
|
.getCondition(discountId, conditionId)
|
|
.then(({ discount_condition }) => {
|
|
console.log(discount_condition.id)
|
|
})
|
|
```
|
|
|
|
To specify relations that should be retrieved:
|
|
|
|
```ts
|
|
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.discounts
|
|
.getCondition(discountId, conditionId, {
|
|
expand: "discount_rule",
|
|
})
|
|
.then(({ discount_condition }) => {
|
|
console.log(discount_condition.id)
|
|
})
|
|
```
|
|
|
|
#### Parameters
|
|
|
|
<ParameterTypes parameters={[
|
|
{
|
|
"name": "discountId",
|
|
"type": "`string`",
|
|
"description": "The ID of the discount that the condition belongs to.",
|
|
"optional": false,
|
|
"defaultValue": "",
|
|
"expandable": false,
|
|
"children": []
|
|
},
|
|
{
|
|
"name": "conditionId",
|
|
"type": "`string`",
|
|
"description": "The ID of the discount condition.",
|
|
"optional": false,
|
|
"defaultValue": "",
|
|
"expandable": false,
|
|
"children": []
|
|
},
|
|
{
|
|
"name": "query",
|
|
"type": "[AdminGetDiscountsDiscountConditionsConditionParams](../internal/classes/internal.AdminGetDiscountsDiscountConditionsConditionParams.mdx)",
|
|
"description": "Configurations to apply on the retrieved discount condition.",
|
|
"optional": true,
|
|
"defaultValue": "",
|
|
"expandable": false,
|
|
"children": [
|
|
{
|
|
"name": "expand",
|
|
"type": "`string`",
|
|
"description": "Comma-separated relations that should be expanded in the returned data.",
|
|
"optional": true,
|
|
"defaultValue": "",
|
|
"expandable": false,
|
|
"children": []
|
|
},
|
|
{
|
|
"name": "fields",
|
|
"type": "`string`",
|
|
"description": "Comma-separated fields that should be included in the returned data.",
|
|
"optional": true,
|
|
"defaultValue": "",
|
|
"expandable": false,
|
|
"children": []
|
|
}
|
|
]
|
|
},
|
|
{
|
|
"name": "customHeaders",
|
|
"type": "`Record<string, any>`",
|
|
"description": "Custom headers to attach to the request.",
|
|
"optional": false,
|
|
"defaultValue": "{}",
|
|
"expandable": false,
|
|
"children": []
|
|
}
|
|
]} />
|
|
|
|
#### Returns
|
|
|
|
<ParameterTypes parameters={[
|
|
{
|
|
"name": "ResponsePromise",
|
|
"type": "[ResponsePromise](../internal/types/internal.ResponsePromise.mdx)<[AdminDiscountConditionsRes](../internal/types/internal.AdminDiscountConditionsRes.mdx)>",
|
|
"optional": false,
|
|
"defaultValue": "",
|
|
"description": "Resolves to the discount condition details.",
|
|
"expandable": false,
|
|
"children": [
|
|
{
|
|
"name": "AdminDiscountConditionsRes",
|
|
"type": "`object`",
|
|
"description": "",
|
|
"optional": false,
|
|
"defaultValue": "",
|
|
"expandable": false,
|
|
"children": [
|
|
{
|
|
"name": "discount_condition",
|
|
"type": "[DiscountCondition](../internal/classes/internal.DiscountCondition.mdx)",
|
|
"description": "Discount condition details.",
|
|
"optional": false,
|
|
"defaultValue": "",
|
|
"expandable": false,
|
|
"children": [
|
|
{
|
|
"name": "created_at",
|
|
"type": "`Date`",
|
|
"description": "The date with timezone at which the resource was created.",
|
|
"optional": false,
|
|
"defaultValue": "",
|
|
"expandable": false,
|
|
"children": []
|
|
},
|
|
{
|
|
"name": "customer_groups",
|
|
"type": "[CustomerGroup](../internal/classes/internal.CustomerGroup.mdx)[]",
|
|
"description": "Customer groups associated with this condition if `type` is `customer\\_groups`.",
|
|
"optional": false,
|
|
"defaultValue": "",
|
|
"expandable": true,
|
|
"children": []
|
|
},
|
|
{
|
|
"name": "deleted_at",
|
|
"type": "`null` \\| `Date`",
|
|
"description": "The date with timezone at which the resource was deleted.",
|
|
"optional": false,
|
|
"defaultValue": "",
|
|
"expandable": false,
|
|
"children": []
|
|
},
|
|
{
|
|
"name": "discount_rule",
|
|
"type": "[DiscountRule](../internal/classes/internal.internal.DiscountRule.mdx)",
|
|
"description": "The details of the discount rule associated with the condition.",
|
|
"optional": false,
|
|
"defaultValue": "",
|
|
"expandable": true,
|
|
"children": []
|
|
},
|
|
{
|
|
"name": "discount_rule_id",
|
|
"type": "`string`",
|
|
"description": "The ID of the discount rule associated with the condition",
|
|
"optional": false,
|
|
"defaultValue": "",
|
|
"expandable": false,
|
|
"children": []
|
|
},
|
|
{
|
|
"name": "id",
|
|
"type": "`string`",
|
|
"description": "The discount condition's ID",
|
|
"optional": false,
|
|
"defaultValue": "",
|
|
"expandable": false,
|
|
"children": []
|
|
},
|
|
{
|
|
"name": "metadata",
|
|
"type": "`Record<string, unknown>`",
|
|
"description": "An optional key-value map with additional details",
|
|
"optional": false,
|
|
"defaultValue": "",
|
|
"expandable": false,
|
|
"children": []
|
|
},
|
|
{
|
|
"name": "operator",
|
|
"type": "[DiscountConditionOperator](../internal/enums/internal.DiscountConditionOperator.mdx)",
|
|
"description": "The operator of the condition. `in` indicates that discountable resources are within the specified resources. `not\\_in` indicates that discountable resources are everything but the specified resources.",
|
|
"optional": false,
|
|
"defaultValue": "",
|
|
"expandable": false,
|
|
"children": []
|
|
},
|
|
{
|
|
"name": "product_collections",
|
|
"type": "[ProductCollection](../internal/classes/internal.ProductCollection.mdx)[]",
|
|
"description": "Product collections associated with this condition if `type` is `product\\_collections`.",
|
|
"optional": false,
|
|
"defaultValue": "",
|
|
"expandable": true,
|
|
"children": []
|
|
},
|
|
{
|
|
"name": "product_tags",
|
|
"type": "[ProductTag](../internal/classes/internal.ProductTag.mdx)[]",
|
|
"description": "Product tags associated with this condition if `type` is `product\\_tags`.",
|
|
"optional": false,
|
|
"defaultValue": "",
|
|
"expandable": true,
|
|
"children": []
|
|
},
|
|
{
|
|
"name": "product_types",
|
|
"type": "[ProductType](../internal/classes/internal.ProductType.mdx)[]",
|
|
"description": "Product types associated with this condition if `type` is `product\\_types`.",
|
|
"optional": false,
|
|
"defaultValue": "",
|
|
"expandable": true,
|
|
"children": []
|
|
},
|
|
{
|
|
"name": "products",
|
|
"type": "[Product](../internal/classes/internal.Product.mdx)[]",
|
|
"description": "products associated with this condition if `type` is `products`.",
|
|
"optional": false,
|
|
"defaultValue": "",
|
|
"expandable": true,
|
|
"children": []
|
|
},
|
|
{
|
|
"name": "type",
|
|
"type": "[DiscountConditionType](../internal/enums/internal.internal.DiscountConditionType.mdx)",
|
|
"description": "The type of the condition. The type affects the available resources associated with the condition. For example, if the type is `products`, that means the `products` relation will hold the products associated with this condition and other relations will be empty.",
|
|
"optional": false,
|
|
"defaultValue": "",
|
|
"expandable": false,
|
|
"children": []
|
|
},
|
|
{
|
|
"name": "updated_at",
|
|
"type": "`Date`",
|
|
"description": "The date with timezone at which the resource was updated.",
|
|
"optional": false,
|
|
"defaultValue": "",
|
|
"expandable": false,
|
|
"children": []
|
|
}
|
|
]
|
|
}
|
|
]
|
|
}
|
|
]
|
|
}
|
|
]} />
|
|
|
|
___
|
|
|
|
### list
|
|
|
|
Retrieve a list of Discounts. The discounts can be filtered by fields such as `rule` or `is_dynamic`. The discounts can also be paginated.
|
|
|
|
#### Example
|
|
|
|
To list discounts:
|
|
|
|
```ts
|
|
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.discounts.list().then(({ discounts, limit, offset, count }) => {
|
|
console.log(discounts.id)
|
|
})
|
|
```
|
|
|
|
To specify relations that should be retrieved within the discounts:
|
|
|
|
```ts
|
|
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.discounts
|
|
.list({
|
|
expand: "rule",
|
|
})
|
|
.then(({ discounts, limit, offset, count }) => {
|
|
console.log(discounts.id)
|
|
})
|
|
```
|
|
|
|
By default, only the first `20` records are retrieved. You can control pagination by specifying the `limit` and `offset` properties:
|
|
|
|
```ts
|
|
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.discounts
|
|
.list({
|
|
expand: "rule",
|
|
limit,
|
|
offset,
|
|
})
|
|
.then(({ discounts, limit, offset, count }) => {
|
|
console.log(discounts.id)
|
|
})
|
|
```
|
|
|
|
#### Parameters
|
|
|
|
<ParameterTypes parameters={[
|
|
{
|
|
"name": "query",
|
|
"type": "[AdminGetDiscountsParams](../internal/classes/internal.AdminGetDiscountsParams.mdx)",
|
|
"description": "Filters and pagination configurations to apply on the retrieved discounts.",
|
|
"optional": true,
|
|
"defaultValue": "",
|
|
"expandable": false,
|
|
"children": [
|
|
{
|
|
"name": "expand",
|
|
"type": "`string`",
|
|
"description": "Comma-separated relations that should be expanded in the returned data.",
|
|
"optional": true,
|
|
"defaultValue": "",
|
|
"expandable": false,
|
|
"children": []
|
|
},
|
|
{
|
|
"name": "fields",
|
|
"type": "`string`",
|
|
"description": "Comma-separated fields that should be included in the returned data.",
|
|
"optional": true,
|
|
"defaultValue": "",
|
|
"expandable": false,
|
|
"children": []
|
|
},
|
|
{
|
|
"name": "is_disabled",
|
|
"type": "`boolean`",
|
|
"description": "Filter discounts by whether they're disabled.",
|
|
"optional": true,
|
|
"defaultValue": "",
|
|
"expandable": false,
|
|
"children": []
|
|
},
|
|
{
|
|
"name": "is_dynamic",
|
|
"type": "`boolean`",
|
|
"description": "Filter discounts by whether they're dynamic.",
|
|
"optional": true,
|
|
"defaultValue": "",
|
|
"expandable": false,
|
|
"children": []
|
|
},
|
|
{
|
|
"name": "limit",
|
|
"type": "`number`",
|
|
"description": "Limit the number of items returned in the list.",
|
|
"optional": true,
|
|
"defaultValue": "20",
|
|
"expandable": false,
|
|
"children": []
|
|
},
|
|
{
|
|
"name": "offset",
|
|
"type": "`number`",
|
|
"description": "The number of items to skip when retrieving a list.",
|
|
"optional": true,
|
|
"defaultValue": "0",
|
|
"expandable": false,
|
|
"children": []
|
|
},
|
|
{
|
|
"name": "q",
|
|
"type": "`string`",
|
|
"description": "Search terms to search discounts' code fields.",
|
|
"optional": true,
|
|
"defaultValue": "",
|
|
"expandable": false,
|
|
"children": []
|
|
},
|
|
{
|
|
"name": "rule",
|
|
"type": "[AdminGetDiscountsDiscountRuleParams](../internal/classes/internal.AdminGetDiscountsDiscountRuleParams.mdx)",
|
|
"description": "Filter discounts by their associated rule.",
|
|
"optional": true,
|
|
"defaultValue": "",
|
|
"expandable": false,
|
|
"children": [
|
|
{
|
|
"name": "allocation",
|
|
"type": "[AllocationType](../internal/enums/internal.internal.AllocationType.mdx)",
|
|
"description": "Allocation to filter discount rules by.",
|
|
"optional": true,
|
|
"defaultValue": "",
|
|
"expandable": false,
|
|
"children": [
|
|
{
|
|
"name": "ITEM",
|
|
"type": "`\"item\"`",
|
|
"description": "The discount should be applied to applicable items in the cart.",
|
|
"optional": true,
|
|
"defaultValue": "",
|
|
"expandable": false,
|
|
"children": []
|
|
},
|
|
{
|
|
"name": "TOTAL",
|
|
"type": "`\"total\"`",
|
|
"description": "The discount should be applied to the checkout total.",
|
|
"optional": true,
|
|
"defaultValue": "",
|
|
"expandable": false,
|
|
"children": []
|
|
}
|
|
]
|
|
},
|
|
{
|
|
"name": "type",
|
|
"type": "[DiscountRuleType](../internal/enums/internal.internal.DiscountRuleType.mdx)",
|
|
"description": "Type to filter discount rules by.",
|
|
"optional": true,
|
|
"defaultValue": "",
|
|
"expandable": false,
|
|
"children": [
|
|
{
|
|
"name": "FIXED",
|
|
"type": "`\"fixed\"`",
|
|
"description": "Discounts that reduce the price by a fixed amount.",
|
|
"optional": true,
|
|
"defaultValue": "",
|
|
"expandable": false,
|
|
"children": []
|
|
},
|
|
{
|
|
"name": "FREE_SHIPPING",
|
|
"type": "`\"free_shipping\"`",
|
|
"description": "Discounts that sets the shipping price to `0`.",
|
|
"optional": true,
|
|
"defaultValue": "",
|
|
"expandable": false,
|
|
"children": []
|
|
},
|
|
{
|
|
"name": "PERCENTAGE",
|
|
"type": "`\"percentage\"`",
|
|
"description": "Discounts that reduce the price by a percentage reduction.",
|
|
"optional": true,
|
|
"defaultValue": "",
|
|
"expandable": false,
|
|
"children": []
|
|
}
|
|
]
|
|
}
|
|
]
|
|
}
|
|
]
|
|
},
|
|
{
|
|
"name": "customHeaders",
|
|
"type": "`Record<string, any>`",
|
|
"description": "Custom headers to attach to the request.",
|
|
"optional": false,
|
|
"defaultValue": "{}",
|
|
"expandable": false,
|
|
"children": []
|
|
}
|
|
]} />
|
|
|
|
#### Returns
|
|
|
|
<ParameterTypes parameters={[
|
|
{
|
|
"name": "ResponsePromise",
|
|
"type": "[ResponsePromise](../internal/types/internal.ResponsePromise.mdx)<[AdminDiscountsListRes](../internal/types/internal.AdminDiscountsListRes.mdx)>",
|
|
"optional": false,
|
|
"defaultValue": "",
|
|
"description": "Resolves to the list of discounts with pagination fields.",
|
|
"expandable": false,
|
|
"children": [
|
|
{
|
|
"name": "AdminDiscountsListRes",
|
|
"type": "[PaginatedResponse](../internal/interfaces/internal.PaginatedResponse.mdx) & ``{ discounts: [Discount](../internal/classes/internal.Discount-1.mdx)[] }``",
|
|
"description": "The list of discounts with pagination fields.",
|
|
"optional": false,
|
|
"defaultValue": "",
|
|
"expandable": false,
|
|
"children": [
|
|
{
|
|
"name": "count",
|
|
"type": "`number`",
|
|
"description": "The total number of items available.",
|
|
"optional": false,
|
|
"defaultValue": "",
|
|
"expandable": false,
|
|
"children": []
|
|
},
|
|
{
|
|
"name": "limit",
|
|
"type": "`number`",
|
|
"description": "The maximum number of items that can be returned in the list.",
|
|
"optional": false,
|
|
"defaultValue": "",
|
|
"expandable": false,
|
|
"children": []
|
|
},
|
|
{
|
|
"name": "offset",
|
|
"type": "`number`",
|
|
"description": "The number of items skipped before the returned items in the list.",
|
|
"optional": false,
|
|
"defaultValue": "",
|
|
"expandable": false,
|
|
"children": []
|
|
},
|
|
{
|
|
"name": "discounts",
|
|
"type": "[Discount](../internal/classes/internal.Discount-1.mdx)[]",
|
|
"description": "The list of discounts.",
|
|
"optional": false,
|
|
"defaultValue": "",
|
|
"expandable": false,
|
|
"children": [
|
|
{
|
|
"name": "code",
|
|
"type": "`string`",
|
|
"description": "A unique code for the discount - this will be used by the customer to apply the discount",
|
|
"optional": false,
|
|
"defaultValue": "",
|
|
"expandable": false,
|
|
"children": []
|
|
},
|
|
{
|
|
"name": "created_at",
|
|
"type": "`Date`",
|
|
"description": "The date with timezone at which the resource was created.",
|
|
"optional": false,
|
|
"defaultValue": "",
|
|
"expandable": false,
|
|
"children": []
|
|
},
|
|
{
|
|
"name": "deleted_at",
|
|
"type": "`null` \\| `Date`",
|
|
"description": "The date with timezone at which the resource was deleted.",
|
|
"optional": false,
|
|
"defaultValue": "",
|
|
"expandable": false,
|
|
"children": []
|
|
},
|
|
{
|
|
"name": "ends_at",
|
|
"type": "`null` \\| `Date`",
|
|
"description": "The time at which the discount can no longer be used.",
|
|
"optional": false,
|
|
"defaultValue": "",
|
|
"expandable": false,
|
|
"children": []
|
|
},
|
|
{
|
|
"name": "id",
|
|
"type": "`string`",
|
|
"description": "The discount's ID",
|
|
"optional": false,
|
|
"defaultValue": "",
|
|
"expandable": false,
|
|
"children": []
|
|
},
|
|
{
|
|
"name": "is_disabled",
|
|
"type": "`boolean`",
|
|
"description": "Whether the Discount has been disabled. Disabled discounts cannot be applied to carts",
|
|
"optional": false,
|
|
"defaultValue": "",
|
|
"expandable": false,
|
|
"children": []
|
|
},
|
|
{
|
|
"name": "is_dynamic",
|
|
"type": "`boolean`",
|
|
"description": "A flag to indicate if multiple instances of the discount can be generated. I.e. for newsletter discounts",
|
|
"optional": false,
|
|
"defaultValue": "",
|
|
"expandable": false,
|
|
"children": []
|
|
},
|
|
{
|
|
"name": "metadata",
|
|
"type": "`Record<string, unknown>`",
|
|
"description": "An optional key-value map with additional details",
|
|
"optional": false,
|
|
"defaultValue": "",
|
|
"expandable": false,
|
|
"children": []
|
|
},
|
|
{
|
|
"name": "parent_discount",
|
|
"type": "[Discount](../internal/classes/internal.Discount-1.mdx)",
|
|
"description": "The details of the parent discount that this discount was created from.",
|
|
"optional": false,
|
|
"defaultValue": "",
|
|
"expandable": true,
|
|
"children": []
|
|
},
|
|
{
|
|
"name": "parent_discount_id",
|
|
"type": "`string`",
|
|
"description": "The Discount that the discount was created from. This will always be a dynamic discount",
|
|
"optional": false,
|
|
"defaultValue": "",
|
|
"expandable": false,
|
|
"children": []
|
|
},
|
|
{
|
|
"name": "regions",
|
|
"type": "[Region](../internal/classes/internal.Region.mdx)[]",
|
|
"description": "The details of the regions in which the Discount can be used.",
|
|
"optional": false,
|
|
"defaultValue": "",
|
|
"expandable": true,
|
|
"children": []
|
|
},
|
|
{
|
|
"name": "rule",
|
|
"type": "[DiscountRule](../internal/classes/internal.internal.DiscountRule.mdx)",
|
|
"description": "The details of the discount rule that defines how the discount will be applied to a cart..",
|
|
"optional": false,
|
|
"defaultValue": "",
|
|
"expandable": true,
|
|
"children": []
|
|
},
|
|
{
|
|
"name": "rule_id",
|
|
"type": "`string`",
|
|
"description": "The ID of the discount rule that defines how the discount will be applied to a cart.",
|
|
"optional": false,
|
|
"defaultValue": "",
|
|
"expandable": false,
|
|
"children": []
|
|
},
|
|
{
|
|
"name": "starts_at",
|
|
"type": "`Date`",
|
|
"description": "The time at which the discount can be used.",
|
|
"optional": false,
|
|
"defaultValue": "",
|
|
"expandable": false,
|
|
"children": []
|
|
},
|
|
{
|
|
"name": "updated_at",
|
|
"type": "`Date`",
|
|
"description": "The date with timezone at which the resource was updated.",
|
|
"optional": false,
|
|
"defaultValue": "",
|
|
"expandable": false,
|
|
"children": []
|
|
},
|
|
{
|
|
"name": "usage_count",
|
|
"type": "`number`",
|
|
"description": "The number of times a discount has been used.",
|
|
"optional": false,
|
|
"defaultValue": "0",
|
|
"expandable": false,
|
|
"children": []
|
|
},
|
|
{
|
|
"name": "usage_limit",
|
|
"type": "`null` \\| `number`",
|
|
"description": "The maximum number of times that a discount can be used.",
|
|
"optional": false,
|
|
"defaultValue": "",
|
|
"expandable": false,
|
|
"children": []
|
|
},
|
|
{
|
|
"name": "valid_duration",
|
|
"type": "`null` \\| `string`",
|
|
"description": "Duration the discount runs between",
|
|
"optional": false,
|
|
"defaultValue": "",
|
|
"expandable": false,
|
|
"children": []
|
|
}
|
|
]
|
|
}
|
|
]
|
|
}
|
|
]
|
|
}
|
|
]} />
|
|
|
|
___
|
|
|
|
### removeRegion
|
|
|
|
Remove a Region from the list of Regions that a Discount can be used in. This does not delete a region, only the association between it and the discount.
|
|
|
|
#### Example
|
|
|
|
```ts
|
|
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.discounts
|
|
.removeRegion(discountId, regionId)
|
|
.then(({ discount }) => {
|
|
console.log(discount.id)
|
|
})
|
|
```
|
|
|
|
#### Parameters
|
|
|
|
<ParameterTypes parameters={[
|
|
{
|
|
"name": "id",
|
|
"type": "`string`",
|
|
"description": "The discount's ID.",
|
|
"optional": false,
|
|
"defaultValue": "",
|
|
"expandable": false,
|
|
"children": []
|
|
},
|
|
{
|
|
"name": "regionId",
|
|
"type": "`string`",
|
|
"description": "The ID of the region to remove.",
|
|
"optional": false,
|
|
"defaultValue": "",
|
|
"expandable": false,
|
|
"children": []
|
|
},
|
|
{
|
|
"name": "customHeaders",
|
|
"type": "`Record<string, any>`",
|
|
"description": "Custom headers to attach to the request.",
|
|
"optional": false,
|
|
"defaultValue": "{}",
|
|
"expandable": false,
|
|
"children": []
|
|
}
|
|
]} />
|
|
|
|
#### Returns
|
|
|
|
<ParameterTypes parameters={[
|
|
{
|
|
"name": "ResponsePromise",
|
|
"type": "[ResponsePromise](../internal/types/internal.ResponsePromise.mdx)<[AdminDiscountsRes](../internal/types/internal.AdminDiscountsRes.mdx)>",
|
|
"optional": false,
|
|
"defaultValue": "",
|
|
"description": "Resolves to the details of the discount.",
|
|
"expandable": false,
|
|
"children": [
|
|
{
|
|
"name": "AdminDiscountsRes",
|
|
"type": "`object`",
|
|
"description": "The discount's details.",
|
|
"optional": false,
|
|
"defaultValue": "",
|
|
"expandable": false,
|
|
"children": [
|
|
{
|
|
"name": "discount",
|
|
"type": "[Discount](../internal/classes/internal.Discount-1.mdx)",
|
|
"description": "Discount details.",
|
|
"optional": false,
|
|
"defaultValue": "",
|
|
"expandable": false,
|
|
"children": [
|
|
{
|
|
"name": "code",
|
|
"type": "`string`",
|
|
"description": "A unique code for the discount - this will be used by the customer to apply the discount",
|
|
"optional": false,
|
|
"defaultValue": "",
|
|
"expandable": false,
|
|
"children": []
|
|
},
|
|
{
|
|
"name": "created_at",
|
|
"type": "`Date`",
|
|
"description": "The date with timezone at which the resource was created.",
|
|
"optional": false,
|
|
"defaultValue": "",
|
|
"expandable": false,
|
|
"children": []
|
|
},
|
|
{
|
|
"name": "deleted_at",
|
|
"type": "`null` \\| `Date`",
|
|
"description": "The date with timezone at which the resource was deleted.",
|
|
"optional": false,
|
|
"defaultValue": "",
|
|
"expandable": false,
|
|
"children": []
|
|
},
|
|
{
|
|
"name": "ends_at",
|
|
"type": "`null` \\| `Date`",
|
|
"description": "The time at which the discount can no longer be used.",
|
|
"optional": false,
|
|
"defaultValue": "",
|
|
"expandable": false,
|
|
"children": []
|
|
},
|
|
{
|
|
"name": "id",
|
|
"type": "`string`",
|
|
"description": "The discount's ID",
|
|
"optional": false,
|
|
"defaultValue": "",
|
|
"expandable": false,
|
|
"children": []
|
|
},
|
|
{
|
|
"name": "is_disabled",
|
|
"type": "`boolean`",
|
|
"description": "Whether the Discount has been disabled. Disabled discounts cannot be applied to carts",
|
|
"optional": false,
|
|
"defaultValue": "",
|
|
"expandable": false,
|
|
"children": []
|
|
},
|
|
{
|
|
"name": "is_dynamic",
|
|
"type": "`boolean`",
|
|
"description": "A flag to indicate if multiple instances of the discount can be generated. I.e. for newsletter discounts",
|
|
"optional": false,
|
|
"defaultValue": "",
|
|
"expandable": false,
|
|
"children": []
|
|
},
|
|
{
|
|
"name": "metadata",
|
|
"type": "`Record<string, unknown>`",
|
|
"description": "An optional key-value map with additional details",
|
|
"optional": false,
|
|
"defaultValue": "",
|
|
"expandable": false,
|
|
"children": []
|
|
},
|
|
{
|
|
"name": "parent_discount",
|
|
"type": "[Discount](../internal/classes/internal.Discount-1.mdx)",
|
|
"description": "The details of the parent discount that this discount was created from.",
|
|
"optional": false,
|
|
"defaultValue": "",
|
|
"expandable": true,
|
|
"children": []
|
|
},
|
|
{
|
|
"name": "parent_discount_id",
|
|
"type": "`string`",
|
|
"description": "The Discount that the discount was created from. This will always be a dynamic discount",
|
|
"optional": false,
|
|
"defaultValue": "",
|
|
"expandable": false,
|
|
"children": []
|
|
},
|
|
{
|
|
"name": "regions",
|
|
"type": "[Region](../internal/classes/internal.Region.mdx)[]",
|
|
"description": "The details of the regions in which the Discount can be used.",
|
|
"optional": false,
|
|
"defaultValue": "",
|
|
"expandable": true,
|
|
"children": []
|
|
},
|
|
{
|
|
"name": "rule",
|
|
"type": "[DiscountRule](../internal/classes/internal.internal.DiscountRule.mdx)",
|
|
"description": "The details of the discount rule that defines how the discount will be applied to a cart..",
|
|
"optional": false,
|
|
"defaultValue": "",
|
|
"expandable": true,
|
|
"children": []
|
|
},
|
|
{
|
|
"name": "rule_id",
|
|
"type": "`string`",
|
|
"description": "The ID of the discount rule that defines how the discount will be applied to a cart.",
|
|
"optional": false,
|
|
"defaultValue": "",
|
|
"expandable": false,
|
|
"children": []
|
|
},
|
|
{
|
|
"name": "starts_at",
|
|
"type": "`Date`",
|
|
"description": "The time at which the discount can be used.",
|
|
"optional": false,
|
|
"defaultValue": "",
|
|
"expandable": false,
|
|
"children": []
|
|
},
|
|
{
|
|
"name": "updated_at",
|
|
"type": "`Date`",
|
|
"description": "The date with timezone at which the resource was updated.",
|
|
"optional": false,
|
|
"defaultValue": "",
|
|
"expandable": false,
|
|
"children": []
|
|
},
|
|
{
|
|
"name": "usage_count",
|
|
"type": "`number`",
|
|
"description": "The number of times a discount has been used.",
|
|
"optional": false,
|
|
"defaultValue": "0",
|
|
"expandable": false,
|
|
"children": []
|
|
},
|
|
{
|
|
"name": "usage_limit",
|
|
"type": "`null` \\| `number`",
|
|
"description": "The maximum number of times that a discount can be used.",
|
|
"optional": false,
|
|
"defaultValue": "",
|
|
"expandable": false,
|
|
"children": []
|
|
},
|
|
{
|
|
"name": "valid_duration",
|
|
"type": "`null` \\| `string`",
|
|
"description": "Duration the discount runs between",
|
|
"optional": false,
|
|
"defaultValue": "",
|
|
"expandable": false,
|
|
"children": []
|
|
}
|
|
]
|
|
}
|
|
]
|
|
}
|
|
]
|
|
}
|
|
]} />
|
|
|
|
___
|
|
|
|
### retrieve
|
|
|
|
Retrieve a discount.
|
|
|
|
#### Example
|
|
|
|
```ts
|
|
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.discounts.retrieve(discountId).then(({ discount }) => {
|
|
console.log(discount.id)
|
|
})
|
|
```
|
|
|
|
#### Parameters
|
|
|
|
<ParameterTypes parameters={[
|
|
{
|
|
"name": "id",
|
|
"type": "`string`",
|
|
"description": "The discount's ID.",
|
|
"optional": false,
|
|
"defaultValue": "",
|
|
"expandable": false,
|
|
"children": []
|
|
},
|
|
{
|
|
"name": "customHeaders",
|
|
"type": "`Record<string, any>`",
|
|
"description": "Custom headers to attach to the request.",
|
|
"optional": false,
|
|
"defaultValue": "{}",
|
|
"expandable": false,
|
|
"children": []
|
|
}
|
|
]} />
|
|
|
|
#### Returns
|
|
|
|
<ParameterTypes parameters={[
|
|
{
|
|
"name": "ResponsePromise",
|
|
"type": "[ResponsePromise](../internal/types/internal.ResponsePromise.mdx)<[AdminDiscountsRes](../internal/types/internal.AdminDiscountsRes.mdx)>",
|
|
"optional": false,
|
|
"defaultValue": "",
|
|
"description": "Resolves to the details of the discount.",
|
|
"expandable": false,
|
|
"children": [
|
|
{
|
|
"name": "AdminDiscountsRes",
|
|
"type": "`object`",
|
|
"description": "The discount's details.",
|
|
"optional": false,
|
|
"defaultValue": "",
|
|
"expandable": false,
|
|
"children": [
|
|
{
|
|
"name": "discount",
|
|
"type": "[Discount](../internal/classes/internal.Discount-1.mdx)",
|
|
"description": "Discount details.",
|
|
"optional": false,
|
|
"defaultValue": "",
|
|
"expandable": false,
|
|
"children": [
|
|
{
|
|
"name": "code",
|
|
"type": "`string`",
|
|
"description": "A unique code for the discount - this will be used by the customer to apply the discount",
|
|
"optional": false,
|
|
"defaultValue": "",
|
|
"expandable": false,
|
|
"children": []
|
|
},
|
|
{
|
|
"name": "created_at",
|
|
"type": "`Date`",
|
|
"description": "The date with timezone at which the resource was created.",
|
|
"optional": false,
|
|
"defaultValue": "",
|
|
"expandable": false,
|
|
"children": []
|
|
},
|
|
{
|
|
"name": "deleted_at",
|
|
"type": "`null` \\| `Date`",
|
|
"description": "The date with timezone at which the resource was deleted.",
|
|
"optional": false,
|
|
"defaultValue": "",
|
|
"expandable": false,
|
|
"children": []
|
|
},
|
|
{
|
|
"name": "ends_at",
|
|
"type": "`null` \\| `Date`",
|
|
"description": "The time at which the discount can no longer be used.",
|
|
"optional": false,
|
|
"defaultValue": "",
|
|
"expandable": false,
|
|
"children": []
|
|
},
|
|
{
|
|
"name": "id",
|
|
"type": "`string`",
|
|
"description": "The discount's ID",
|
|
"optional": false,
|
|
"defaultValue": "",
|
|
"expandable": false,
|
|
"children": []
|
|
},
|
|
{
|
|
"name": "is_disabled",
|
|
"type": "`boolean`",
|
|
"description": "Whether the Discount has been disabled. Disabled discounts cannot be applied to carts",
|
|
"optional": false,
|
|
"defaultValue": "",
|
|
"expandable": false,
|
|
"children": []
|
|
},
|
|
{
|
|
"name": "is_dynamic",
|
|
"type": "`boolean`",
|
|
"description": "A flag to indicate if multiple instances of the discount can be generated. I.e. for newsletter discounts",
|
|
"optional": false,
|
|
"defaultValue": "",
|
|
"expandable": false,
|
|
"children": []
|
|
},
|
|
{
|
|
"name": "metadata",
|
|
"type": "`Record<string, unknown>`",
|
|
"description": "An optional key-value map with additional details",
|
|
"optional": false,
|
|
"defaultValue": "",
|
|
"expandable": false,
|
|
"children": []
|
|
},
|
|
{
|
|
"name": "parent_discount",
|
|
"type": "[Discount](../internal/classes/internal.Discount-1.mdx)",
|
|
"description": "The details of the parent discount that this discount was created from.",
|
|
"optional": false,
|
|
"defaultValue": "",
|
|
"expandable": true,
|
|
"children": []
|
|
},
|
|
{
|
|
"name": "parent_discount_id",
|
|
"type": "`string`",
|
|
"description": "The Discount that the discount was created from. This will always be a dynamic discount",
|
|
"optional": false,
|
|
"defaultValue": "",
|
|
"expandable": false,
|
|
"children": []
|
|
},
|
|
{
|
|
"name": "regions",
|
|
"type": "[Region](../internal/classes/internal.Region.mdx)[]",
|
|
"description": "The details of the regions in which the Discount can be used.",
|
|
"optional": false,
|
|
"defaultValue": "",
|
|
"expandable": true,
|
|
"children": []
|
|
},
|
|
{
|
|
"name": "rule",
|
|
"type": "[DiscountRule](../internal/classes/internal.internal.DiscountRule.mdx)",
|
|
"description": "The details of the discount rule that defines how the discount will be applied to a cart..",
|
|
"optional": false,
|
|
"defaultValue": "",
|
|
"expandable": true,
|
|
"children": []
|
|
},
|
|
{
|
|
"name": "rule_id",
|
|
"type": "`string`",
|
|
"description": "The ID of the discount rule that defines how the discount will be applied to a cart.",
|
|
"optional": false,
|
|
"defaultValue": "",
|
|
"expandable": false,
|
|
"children": []
|
|
},
|
|
{
|
|
"name": "starts_at",
|
|
"type": "`Date`",
|
|
"description": "The time at which the discount can be used.",
|
|
"optional": false,
|
|
"defaultValue": "",
|
|
"expandable": false,
|
|
"children": []
|
|
},
|
|
{
|
|
"name": "updated_at",
|
|
"type": "`Date`",
|
|
"description": "The date with timezone at which the resource was updated.",
|
|
"optional": false,
|
|
"defaultValue": "",
|
|
"expandable": false,
|
|
"children": []
|
|
},
|
|
{
|
|
"name": "usage_count",
|
|
"type": "`number`",
|
|
"description": "The number of times a discount has been used.",
|
|
"optional": false,
|
|
"defaultValue": "0",
|
|
"expandable": false,
|
|
"children": []
|
|
},
|
|
{
|
|
"name": "usage_limit",
|
|
"type": "`null` \\| `number`",
|
|
"description": "The maximum number of times that a discount can be used.",
|
|
"optional": false,
|
|
"defaultValue": "",
|
|
"expandable": false,
|
|
"children": []
|
|
},
|
|
{
|
|
"name": "valid_duration",
|
|
"type": "`null` \\| `string`",
|
|
"description": "Duration the discount runs between",
|
|
"optional": false,
|
|
"defaultValue": "",
|
|
"expandable": false,
|
|
"children": []
|
|
}
|
|
]
|
|
}
|
|
]
|
|
}
|
|
]
|
|
}
|
|
]} />
|
|
|
|
___
|
|
|
|
### retrieveByCode
|
|
|
|
Retrieve a discount's details by its discount code.
|
|
|
|
#### Example
|
|
|
|
```ts
|
|
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.discounts.retrieveByCode(code).then(({ discount }) => {
|
|
console.log(discount.id)
|
|
})
|
|
```
|
|
|
|
#### Parameters
|
|
|
|
<ParameterTypes parameters={[
|
|
{
|
|
"name": "code",
|
|
"type": "`string`",
|
|
"description": "The code of the discount.",
|
|
"optional": false,
|
|
"defaultValue": "",
|
|
"expandable": false,
|
|
"children": []
|
|
},
|
|
{
|
|
"name": "customHeaders",
|
|
"type": "`Record<string, any>`",
|
|
"description": "Custom headers to attach to the request.",
|
|
"optional": false,
|
|
"defaultValue": "{}",
|
|
"expandable": false,
|
|
"children": []
|
|
}
|
|
]} />
|
|
|
|
#### Returns
|
|
|
|
<ParameterTypes parameters={[
|
|
{
|
|
"name": "ResponsePromise",
|
|
"type": "[ResponsePromise](../internal/types/internal.ResponsePromise.mdx)<[AdminDiscountsRes](../internal/types/internal.AdminDiscountsRes.mdx)>",
|
|
"optional": false,
|
|
"defaultValue": "",
|
|
"description": "Resolves to the details of the discount.",
|
|
"expandable": false,
|
|
"children": [
|
|
{
|
|
"name": "AdminDiscountsRes",
|
|
"type": "`object`",
|
|
"description": "The discount's details.",
|
|
"optional": false,
|
|
"defaultValue": "",
|
|
"expandable": false,
|
|
"children": [
|
|
{
|
|
"name": "discount",
|
|
"type": "[Discount](../internal/classes/internal.Discount-1.mdx)",
|
|
"description": "Discount details.",
|
|
"optional": false,
|
|
"defaultValue": "",
|
|
"expandable": false,
|
|
"children": [
|
|
{
|
|
"name": "code",
|
|
"type": "`string`",
|
|
"description": "A unique code for the discount - this will be used by the customer to apply the discount",
|
|
"optional": false,
|
|
"defaultValue": "",
|
|
"expandable": false,
|
|
"children": []
|
|
},
|
|
{
|
|
"name": "created_at",
|
|
"type": "`Date`",
|
|
"description": "The date with timezone at which the resource was created.",
|
|
"optional": false,
|
|
"defaultValue": "",
|
|
"expandable": false,
|
|
"children": []
|
|
},
|
|
{
|
|
"name": "deleted_at",
|
|
"type": "`null` \\| `Date`",
|
|
"description": "The date with timezone at which the resource was deleted.",
|
|
"optional": false,
|
|
"defaultValue": "",
|
|
"expandable": false,
|
|
"children": []
|
|
},
|
|
{
|
|
"name": "ends_at",
|
|
"type": "`null` \\| `Date`",
|
|
"description": "The time at which the discount can no longer be used.",
|
|
"optional": false,
|
|
"defaultValue": "",
|
|
"expandable": false,
|
|
"children": []
|
|
},
|
|
{
|
|
"name": "id",
|
|
"type": "`string`",
|
|
"description": "The discount's ID",
|
|
"optional": false,
|
|
"defaultValue": "",
|
|
"expandable": false,
|
|
"children": []
|
|
},
|
|
{
|
|
"name": "is_disabled",
|
|
"type": "`boolean`",
|
|
"description": "Whether the Discount has been disabled. Disabled discounts cannot be applied to carts",
|
|
"optional": false,
|
|
"defaultValue": "",
|
|
"expandable": false,
|
|
"children": []
|
|
},
|
|
{
|
|
"name": "is_dynamic",
|
|
"type": "`boolean`",
|
|
"description": "A flag to indicate if multiple instances of the discount can be generated. I.e. for newsletter discounts",
|
|
"optional": false,
|
|
"defaultValue": "",
|
|
"expandable": false,
|
|
"children": []
|
|
},
|
|
{
|
|
"name": "metadata",
|
|
"type": "`Record<string, unknown>`",
|
|
"description": "An optional key-value map with additional details",
|
|
"optional": false,
|
|
"defaultValue": "",
|
|
"expandable": false,
|
|
"children": []
|
|
},
|
|
{
|
|
"name": "parent_discount",
|
|
"type": "[Discount](../internal/classes/internal.Discount-1.mdx)",
|
|
"description": "The details of the parent discount that this discount was created from.",
|
|
"optional": false,
|
|
"defaultValue": "",
|
|
"expandable": true,
|
|
"children": []
|
|
},
|
|
{
|
|
"name": "parent_discount_id",
|
|
"type": "`string`",
|
|
"description": "The Discount that the discount was created from. This will always be a dynamic discount",
|
|
"optional": false,
|
|
"defaultValue": "",
|
|
"expandable": false,
|
|
"children": []
|
|
},
|
|
{
|
|
"name": "regions",
|
|
"type": "[Region](../internal/classes/internal.Region.mdx)[]",
|
|
"description": "The details of the regions in which the Discount can be used.",
|
|
"optional": false,
|
|
"defaultValue": "",
|
|
"expandable": true,
|
|
"children": []
|
|
},
|
|
{
|
|
"name": "rule",
|
|
"type": "[DiscountRule](../internal/classes/internal.internal.DiscountRule.mdx)",
|
|
"description": "The details of the discount rule that defines how the discount will be applied to a cart..",
|
|
"optional": false,
|
|
"defaultValue": "",
|
|
"expandable": true,
|
|
"children": []
|
|
},
|
|
{
|
|
"name": "rule_id",
|
|
"type": "`string`",
|
|
"description": "The ID of the discount rule that defines how the discount will be applied to a cart.",
|
|
"optional": false,
|
|
"defaultValue": "",
|
|
"expandable": false,
|
|
"children": []
|
|
},
|
|
{
|
|
"name": "starts_at",
|
|
"type": "`Date`",
|
|
"description": "The time at which the discount can be used.",
|
|
"optional": false,
|
|
"defaultValue": "",
|
|
"expandable": false,
|
|
"children": []
|
|
},
|
|
{
|
|
"name": "updated_at",
|
|
"type": "`Date`",
|
|
"description": "The date with timezone at which the resource was updated.",
|
|
"optional": false,
|
|
"defaultValue": "",
|
|
"expandable": false,
|
|
"children": []
|
|
},
|
|
{
|
|
"name": "usage_count",
|
|
"type": "`number`",
|
|
"description": "The number of times a discount has been used.",
|
|
"optional": false,
|
|
"defaultValue": "0",
|
|
"expandable": false,
|
|
"children": []
|
|
},
|
|
{
|
|
"name": "usage_limit",
|
|
"type": "`null` \\| `number`",
|
|
"description": "The maximum number of times that a discount can be used.",
|
|
"optional": false,
|
|
"defaultValue": "",
|
|
"expandable": false,
|
|
"children": []
|
|
},
|
|
{
|
|
"name": "valid_duration",
|
|
"type": "`null` \\| `string`",
|
|
"description": "Duration the discount runs between",
|
|
"optional": false,
|
|
"defaultValue": "",
|
|
"expandable": false,
|
|
"children": []
|
|
}
|
|
]
|
|
}
|
|
]
|
|
}
|
|
]
|
|
}
|
|
]} />
|
|
|
|
___
|
|
|
|
### update
|
|
|
|
Update a discount with a given set of rules that define how the discount is applied.
|
|
|
|
#### Example
|
|
|
|
```ts
|
|
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.discounts
|
|
.update(discountId, {
|
|
code: "TEST",
|
|
})
|
|
.then(({ discount }) => {
|
|
console.log(discount.id)
|
|
})
|
|
```
|
|
|
|
#### Parameters
|
|
|
|
<ParameterTypes parameters={[
|
|
{
|
|
"name": "id",
|
|
"type": "`string`",
|
|
"description": "The discount's ID.",
|
|
"optional": false,
|
|
"defaultValue": "",
|
|
"expandable": false,
|
|
"children": []
|
|
},
|
|
{
|
|
"name": "payload",
|
|
"type": "[AdminPostDiscountsDiscountReq](../internal/classes/internal.AdminPostDiscountsDiscountReq.mdx)",
|
|
"description": "The attributes to update in the discount.",
|
|
"optional": false,
|
|
"defaultValue": "",
|
|
"expandable": false,
|
|
"children": [
|
|
{
|
|
"name": "code",
|
|
"type": "`string`",
|
|
"description": "A unique code that will be used to redeem the discount",
|
|
"optional": true,
|
|
"defaultValue": "",
|
|
"expandable": false,
|
|
"children": []
|
|
},
|
|
{
|
|
"name": "ends_at",
|
|
"type": "`null` \\| `Date`",
|
|
"description": "The date and time at which the discount should no longer be available.",
|
|
"optional": true,
|
|
"defaultValue": "",
|
|
"expandable": false,
|
|
"children": []
|
|
},
|
|
{
|
|
"name": "is_disabled",
|
|
"type": "`boolean`",
|
|
"description": "Whether the discount code is disabled on creation. If set to `true`, it will not be available for customers.",
|
|
"optional": true,
|
|
"defaultValue": "",
|
|
"expandable": false,
|
|
"children": []
|
|
},
|
|
{
|
|
"name": "metadata",
|
|
"type": "`Record<string, unknown>`",
|
|
"description": "An object containing metadata of the discount",
|
|
"optional": true,
|
|
"defaultValue": "",
|
|
"expandable": false,
|
|
"children": []
|
|
},
|
|
{
|
|
"name": "regions",
|
|
"type": "`string`[]",
|
|
"description": "A list of region IDs representing the Regions in which the Discount can be used.",
|
|
"optional": true,
|
|
"defaultValue": "",
|
|
"expandable": false,
|
|
"children": []
|
|
},
|
|
{
|
|
"name": "rule",
|
|
"type": "[AdminUpdateDiscountRule](../internal/classes/internal.AdminUpdateDiscountRule.mdx)",
|
|
"description": "The discount rule that defines how discounts are calculated",
|
|
"optional": true,
|
|
"defaultValue": "",
|
|
"expandable": false,
|
|
"children": [
|
|
{
|
|
"name": "allocation",
|
|
"type": "[AllocationType](../internal/enums/internal.internal.AllocationType.mdx)",
|
|
"description": "The discount rule's allocation.",
|
|
"optional": true,
|
|
"defaultValue": "",
|
|
"expandable": false,
|
|
"children": [
|
|
{
|
|
"name": "ITEM",
|
|
"type": "`\"item\"`",
|
|
"description": "The discount should be applied to applicable items in the cart.",
|
|
"optional": true,
|
|
"defaultValue": "",
|
|
"expandable": false,
|
|
"children": []
|
|
},
|
|
{
|
|
"name": "TOTAL",
|
|
"type": "`\"total\"`",
|
|
"description": "The discount should be applied to the checkout total.",
|
|
"optional": true,
|
|
"defaultValue": "",
|
|
"expandable": false,
|
|
"children": []
|
|
}
|
|
]
|
|
},
|
|
{
|
|
"name": "conditions",
|
|
"type": "[AdminUpsertCondition](../internal/classes/internal.internal.AdminUpsertCondition.mdx)[]",
|
|
"description": "The discount rule's discount conditions.",
|
|
"optional": true,
|
|
"defaultValue": "",
|
|
"expandable": false,
|
|
"children": [
|
|
{
|
|
"name": "customer_groups",
|
|
"type": "`string`[]",
|
|
"description": "The customer groups associated with the discount condition, if the discount condition's type is `customer_groups`.",
|
|
"optional": true,
|
|
"defaultValue": "",
|
|
"expandable": false,
|
|
"children": []
|
|
},
|
|
{
|
|
"name": "id",
|
|
"type": "`string`",
|
|
"description": "The discount condition's ID.",
|
|
"optional": true,
|
|
"defaultValue": "",
|
|
"expandable": false,
|
|
"children": []
|
|
},
|
|
{
|
|
"name": "operator",
|
|
"type": "[DiscountConditionOperator](../internal/enums/internal.DiscountConditionOperator.mdx)",
|
|
"description": "The discount condition's operator.",
|
|
"optional": false,
|
|
"defaultValue": "",
|
|
"expandable": false,
|
|
"children": []
|
|
},
|
|
{
|
|
"name": "product_collections",
|
|
"type": "`string`[]",
|
|
"description": "The product collections associated with the discount condition, if the discount condition's type is `product_collections`.",
|
|
"optional": true,
|
|
"defaultValue": "",
|
|
"expandable": false,
|
|
"children": []
|
|
},
|
|
{
|
|
"name": "product_tags",
|
|
"type": "`string`[]",
|
|
"description": "The product tags associated with the discount condition, if the discount condition's type is `product_tags`.",
|
|
"optional": true,
|
|
"defaultValue": "",
|
|
"expandable": false,
|
|
"children": []
|
|
},
|
|
{
|
|
"name": "product_types",
|
|
"type": "`string`[]",
|
|
"description": "The product types associated with the discount condition, if the discount condition's type is `product_types`.",
|
|
"optional": true,
|
|
"defaultValue": "",
|
|
"expandable": false,
|
|
"children": []
|
|
},
|
|
{
|
|
"name": "products",
|
|
"type": "`string`[]",
|
|
"description": "The products associated with the discount condition, if the discount condition's type is `products`.",
|
|
"optional": true,
|
|
"defaultValue": "",
|
|
"expandable": false,
|
|
"children": []
|
|
}
|
|
]
|
|
},
|
|
{
|
|
"name": "description",
|
|
"type": "`string`",
|
|
"description": "The discount rule's description.",
|
|
"optional": true,
|
|
"defaultValue": "",
|
|
"expandable": false,
|
|
"children": []
|
|
},
|
|
{
|
|
"name": "id",
|
|
"type": "`string`",
|
|
"description": "The discount rule's ID.",
|
|
"optional": false,
|
|
"defaultValue": "",
|
|
"expandable": false,
|
|
"children": []
|
|
},
|
|
{
|
|
"name": "value",
|
|
"type": "`number`",
|
|
"description": "The discount rule's value.",
|
|
"optional": true,
|
|
"defaultValue": "",
|
|
"expandable": false,
|
|
"children": []
|
|
}
|
|
]
|
|
},
|
|
{
|
|
"name": "starts_at",
|
|
"type": "`Date`",
|
|
"description": "The date and time at which the discount should be available.",
|
|
"optional": true,
|
|
"defaultValue": "",
|
|
"expandable": false,
|
|
"children": []
|
|
},
|
|
{
|
|
"name": "usage_limit",
|
|
"type": "`null` \\| `number`",
|
|
"description": "Maximum number of times the discount can be used",
|
|
"optional": true,
|
|
"defaultValue": "",
|
|
"expandable": false,
|
|
"children": []
|
|
},
|
|
{
|
|
"name": "valid_duration",
|
|
"type": "`null` \\| `string`",
|
|
"description": "The duration the discount runs between",
|
|
"optional": true,
|
|
"defaultValue": "",
|
|
"expandable": false,
|
|
"children": []
|
|
}
|
|
]
|
|
},
|
|
{
|
|
"name": "customHeaders",
|
|
"type": "`Record<string, any>`",
|
|
"description": "Custom headers to attach to the request.",
|
|
"optional": false,
|
|
"defaultValue": "{}",
|
|
"expandable": false,
|
|
"children": []
|
|
}
|
|
]} />
|
|
|
|
#### Returns
|
|
|
|
<ParameterTypes parameters={[
|
|
{
|
|
"name": "ResponsePromise",
|
|
"type": "[ResponsePromise](../internal/types/internal.ResponsePromise.mdx)<[AdminDiscountsRes](../internal/types/internal.AdminDiscountsRes.mdx)>",
|
|
"optional": false,
|
|
"defaultValue": "",
|
|
"description": "Resolves to the details of the discount.",
|
|
"expandable": false,
|
|
"children": [
|
|
{
|
|
"name": "AdminDiscountsRes",
|
|
"type": "`object`",
|
|
"description": "The discount's details.",
|
|
"optional": false,
|
|
"defaultValue": "",
|
|
"expandable": false,
|
|
"children": [
|
|
{
|
|
"name": "discount",
|
|
"type": "[Discount](../internal/classes/internal.Discount-1.mdx)",
|
|
"description": "Discount details.",
|
|
"optional": false,
|
|
"defaultValue": "",
|
|
"expandable": false,
|
|
"children": [
|
|
{
|
|
"name": "code",
|
|
"type": "`string`",
|
|
"description": "A unique code for the discount - this will be used by the customer to apply the discount",
|
|
"optional": false,
|
|
"defaultValue": "",
|
|
"expandable": false,
|
|
"children": []
|
|
},
|
|
{
|
|
"name": "created_at",
|
|
"type": "`Date`",
|
|
"description": "The date with timezone at which the resource was created.",
|
|
"optional": false,
|
|
"defaultValue": "",
|
|
"expandable": false,
|
|
"children": []
|
|
},
|
|
{
|
|
"name": "deleted_at",
|
|
"type": "`null` \\| `Date`",
|
|
"description": "The date with timezone at which the resource was deleted.",
|
|
"optional": false,
|
|
"defaultValue": "",
|
|
"expandable": false,
|
|
"children": []
|
|
},
|
|
{
|
|
"name": "ends_at",
|
|
"type": "`null` \\| `Date`",
|
|
"description": "The time at which the discount can no longer be used.",
|
|
"optional": false,
|
|
"defaultValue": "",
|
|
"expandable": false,
|
|
"children": []
|
|
},
|
|
{
|
|
"name": "id",
|
|
"type": "`string`",
|
|
"description": "The discount's ID",
|
|
"optional": false,
|
|
"defaultValue": "",
|
|
"expandable": false,
|
|
"children": []
|
|
},
|
|
{
|
|
"name": "is_disabled",
|
|
"type": "`boolean`",
|
|
"description": "Whether the Discount has been disabled. Disabled discounts cannot be applied to carts",
|
|
"optional": false,
|
|
"defaultValue": "",
|
|
"expandable": false,
|
|
"children": []
|
|
},
|
|
{
|
|
"name": "is_dynamic",
|
|
"type": "`boolean`",
|
|
"description": "A flag to indicate if multiple instances of the discount can be generated. I.e. for newsletter discounts",
|
|
"optional": false,
|
|
"defaultValue": "",
|
|
"expandable": false,
|
|
"children": []
|
|
},
|
|
{
|
|
"name": "metadata",
|
|
"type": "`Record<string, unknown>`",
|
|
"description": "An optional key-value map with additional details",
|
|
"optional": false,
|
|
"defaultValue": "",
|
|
"expandable": false,
|
|
"children": []
|
|
},
|
|
{
|
|
"name": "parent_discount",
|
|
"type": "[Discount](../internal/classes/internal.Discount-1.mdx)",
|
|
"description": "The details of the parent discount that this discount was created from.",
|
|
"optional": false,
|
|
"defaultValue": "",
|
|
"expandable": true,
|
|
"children": []
|
|
},
|
|
{
|
|
"name": "parent_discount_id",
|
|
"type": "`string`",
|
|
"description": "The Discount that the discount was created from. This will always be a dynamic discount",
|
|
"optional": false,
|
|
"defaultValue": "",
|
|
"expandable": false,
|
|
"children": []
|
|
},
|
|
{
|
|
"name": "regions",
|
|
"type": "[Region](../internal/classes/internal.Region.mdx)[]",
|
|
"description": "The details of the regions in which the Discount can be used.",
|
|
"optional": false,
|
|
"defaultValue": "",
|
|
"expandable": true,
|
|
"children": []
|
|
},
|
|
{
|
|
"name": "rule",
|
|
"type": "[DiscountRule](../internal/classes/internal.internal.DiscountRule.mdx)",
|
|
"description": "The details of the discount rule that defines how the discount will be applied to a cart..",
|
|
"optional": false,
|
|
"defaultValue": "",
|
|
"expandable": true,
|
|
"children": []
|
|
},
|
|
{
|
|
"name": "rule_id",
|
|
"type": "`string`",
|
|
"description": "The ID of the discount rule that defines how the discount will be applied to a cart.",
|
|
"optional": false,
|
|
"defaultValue": "",
|
|
"expandable": false,
|
|
"children": []
|
|
},
|
|
{
|
|
"name": "starts_at",
|
|
"type": "`Date`",
|
|
"description": "The time at which the discount can be used.",
|
|
"optional": false,
|
|
"defaultValue": "",
|
|
"expandable": false,
|
|
"children": []
|
|
},
|
|
{
|
|
"name": "updated_at",
|
|
"type": "`Date`",
|
|
"description": "The date with timezone at which the resource was updated.",
|
|
"optional": false,
|
|
"defaultValue": "",
|
|
"expandable": false,
|
|
"children": []
|
|
},
|
|
{
|
|
"name": "usage_count",
|
|
"type": "`number`",
|
|
"description": "The number of times a discount has been used.",
|
|
"optional": false,
|
|
"defaultValue": "0",
|
|
"expandable": false,
|
|
"children": []
|
|
},
|
|
{
|
|
"name": "usage_limit",
|
|
"type": "`null` \\| `number`",
|
|
"description": "The maximum number of times that a discount can be used.",
|
|
"optional": false,
|
|
"defaultValue": "",
|
|
"expandable": false,
|
|
"children": []
|
|
},
|
|
{
|
|
"name": "valid_duration",
|
|
"type": "`null` \\| `string`",
|
|
"description": "Duration the discount runs between",
|
|
"optional": false,
|
|
"defaultValue": "",
|
|
"expandable": false,
|
|
"children": []
|
|
}
|
|
]
|
|
}
|
|
]
|
|
}
|
|
]
|
|
}
|
|
]} />
|
|
|
|
___
|
|
|
|
### updateCondition
|
|
|
|
Update a discount condition. Only one of `products`, `product_types`, `product_collections`, `product_tags`, and `customer_groups` should be provided in the `payload` parameter,
|
|
based on the type of discount condition. For example, if the discount condition's type is `products`, the `products` field should be provided in the `payload` parameter.
|
|
|
|
#### Example
|
|
|
|
To update a condition in a discount:
|
|
|
|
```ts
|
|
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.discounts
|
|
.updateCondition(discountId, conditionId, {
|
|
products: [productId],
|
|
})
|
|
.then(({ discount }) => {
|
|
console.log(discount.id)
|
|
})
|
|
```
|
|
|
|
To specify relations that should be retrieved as part of the response:
|
|
|
|
```ts
|
|
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.discounts
|
|
.updateCondition(
|
|
discountId,
|
|
conditionId,
|
|
{
|
|
products: [productId],
|
|
],
|
|
}, {
|
|
expand: "rule",
|
|
}
|
|
)
|
|
.then(({ discount }) => {
|
|
console.log(discount.id)
|
|
})
|
|
```
|
|
|
|
#### Parameters
|
|
|
|
<ParameterTypes parameters={[
|
|
{
|
|
"name": "discountId",
|
|
"type": "`string`",
|
|
"description": "The discount's ID.",
|
|
"optional": false,
|
|
"defaultValue": "",
|
|
"expandable": false,
|
|
"children": []
|
|
},
|
|
{
|
|
"name": "conditionId",
|
|
"type": "`string`",
|
|
"description": "The ID of the discount condition.",
|
|
"optional": false,
|
|
"defaultValue": "",
|
|
"expandable": false,
|
|
"children": []
|
|
},
|
|
{
|
|
"name": "payload",
|
|
"type": "[AdminPostDiscountsDiscountConditionsCondition](../internal/classes/internal.AdminPostDiscountsDiscountConditionsCondition.mdx)",
|
|
"description": "The attributes to update in the discount condition.",
|
|
"optional": false,
|
|
"defaultValue": "",
|
|
"expandable": false,
|
|
"children": [
|
|
{
|
|
"name": "customer_groups",
|
|
"type": "`string`[]",
|
|
"description": "The customer groups associated with the discount condition, if the discount condition's type is `customer_groups`.",
|
|
"optional": true,
|
|
"defaultValue": "",
|
|
"expandable": false,
|
|
"children": []
|
|
},
|
|
{
|
|
"name": "product_collections",
|
|
"type": "`string`[]",
|
|
"description": "The product collections associated with the discount condition, if the discount condition's type is `product_collections`.",
|
|
"optional": true,
|
|
"defaultValue": "",
|
|
"expandable": false,
|
|
"children": []
|
|
},
|
|
{
|
|
"name": "product_tags",
|
|
"type": "`string`[]",
|
|
"description": "The product tags associated with the discount condition, if the discount condition's type is `product_tags`.",
|
|
"optional": true,
|
|
"defaultValue": "",
|
|
"expandable": false,
|
|
"children": []
|
|
},
|
|
{
|
|
"name": "product_types",
|
|
"type": "`string`[]",
|
|
"description": "The product types associated with the discount condition, if the discount condition's type is `product_types`.",
|
|
"optional": true,
|
|
"defaultValue": "",
|
|
"expandable": false,
|
|
"children": []
|
|
},
|
|
{
|
|
"name": "products",
|
|
"type": "`string`[]",
|
|
"description": "The products associated with the discount condition, if the discount condition's type is `products`.",
|
|
"optional": true,
|
|
"defaultValue": "",
|
|
"expandable": false,
|
|
"children": []
|
|
}
|
|
]
|
|
},
|
|
{
|
|
"name": "query",
|
|
"type": "[AdminPostDiscountsDiscountConditionsConditionParams](../internal/classes/internal.AdminPostDiscountsDiscountConditionsConditionParams.mdx)",
|
|
"description": "Configurations to apply on the returned discount.",
|
|
"optional": false,
|
|
"defaultValue": "{}",
|
|
"expandable": false,
|
|
"children": [
|
|
{
|
|
"name": "expand",
|
|
"type": "`string`",
|
|
"description": "Comma-separated relations that should be expanded in the returned data.",
|
|
"optional": true,
|
|
"defaultValue": "",
|
|
"expandable": false,
|
|
"children": []
|
|
},
|
|
{
|
|
"name": "fields",
|
|
"type": "`string`",
|
|
"description": "Comma-separated fields that should be included in the returned data.",
|
|
"optional": true,
|
|
"defaultValue": "",
|
|
"expandable": false,
|
|
"children": []
|
|
}
|
|
]
|
|
},
|
|
{
|
|
"name": "customHeaders",
|
|
"type": "`Record<string, any>`",
|
|
"description": "Custom headers to attach to the request.",
|
|
"optional": false,
|
|
"defaultValue": "{}",
|
|
"expandable": false,
|
|
"children": []
|
|
}
|
|
]} />
|
|
|
|
#### Returns
|
|
|
|
<ParameterTypes parameters={[
|
|
{
|
|
"name": "ResponsePromise",
|
|
"type": "[ResponsePromise](../internal/types/internal.ResponsePromise.mdx)<[AdminDiscountsRes](../internal/types/internal.AdminDiscountsRes.mdx)>",
|
|
"optional": false,
|
|
"defaultValue": "",
|
|
"description": "Resolves to the details of the discount.",
|
|
"expandable": false,
|
|
"children": [
|
|
{
|
|
"name": "AdminDiscountsRes",
|
|
"type": "`object`",
|
|
"description": "The discount's details.",
|
|
"optional": false,
|
|
"defaultValue": "",
|
|
"expandable": false,
|
|
"children": [
|
|
{
|
|
"name": "discount",
|
|
"type": "[Discount](../internal/classes/internal.Discount-1.mdx)",
|
|
"description": "Discount details.",
|
|
"optional": false,
|
|
"defaultValue": "",
|
|
"expandable": false,
|
|
"children": [
|
|
{
|
|
"name": "code",
|
|
"type": "`string`",
|
|
"description": "A unique code for the discount - this will be used by the customer to apply the discount",
|
|
"optional": false,
|
|
"defaultValue": "",
|
|
"expandable": false,
|
|
"children": []
|
|
},
|
|
{
|
|
"name": "created_at",
|
|
"type": "`Date`",
|
|
"description": "The date with timezone at which the resource was created.",
|
|
"optional": false,
|
|
"defaultValue": "",
|
|
"expandable": false,
|
|
"children": []
|
|
},
|
|
{
|
|
"name": "deleted_at",
|
|
"type": "`null` \\| `Date`",
|
|
"description": "The date with timezone at which the resource was deleted.",
|
|
"optional": false,
|
|
"defaultValue": "",
|
|
"expandable": false,
|
|
"children": []
|
|
},
|
|
{
|
|
"name": "ends_at",
|
|
"type": "`null` \\| `Date`",
|
|
"description": "The time at which the discount can no longer be used.",
|
|
"optional": false,
|
|
"defaultValue": "",
|
|
"expandable": false,
|
|
"children": []
|
|
},
|
|
{
|
|
"name": "id",
|
|
"type": "`string`",
|
|
"description": "The discount's ID",
|
|
"optional": false,
|
|
"defaultValue": "",
|
|
"expandable": false,
|
|
"children": []
|
|
},
|
|
{
|
|
"name": "is_disabled",
|
|
"type": "`boolean`",
|
|
"description": "Whether the Discount has been disabled. Disabled discounts cannot be applied to carts",
|
|
"optional": false,
|
|
"defaultValue": "",
|
|
"expandable": false,
|
|
"children": []
|
|
},
|
|
{
|
|
"name": "is_dynamic",
|
|
"type": "`boolean`",
|
|
"description": "A flag to indicate if multiple instances of the discount can be generated. I.e. for newsletter discounts",
|
|
"optional": false,
|
|
"defaultValue": "",
|
|
"expandable": false,
|
|
"children": []
|
|
},
|
|
{
|
|
"name": "metadata",
|
|
"type": "`Record<string, unknown>`",
|
|
"description": "An optional key-value map with additional details",
|
|
"optional": false,
|
|
"defaultValue": "",
|
|
"expandable": false,
|
|
"children": []
|
|
},
|
|
{
|
|
"name": "parent_discount",
|
|
"type": "[Discount](../internal/classes/internal.Discount-1.mdx)",
|
|
"description": "The details of the parent discount that this discount was created from.",
|
|
"optional": false,
|
|
"defaultValue": "",
|
|
"expandable": true,
|
|
"children": []
|
|
},
|
|
{
|
|
"name": "parent_discount_id",
|
|
"type": "`string`",
|
|
"description": "The Discount that the discount was created from. This will always be a dynamic discount",
|
|
"optional": false,
|
|
"defaultValue": "",
|
|
"expandable": false,
|
|
"children": []
|
|
},
|
|
{
|
|
"name": "regions",
|
|
"type": "[Region](../internal/classes/internal.Region.mdx)[]",
|
|
"description": "The details of the regions in which the Discount can be used.",
|
|
"optional": false,
|
|
"defaultValue": "",
|
|
"expandable": true,
|
|
"children": []
|
|
},
|
|
{
|
|
"name": "rule",
|
|
"type": "[DiscountRule](../internal/classes/internal.internal.DiscountRule.mdx)",
|
|
"description": "The details of the discount rule that defines how the discount will be applied to a cart..",
|
|
"optional": false,
|
|
"defaultValue": "",
|
|
"expandable": true,
|
|
"children": []
|
|
},
|
|
{
|
|
"name": "rule_id",
|
|
"type": "`string`",
|
|
"description": "The ID of the discount rule that defines how the discount will be applied to a cart.",
|
|
"optional": false,
|
|
"defaultValue": "",
|
|
"expandable": false,
|
|
"children": []
|
|
},
|
|
{
|
|
"name": "starts_at",
|
|
"type": "`Date`",
|
|
"description": "The time at which the discount can be used.",
|
|
"optional": false,
|
|
"defaultValue": "",
|
|
"expandable": false,
|
|
"children": []
|
|
},
|
|
{
|
|
"name": "updated_at",
|
|
"type": "`Date`",
|
|
"description": "The date with timezone at which the resource was updated.",
|
|
"optional": false,
|
|
"defaultValue": "",
|
|
"expandable": false,
|
|
"children": []
|
|
},
|
|
{
|
|
"name": "usage_count",
|
|
"type": "`number`",
|
|
"description": "The number of times a discount has been used.",
|
|
"optional": false,
|
|
"defaultValue": "0",
|
|
"expandable": false,
|
|
"children": []
|
|
},
|
|
{
|
|
"name": "usage_limit",
|
|
"type": "`null` \\| `number`",
|
|
"description": "The maximum number of times that a discount can be used.",
|
|
"optional": false,
|
|
"defaultValue": "",
|
|
"expandable": false,
|
|
"children": []
|
|
},
|
|
{
|
|
"name": "valid_duration",
|
|
"type": "`null` \\| `string`",
|
|
"description": "Duration the discount runs between",
|
|
"optional": false,
|
|
"defaultValue": "",
|
|
"expandable": false,
|
|
"children": []
|
|
}
|
|
]
|
|
}
|
|
]
|
|
}
|
|
]
|
|
}
|
|
]} />
|