1 /**
2 * @oas [post] /admin/draft-orders
3 * operationId: PostDraftOrders
4 * summary: Create Draft Order
5 * description: Create a draft order. This creates an order with the `is_draft_order` property enabled. You can later convert the draft order to an order.
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 draft order's details.
31 * required:
32 * - sales_channel_id
33 * - email
34 * - customer_id
35 * - region_id
36 * - currency_code
37 * - shipping_methods
38 * - metadata
39 * properties:
40 * status:
41 * type: string
42 * title: status
43 * description: The draft order's status.
44 * enum:
45 * - completed
46 * sales_channel_id:
47 * type: string
48 * title: sales_channel_id
49 * description: The ID of the associated sales channel.
50 * email:
51 * type: string
52 * title: email
53 * description: The email of the draft order's customer.
54 * format: email
55 * customer_id:
56 * type: string
57 * title: customer_id
58 * description: The ID of the draft order's customer.
59 * billing_address:
60 * type: object
61 * description: The billing address's details.
62 * required:
63 * - first_name
64 * - last_name
65 * - phone
66 * - company
67 * - address_1
68 * - address_2
69 * - city
70 * - country_code
71 * - province
72 * - postal_code
73 * - metadata
74 * properties:
75 * first_name:
76 * type: string
77 * title: first_name
78 * description: The billing address's first name.
79 * last_name:
80 * type: string
81 * title: last_name
82 * description: The billing address's last name.
83 * phone:
84 * type: string
85 * title: phone
86 * description: The billing address's phone.
87 * company:
88 * type: string
89 * title: company
90 * description: The billing address's company.
91 * address_1:
92 * type: string
93 * title: address_1
94 * description: The billing address's first line.
95 * address_2:
96 * type: string
97 * title: address_2
98 * description: The billing address's second line.
99 * city:
100 * type: string
101 * title: city
102 * description: The billing address's city.
103 * country_code:
104 * type: string
105 * title: country_code
106 * description: The billing address's country code.
107 * province:
108 * type: string
109 * title: province
110 * description: The billing address's ISO 3166-2 province code. Must be lower-case.
111 * example: us-ca
112 * externalDocs:
113 * url: https://en.wikipedia.org/wiki/ISO_3166-2
114 * description: Learn more about ISO 3166-2
115 * postal_code:
116 * type: string
117 * title: postal_code
118 * description: The billing address's postal code.
119 * metadata:
120 * type: object
121 * description: The billing address's metadata.
122 * shipping_address:
123 * type: object
124 * description: The draft order's shipping address.
125 * required:
126 * - first_name
127 * - last_name
128 * - phone
129 * - company
130 * - address_1
131 * - address_2
132 * - city
133 * - country_code
134 * - province
135 * - postal_code
136 * - metadata
137 * properties:
138 * first_name:
139 * type: string
140 * title: first_name
141 * description: The shipping address's first name.
142 * last_name:
143 * type: string
144 * title: last_name
145 * description: The shipping address's last name.
146 * phone:
147 * type: string
148 * title: phone
149 * description: The shipping address's phone.
150 * company:
151 * type: string
152 * title: company
153 * description: The shipping address's company.
154 * address_1:
155 * type: string
156 * title: address_1
157 * description: The shipping address's first line.
158 * address_2:
159 * type: string
160 * title: address_2
161 * description: The shipping address's second line.
162 * city:
163 * type: string
164 * title: city
165 * description: The shipping address's city.
166 * country_code:
167 * type: string
168 * title: country_code
169 * description: The shipping address's country code.
170 * province:
171 * type: string
172 * title: province
173 * description: The shipping address's ISO 3166-2 province code. Must be lower-case.
174 * example: us-ca
175 * externalDocs:
176 * url: https://en.wikipedia.org/wiki/ISO_3166-2
177 * description: Learn more about ISO 3166-2
178 * postal_code:
179 * type: string
180 * title: postal_code
181 * description: The shipping address's postal code.
182 * metadata:
183 * type: object
184 * description: The shipping address's metadata.
185 * items:
186 * type: array
187 * description: The draft order's items.
188 * items:
189 * type: object
190 * description: The item's details.
191 * required:
192 * - title
193 * - sku
194 * - barcode
195 * - variant_id
196 * - unit_price
197 * - quantity
198 * - metadata
199 * properties:
200 * title:
201 * type: string
202 * title: title
203 * description: The item's title.
204 * sku:
205 * type: string
206 * title: sku
207 * description: The item's SKU.
208 * barcode:
209 * type: string
210 * title: barcode
211 * description: The item's barcode.
212 * variant_id:
213 * type: string
214 * title: variant_id
215 * description: The ID of the associated product variant.
216 * unit_price:
217 * oneOf:
218 * - type: string
219 * title: unit_price
220 * description: The item's unit price.
221 * - type: number
222 * title: unit_price
223 * description: The item's unit price.
224 * - type: object
225 * description: The item's unit price.
226 * required:
227 * - value
228 * - precision
229 * properties:
230 * value:
231 * type: string
232 * title: value
233 * description: The unit price's value.
234 * precision:
235 * type: number
236 * title: precision
237 * description: The unit price's rounding precision.
238 * quantity:
239 * type: number
240 * title: quantity
241 * description: The item's ordered quantity.
242 * metadata:
243 * type: object
244 * description: The item's metadata.
245 * region_id:
246 * type: string
247 * title: region_id
248 * description: The ID of the associated region.
249 * promo_codes:
250 * type: array
251 * description: The promotion codes applied on the draft order.
252 * items:
253 * type: string
254 * title: promo_codes
255 * description: A promotion code.
256 * currency_code:
257 * type: string
258 * title: currency_code
259 * description: The draft order's currency code.
260 * no_notification_order:
261 * type: boolean
262 * title: no_notification_order
263 * description: Whether to send the customer notifications on order changes.
264 * shipping_methods:
265 * type: array
266 * description: The draft order's shipping methods.
267 * items:
268 * type: object
269 * description: The shipping method's details.
270 * required:
271 * - name
272 * - option_id
273 * - amount
274 * properties:
275 * shipping_method_id:
276 * type: string
277 * title: shipping_method_id
278 * description: The ID of an existing shipping method.
279 * name:
280 * type: string
281 * title: name
282 * description: The shipping method's name.
283 * option_id:
284 * type: string
285 * title: option_id
286 * description: The ID of the shipping option this method is created from.
287 * data:
288 * type: object
289 * description: The shipping method's data, useful for fulfillment providers.
290 * externalDocs:
291 * url: https://docs.medusajs.com/resources/commerce-modules/order/concepts#data-property
292 * amount:
293 * oneOf:
294 * - type: string
295 * title: amount
296 * description: The shipping method's amount.
297 * - type: number
298 * title: amount
299 * description: The shipping method's amount.
300 * - type: object
301 * description: The shipping method's amount.
302 * required:
303 * - value
304 * - precision
305 * properties:
306 * value:
307 * type: string
308 * title: value
309 * description: The amount's value.
310 * precision:
311 * type: number
312 * title: precision
313 * description: The amount's rounding precision.
314 * metadata:
315 * type: object
316 * description: The draft order's metadata.
317 * - type: object
318 * description: The draft order's details.
319 * properties:
320 * additional_data:
321 * type: object
322 * description: Pass additional custom data to the API route. This data is passed to the underlying workflow under the `additional_data` parameter.
323 * description: The draft order's details.
324 * x-codeSamples:
325 * - lang: JavaScript
326 * label: JS SDK
327 * source: |-
328 * import Medusa from "@medusajs/js-sdk"
329 *
330 * export const sdk = new Medusa({
331 * baseUrl: import.meta.env.VITE_BACKEND_URL || "/",
332 * debug: import.meta.env.DEV,
333 * auth: {
334 * type: "session",
335 * },
336 * })
337 *
338 * sdk.admin.draftOrder.create({
339 * email: "test@test.com",
340 * items: [
341 * {
342 * variant_id: "variant_123",
343 * quantity: 1,
344 * },
345 * ],
346 * region_id: "region_123",
347 * sales_channel_id: "sc_123",
348 * })
349 * .then(({ draft_order }) => {
350 * console.log(draft_order)
351 * })
352 * - lang: Shell
353 * label: cURL
354 * source: |-
355 * curl -X POST '{backend_url}/admin/draft-orders' \
356 * -H 'Authorization: Bearer {jwt_token}' \
357 * -H 'Content-Type: application/json' \
358 * --data-raw '{
359 * "sales_channel_id": "{value}",
360 * "email": "Bartholome.Goodwin90@yahoo.com",
361 * "customer_id": "{value}",
362 * "region_id": "{value}",
363 * "currency_code": "{value}",
364 * "shipping_methods": [
365 * {
366 * "shipping_method_id": "{value}",
367 * "order_id": "{value}",
368 * "name": "Cheyanne",
369 * "option_id": "{value}"
370 * }
371 * ],
372 * "metadata": {}
373 * }'
374 * tags:
375 * - Draft Orders
376 * responses:
377 * "200":
378 * description: OK
379 * content:
380 * application/json:
381 * schema:
382 * $ref: "#/components/schemas/AdminDraftOrderResponse"
383 * "400":
384 * $ref: "#/components/responses/400_error"
385 * "401":
386 * $ref: "#/components/responses/unauthorized"
387 * "404":
388 * $ref: "#/components/responses/not_found_error"
389 * "409":
390 * $ref: "#/components/responses/invalid_state_error"
391 * "422":
392 * $ref: "#/components/responses/invalid_request_error"
393 * "500":
394 * $ref: "#/components/responses/500_error"
395 * x-workflow: createOrderWorkflow
396 * x-events: []
397 *
398 */
399