|
1
|
/** |
|
2
|
* @oas [post] /admin/promotions |
|
3
|
* operationId: PostPromotions |
|
4
|
* summary: Create Promotion |
|
5
|
* description: Create a promotion. |
|
6
|
* x-authenticated: true |
|
7
|
* parameters: |
|
8
|
* - name: fields |
|
9
|
* in: query |
|
10
|
* description: Comma-separated fields that should be included in the returned data. if a field is prefixed with `+` it will be added to the default fields, using `-` will remove it from the default |
|
11
|
* fields. without prefix it will replace the entire default fields. |
|
12
|
* required: false |
|
13
|
* schema: |
|
14
|
* type: string |
|
15
|
* title: fields |
|
16
|
* description: Comma-separated fields that should be included in the returned data. if a field is prefixed with `+` it will be added to the default fields, using `-` will remove it from the default |
|
17
|
* fields. without prefix it will replace the entire default fields. |
|
18
|
* externalDocs: |
|
19
|
* url: "#select-fields-and-relations" |
|
20
|
* security: |
|
21
|
* - api_token: [] |
|
22
|
* - cookie_auth: [] |
|
23
|
* - jwt_token: [] |
|
24
|
* requestBody: |
|
25
|
* content: |
|
26
|
* application/json: |
|
27
|
* schema: |
|
28
|
* allOf: |
|
29
|
* - type: object |
|
30
|
* description: The promotion's details. |
|
31
|
* required: |
|
32
|
* - code |
|
33
|
* - type |
|
34
|
* - campaign_id |
|
35
|
* - application_method |
|
36
|
* properties: |
|
37
|
* code: |
|
38
|
* type: string |
|
39
|
* title: code |
|
40
|
* description: The promotion's code. |
|
41
|
* is_automatic: |
|
42
|
* type: boolean |
|
43
|
* title: is_automatic |
|
44
|
* description: Whether the promotion is applied automatically. |
|
45
|
* type: |
|
46
|
* type: string |
|
47
|
* description: The promotion's type. |
|
48
|
* externalDocs: |
|
49
|
* url: https://docs.medusajs.com/resources/commerce-modules/promotion/concepts#what-is-a-promotion |
|
50
|
* enum: |
|
51
|
* - standard |
|
52
|
* - buyget |
|
53
|
* campaign_id: |
|
54
|
* type: string |
|
55
|
* title: campaign_id |
|
56
|
* description: The ID of the campaign that the promotion belongs to. |
|
57
|
* campaign: |
|
58
|
* type: object |
|
59
|
* description: The details of a campaign to create and add the promotion to it. |
|
60
|
* required: |
|
61
|
* - name |
|
62
|
* - campaign_identifier |
|
63
|
* - description |
|
64
|
* - budget |
|
65
|
* - starts_at |
|
66
|
* - ends_at |
|
67
|
* properties: |
|
68
|
* name: |
|
69
|
* type: string |
|
70
|
* title: name |
|
71
|
* description: The campaign's name. |
|
72
|
* campaign_identifier: |
|
73
|
* type: string |
|
74
|
* title: campaign_identifier |
|
75
|
* description: The campaign's identifier. |
|
76
|
* description: |
|
77
|
* type: string |
|
78
|
* title: description |
|
79
|
* description: The campaign's description. |
|
80
|
* budget: |
|
81
|
* type: object |
|
82
|
* description: The campaign's budget which, when crossed, ends the campaign. |
|
83
|
* required: |
|
84
|
* - type |
|
85
|
* - limit |
|
86
|
* - currency_code |
|
87
|
* properties: |
|
88
|
* type: |
|
89
|
* type: string |
|
90
|
* description: | |
|
91
|
* The budget's type. This can't be edited later. Use `spend` to set a limit on the total amount discounted by the campaign's promotions. Use `usage` to set a limit on the total number of times the campaign's promotions can be used. |
|
92
|
* enum: |
|
93
|
* - spend |
|
94
|
* - usage |
|
95
|
* limit: |
|
96
|
* type: number |
|
97
|
* title: limit |
|
98
|
* description: The budget's limit. |
|
99
|
* currency_code: |
|
100
|
* type: string |
|
101
|
* title: currency_code |
|
102
|
* description: The campaign budget's currency code. This can't be edited later. |
|
103
|
* starts_at: |
|
104
|
* type: string |
|
105
|
* title: starts_at |
|
106
|
* description: The campaign's start date. |
|
107
|
* format: date-time |
|
108
|
* ends_at: |
|
109
|
* type: string |
|
110
|
* title: ends_at |
|
111
|
* description: The campaign's end date. |
|
112
|
* format: date-time |
|
113
|
* application_method: |
|
114
|
* type: object |
|
115
|
* description: The promotion's application method. |
|
116
|
* required: |
|
117
|
* - description |
|
118
|
* - value |
|
119
|
* - currency_code |
|
120
|
* - max_quantity |
|
121
|
* - type |
|
122
|
* - target_type |
|
123
|
* - apply_to_quantity |
|
124
|
* - buy_rules_min_quantity |
|
125
|
* properties: |
|
126
|
* description: |
|
127
|
* type: string |
|
128
|
* title: description |
|
129
|
* description: The application method's description. |
|
130
|
* value: |
|
131
|
* type: number |
|
132
|
* title: value |
|
133
|
* description: The discounted amount applied by the associated promotion based on the `type`. |
|
134
|
* currency_code: |
|
135
|
* type: string |
|
136
|
* title: currency_code |
|
137
|
* description: The application method's currency code. |
|
138
|
* max_quantity: |
|
139
|
* type: number |
|
140
|
* title: max_quantity |
|
141
|
* description: The max quantity allowed in the cart for the associated promotion to be applied. |
|
142
|
* type: |
|
143
|
* type: string |
|
144
|
* description: The type of the application method indicating how the associated promotion is applied. |
|
145
|
* enum: |
|
146
|
* - fixed |
|
147
|
* - percentage |
|
148
|
* target_type: |
|
149
|
* type: string |
|
150
|
* description: The target type of the application method indicating whether the associated promotion is applied to the cart's items, shipping methods, or the whole order. |
|
151
|
* enum: |
|
152
|
* - order |
|
153
|
* - shipping_methods |
|
154
|
* - items |
|
155
|
* allocation: |
|
156
|
* type: string |
|
157
|
* description: The allocation value that indicates whether the associated promotion is applied on each item in a cart or split between the items in the cart. |
|
158
|
* enum: |
|
159
|
* - each |
|
160
|
* - across |
|
161
|
* target_rules: |
|
162
|
* type: array |
|
163
|
* description: The application method's target rules. |
|
164
|
* items: |
|
165
|
* type: object |
|
166
|
* description: A target rule's details. |
|
167
|
* required: |
|
168
|
* - operator |
|
169
|
* - description |
|
170
|
* - attribute |
|
171
|
* - values |
|
172
|
* properties: |
|
173
|
* operator: |
|
174
|
* type: string |
|
175
|
* description: The operator used to check whether the target rule applies on a cart. For example, `eq` means that the cart's value for the specified attribute must match the specified value. |
|
176
|
* enum: |
|
177
|
* - gte |
|
178
|
* - lte |
|
179
|
* - gt |
|
180
|
* - lt |
|
181
|
* - eq |
|
182
|
* - ne |
|
183
|
* - in |
|
184
|
* description: |
|
185
|
* type: string |
|
186
|
* title: description |
|
187
|
* description: The target rule's description. |
|
188
|
* attribute: |
|
189
|
* type: string |
|
190
|
* title: attribute |
|
191
|
* description: The attribute to compare against when checking whether a promotion can be applied on a cart. |
|
192
|
* example: items.product.id |
|
193
|
* values: |
|
194
|
* oneOf: |
|
195
|
* - type: string |
|
196
|
* title: values |
|
197
|
* description: The attribute's value. |
|
198
|
* example: prod_123 |
|
199
|
* - type: array |
|
200
|
* description: The allowed attribute values. |
|
201
|
* items: |
|
202
|
* type: string |
|
203
|
* title: values |
|
204
|
* description: An attribute value. |
|
205
|
* example: prod_123 |
|
206
|
* buy_rules: |
|
207
|
* type: array |
|
208
|
* description: The application method's buy rules. |
|
209
|
* items: |
|
210
|
* type: object |
|
211
|
* description: A buy rule's details. |
|
212
|
* required: |
|
213
|
* - operator |
|
214
|
* - description |
|
215
|
* - attribute |
|
216
|
* - values |
|
217
|
* properties: |
|
218
|
* operator: |
|
219
|
* type: string |
|
220
|
* description: The operator used to check whether the buy rule applies on a cart. For example, `eq` means that the cart's value for the specified attribute must match the specified value. |
|
221
|
* enum: |
|
222
|
* - gte |
|
223
|
* - lte |
|
224
|
* - gt |
|
225
|
* - lt |
|
226
|
* - eq |
|
227
|
* - ne |
|
228
|
* - in |
|
229
|
* description: |
|
230
|
* type: string |
|
231
|
* title: description |
|
232
|
* description: The buy rule's description. |
|
233
|
* attribute: |
|
234
|
* type: string |
|
235
|
* title: attribute |
|
236
|
* description: The attribute to compare against when checking whether a promotion can be applied on a cart. |
|
237
|
* example: items.product.id |
|
238
|
* values: |
|
239
|
* oneOf: |
|
240
|
* - type: string |
|
241
|
* title: values |
|
242
|
* description: The attribute's value. |
|
243
|
* example: prod_123 |
|
244
|
* - type: array |
|
245
|
* description: The allowed attribute values. |
|
246
|
* items: |
|
247
|
* type: string |
|
248
|
* title: values |
|
249
|
* description: An attribute value. |
|
250
|
* example: prod_123 |
|
251
|
* apply_to_quantity: |
|
252
|
* type: number |
|
253
|
* title: apply_to_quantity |
|
254
|
* description: The quantity that results from matching the `buyget` promotion's condition. For example, if the promotion is a "Buy 2 shirts get 1 free", the value f this attribute is `1`. |
|
255
|
* buy_rules_min_quantity: |
|
256
|
* type: number |
|
257
|
* title: buy_rules_min_quantity |
|
258
|
* description: The minimum quantity required for a `buyget` promotion to be applied. For example, if the promotion is a "Buy 2 shirts get 1 free", the value of this attribute is `2`. |
|
259
|
* rules: |
|
260
|
* type: array |
|
261
|
* description: The promotion's rules. |
|
262
|
* items: |
|
263
|
* type: object |
|
264
|
* description: A rule's details. |
|
265
|
* required: |
|
266
|
* - operator |
|
267
|
* - description |
|
268
|
* - attribute |
|
269
|
* - values |
|
270
|
* properties: |
|
271
|
* operator: |
|
272
|
* type: string |
|
273
|
* description: The operator used to check whether the buy rule applies on a cart. For example, `eq` means that the cart's value for the specified attribute must match the specified value. |
|
274
|
* enum: |
|
275
|
* - gte |
|
276
|
* - lte |
|
277
|
* - gt |
|
278
|
* - lt |
|
279
|
* - eq |
|
280
|
* - ne |
|
281
|
* - in |
|
282
|
* description: |
|
283
|
* type: string |
|
284
|
* title: description |
|
285
|
* description: The rule's description. |
|
286
|
* attribute: |
|
287
|
* type: string |
|
288
|
* title: attribute |
|
289
|
* description: The attribute to compare against when checking whether a promotion can be applied on a cart. |
|
290
|
* example: items.product.id |
|
291
|
* values: |
|
292
|
* oneOf: |
|
293
|
* - type: string |
|
294
|
* title: values |
|
295
|
* description: The attribute's value. |
|
296
|
* example: prod_123 |
|
297
|
* - type: array |
|
298
|
* description: The allowed attribute values. |
|
299
|
* items: |
|
300
|
* type: string |
|
301
|
* title: values |
|
302
|
* description: An attribute value. |
|
303
|
* example: prod_123 |
|
304
|
* - type: object |
|
305
|
* description: The promotion's details. |
|
306
|
* properties: |
|
307
|
* additional_data: |
|
308
|
* type: object |
|
309
|
* description: Pass additional custom data to the API route. This data is passed to the underlying workflow under the `additional_data` parameter. |
|
310
|
* description: The promotion's details. |
|
311
|
* x-codeSamples: |
|
312
|
* - lang: JavaScript |
|
313
|
* label: JS SDK |
|
314
|
* source: |- |
|
315
|
* import Medusa from "@medusajs/js-sdk" |
|
316
|
* |
|
317
|
* export const sdk = new Medusa({ |
|
318
|
* baseUrl: import.meta.env.VITE_BACKEND_URL || "/", |
|
319
|
* debug: import.meta.env.DEV, |
|
320
|
* auth: { |
|
321
|
* type: "session", |
|
322
|
* }, |
|
323
|
* }) |
|
324
|
* |
|
325
|
* sdk.admin.promotion.create({ |
|
326
|
* name: "My Promotion", |
|
327
|
* description: "This is a test promotion", |
|
328
|
* code: "PROMO123", |
|
329
|
* starts_at: "2021-01-01", |
|
330
|
* ends_at: "2021-01-01", |
|
331
|
* }) |
|
332
|
* .then(({ promotion }) => { |
|
333
|
* console.log(promotion) |
|
334
|
* }) |
|
335
|
* - lang: Shell |
|
336
|
* label: cURL |
|
337
|
* source: |- |
|
338
|
* curl -X POST '{backend_url}/admin/promotions' \ |
|
339
|
* -H 'Authorization: Bearer {jwt_token}' \ |
|
340
|
* -H 'Content-Type: application/json' \ |
|
341
|
* --data-raw '{ |
|
342
|
* "code": "{value}", |
|
343
|
* "type": "{value}", |
|
344
|
* "campaign_id": "{value}", |
|
345
|
* "application_method": { |
|
346
|
* "description": "{value}", |
|
347
|
* "value": 1841223411171328, |
|
348
|
* "currency_code": "{value}", |
|
349
|
* "max_quantity": 2960098049654784, |
|
350
|
* "type": "{value}", |
|
351
|
* "target_type": "{value}", |
|
352
|
* "allocation": "{value}", |
|
353
|
* "target_rules": [], |
|
354
|
* "buy_rules": [], |
|
355
|
* "apply_to_quantity": 708643867590656, |
|
356
|
* "buy_rules_min_quantity": 3167972149428224 |
|
357
|
* } |
|
358
|
* }' |
|
359
|
* tags: |
|
360
|
* - Promotions |
|
361
|
* responses: |
|
362
|
* "200": |
|
363
|
* description: OK |
|
364
|
* content: |
|
365
|
* application/json: |
|
366
|
* schema: |
|
367
|
* $ref: "#/components/schemas/AdminPromotionResponse" |
|
368
|
* "400": |
|
369
|
* $ref: "#/components/responses/400_error" |
|
370
|
* "401": |
|
371
|
* $ref: "#/components/responses/unauthorized" |
|
372
|
* "404": |
|
373
|
* $ref: "#/components/responses/not_found_error" |
|
374
|
* "409": |
|
375
|
* $ref: "#/components/responses/invalid_state_error" |
|
376
|
* "422": |
|
377
|
* $ref: "#/components/responses/invalid_request_error" |
|
378
|
* "500": |
|
379
|
* $ref: "#/components/responses/500_error" |
|
380
|
* x-workflow: createPromotionsWorkflow |
|
381
|
* x-events: [] |
|
382
|
* |
|
383
|
*/ |
|
384
|
|