Raw
Large file — syntax highlighting disabled.
1 openapi: 3.0.0
2 info:
3 version: 2.17.2
4 title: Medusa Storefront API
5 license:
6 name: MIT
7 url: https://github.com/medusajs/medusa/blob/master/LICENSE
8 servers:
9 - url: http://localhost:9000
10 - url: https://api.medusajs.com
11 tags:
12 - name: Auth
13 description: |
14 Auth API routes allow you to manage a customer's authentication.
15 - name: Carts
16 description: |
17 A cart is a virtual shopping bag that customers can use to add items they want to purchase.
18
19 A cart is then used to checkout and place an order.
20
21 These API routes allow customers to create and manage their cart, and place an order.
22 externalDocs:
23 description: How to implement cart functionality in a storefront.
24 url: https://docs.medusajs.com/resources/storefront-development/cart
25 x-associatedSchema:
26 $ref: '#/components/schemas/StoreCart'
27 - name: Collections
28 description: |
29 A product collection organizes products into a collection for marketing purposes. For example, a summer collection.
30
31 These API routes allow customers to browse collections and their products.
32 externalDocs:
33 description: How to list product collections in a storefront.
34 url: https://docs.medusajs.com/resources/storefront-development/products/collections/list
35 x-associatedSchema:
36 $ref: '#/components/schemas/StoreCollection'
37 - name: Currencies
38 description: |
39 A store has multiple currencies, and product prices can be different for each currency.
40
41 When retrieving product variant prices, you specify either the ID of a region or a currency that the customer selected.
42
43 These API routes allow customers to browse currencies.
44 externalDocs:
45 description: How to retrieve product variant prices in a storefront.
46 url: https://docs.medusajs.com/resources/storefront-development/products/price
47 x-associatedSchema:
48 $ref: '#/components/schemas/StoreCurrency'
49 - name: Customers
50 description: |
51 Customers can place orders as guest customers or register.
52
53 When a customer registers, they can manage their profile, save addresses for later usage, and more.
54
55 These API routes allow customers to create and manage their accounts.
56 externalDocs:
57 description: How to implement customer account functionalities in a storefront.
58 url: https://docs.medusajs.com/resources/storefront-development/customers
59 x-associatedSchema:
60 $ref: '#/components/schemas/StoreCustomer'
61 - name: Gift Cards
62 description: |
63 A gift card is a prepaid card that customers can use to purchase products in the store.
64 Customers can purchase gift cards for themselves or others, and then use them to pay for their orders.
65 These API routes allow logged-in customers to create and manage their gift cards.
66 <Note>
67 Gift Cards are available through the [Loyalty Plugin](https://docs.medusajs.com/resources/commerce-modules/loyalty).
68 </Note>
69 x-associatedSchema:
70 $ref: '#/components/schemas/StoreGiftCard'
71 - name: Locales
72 description: |
73 A locale is a language that content is translated into for customers to view in a storefront.
74 Medusa installs locales by default. These API routes allow you to retrieve supported locales in the store.
75 externalDocs:
76 description: Learn more about locales and translations.
77 url: https://docs.medusajs.com/resources/commerce-modules/translation/concepts
78 x-associatedSchema:
79 $ref: '#/components/schemas/StoreLocale'
80 - name: Multi-Factor Authentication (MFA) Factors
81 description: |
82 Multi-factor authentication (MFA) factors are additional ways to verify a customer's identity during login, in addition to their password. Examples of MFA factors include authenticator apps, SMS messages, and email.
83 These API routes allow customers to manage their MFA factors, such as enabling an authenticator app or generating recovery codes.
84 externalDocs:
85 description: Learn more about MFA in Medusa
86 url: https://docs.medusajs.com/resources/commerce-modules/auth/mfa
87 - name: Orders
88 description: |
89 Guest and registered customers can view orders they placed.
90
91 These API routes allow customers to view their orders.
92 x-associatedSchema:
93 $ref: '#/components/schemas/StoreOrder'
94 - name: Payment Collections
95 description: |
96 A cart must have a payment collection with an authorized payment session.
97
98 Use these API routes during checkout to set the cart's payment provider and authorize its payment session.
99 externalDocs:
100 description: How to implement payment during checkout.
101 url: https://docs.medusajs.com/resources/storefront-development/checkout/payment
102 x-associatedSchema:
103 $ref: '#/components/schemas/StorePaymentCollection'
104 - name: Payment Providers
105 description: |
106 Each region has a set of payment providers enabled.
107
108 During checkout, you retrieve the available payment providers in the customer's region to show them to the customer. Customers then choose their preferred provider to authorize their payment and place their order.
109
110 These API routes allow customers to view available payment providers in their region.
111 externalDocs:
112 description: How to implement payment during checkout.
113 url: https://docs.medusajs.com/resources/storefront-development/checkout/payment
114 x-associatedSchema:
115 $ref: '#/components/schemas/StorePaymentProvider'
116 - name: Product Categories
117 description: |
118 Products can be categorized into categories.
119
120 These API routes allow customers to browse categories and their products.
121 externalDocs:
122 description: How to list product categories in a storefront.
123 url: https://docs.medusajs.com/resources/storefront-development/products/categories/list
124 x-associatedSchema:
125 $ref: '#/components/schemas/StoreProductCategory'
126 - name: Product Options
127 x-associatedSchema:
128 $ref: '#/components/schemas/StoreProductOption'
129 description: |
130 A product option is a way to define different options for a product, such as "Size" or "Color". Product options can be created globally and used by multiple products, or they can be exclusive to a specific product.
131 These API routes allow customers to view product options.
132 externalDocs:
133 description: Use Product Options in a Storefront
134 url: https://docs.medusajs.com/resources/storefront-development/products/options
135 - name: Product Tags
136 x-associatedSchema:
137 $ref: '#/components/schemas/StoreProductTag'
138 - name: Product Types
139 x-associatedSchema:
140 $ref: '#/components/schemas/StoreProductType'
141 - name: Product Variants
142 x-associatedSchema:
143 $ref: '#/components/schemas/StoreProductVariant'
144 - name: Products
145 description: |
146 Customers browse products for their purchase.
147
148 A product has variants for different option values. The customer chooses from these variants before adding it to the cart.
149
150 These API routes allow customers to browse products.
151 externalDocs:
152 description: How to list products, get their prices, and more in a storefront.
153 url: https://docs.medusajs.com/resources/storefront-development/products
154 x-associatedSchema:
155 $ref: '#/components/schemas/StoreProduct'
156 - name: Regions
157 description: |
158 Regions are different countries or geographical regions that the commerce store serves customers in.
159
160 Customers can choose what region they're in to view prices of that region's currency.
161
162 Use these API routes to retrieve available regions in the store.
163 externalDocs:
164 description: How to retrieve and store selected region in a storefront.
165 url: https://docs.medusajs.com/resources/storefront-development/regions
166 x-associatedSchema:
167 $ref: '#/components/schemas/StoreRegion'
168 - name: Return Reasons
169 description: |
170 A return reason is a possible reason a customer wants to return an item.
171
172 Use these API routes when implementing return creation flow in your storefront to allow customers to select their return reason.
173 x-associatedSchema:
174 $ref: '#/components/schemas/StoreReturnReason'
175 - name: Returns
176 description: |
177 Customers can request to return items in their order. The admin user then receives and handles the return.
178
179 These API routes allows customers to create a return.
180 x-associatedSchema:
181 $ref: '#/components/schemas/StoreReturn'
182 - name: Shipping Options
183 description: |
184 A shipping option is a way of shipping an item to or from the customer.
185
186 During the checkout flow, the customer selects their preferred shipping option to receive their order.
187
188 These API routes allow customers to retrieve available shipping options for their context.
189 externalDocs:
190 description: How to implement shipping during checkout.
191 url: https://docs.medusajs.com/resources/storefront-development/checkout/shipping
192 x-associatedSchema:
193 $ref: '#/components/schemas/StoreShippingOption'
194 - name: Store Credit Accounts
195 x-associatedSchema:
196 description: |
197 A store credit account is a way for customers to manage their store credit balance. Customers can use their store credit to pay for orders, and view their store credit balance.
198 These API routes allow customers to view their store credit accounts.
199 <Note>
200 Store Credit Accounts are only available through the [Loyalty Plugin](https://docs.medusajs.com/resources/commerce-modules/loyalty).
201 </Note>
202 $ref: '#/components/schemas/StoreStoreCreditAccount'
203 paths:
204 /auth/customer/emailpass/verification/confirm:
205 post:
206 operationId: PostActor_typeAuth_providerVerificationConfirm
207 summary: Verify the Customer's Email
208 description: Verifies the customer's email using a token that is typically sent to their email address. This is used to confirm the customer's email during registration or authentication when [email verification is required](https://docs.medusajs.com/resources/commerce-modules/auth/auth-providers/emailpass). You can listen to the `auth.verification_requested` event in a subscriber and send an email to the customer with the verification token.
209 x-authenticated: false
210 requestBody:
211 content:
212 application/json:
213 schema:
214 type: object
215 description: The details required to verify the customer's email.
216 required:
217 - token
218 properties:
219 token:
220 type: string
221 title: token
222 description: The verification token sent to the customer's email address.
223 x-codeSamples:
224 - lang: Shell
225 label: cURL
226 source: |-
227 curl -X POST '{backend_url}/auth/customer/emailpass/verification/confirm' \
228 -H 'Content-Type: application/json' \
229 --data-raw '{
230 "token": "{value}"
231 }'
232 tags:
233 - Auth
234 responses:
235 '200':
236 description: OK
237 '400':
238 $ref: '#/components/responses/400_error'
239 '401':
240 $ref: '#/components/responses/unauthorized'
241 '404':
242 $ref: '#/components/responses/not_found_error'
243 '409':
244 $ref: '#/components/responses/invalid_state_error'
245 '422':
246 $ref: '#/components/responses/invalid_request_error'
247 '500':
248 $ref: '#/components/responses/500_error'
249 /auth/customer/{auth_provider}:
250 post:
251 operationId: PostActor_typeAuth_provider
252 summary: Authenticate Customer
253 description: |
254 Authenticate a customer and receive the JWT token to be used in the header of subsequent requests.
255
256 When used with a third-party provider, such as Google, the request returns a `location` property. You redirect to the specified URL in your storefront to continue authentication with the third-party service.
257 externalDocs:
258 url: https://docs.medusajs.com/resources/storefront-development/customers/login#1-using-a-jwt-token
259 description: 'Storefront development: How to login as a customer'
260 x-authenticated: false
261 parameters:
262 - name: auth_provider
263 in: path
264 description: The provider used for authentication.
265 required: true
266 schema:
267 type: string
268 example: emailpass
269 requestBody:
270 content:
271 application/json:
272 schema:
273 type: object
274 title: input
275 description: |
276 The input data necessary for authentication.
277 For example, for email-pass authentication, pass `email` and `password` properties.
278 For the Google and GitHub authentication providers, you can pass `callback_url` to indicate the URL in the frontend that the customer should be redirected to after completing their authentication. This will override the provider's `callbackUrl` configurations in `medusa-config.ts`.
279 x-codeSamples:
280 - lang: JavaScript
281 label: JS SDK
282 source: |-
283 import Medusa from "@medusajs/js-sdk"
284
285 let MEDUSA_BACKEND_URL = "http://localhost:9000"
286
287 if (process.env.NEXT_PUBLIC_MEDUSA_BACKEND_URL) {
288 MEDUSA_BACKEND_URL = process.env.NEXT_PUBLIC_MEDUSA_BACKEND_URL
289 }
290
291 export const sdk = new Medusa({
292 baseUrl: MEDUSA_BACKEND_URL,
293 debug: process.env.NODE_ENV === "development",
294 publishableKey: process.env.NEXT_PUBLIC_MEDUSA_PUBLISHABLE_KEY,
295 })
296
297 const result = await sdk.auth.login(
298 "customer",
299 "emailpass",
300 {
301 email: "customer@gmail.com",
302 password: "supersecret"
303 }
304 )
305
306 if (typeof result !== "string") {
307 alert("Authentication requires additional steps")
308 // replace with the redirect logic of your application
309 window.location.href = result.location
310 return
311 }
312
313 // customer is now authenticated
314 // all subsequent requests will use the token in the header
315 const { customer } = await sdk.store.customer.retrieve()
316 - lang: Bash
317 label: Google Provider
318 source: curl -X POST '{backend_url}/auth/customer/google'
319 tags:
320 - Auth
321 responses:
322 '200':
323 description: OK
324 content:
325 application/json:
326 schema:
327 oneOf:
328 - $ref: '#/components/schemas/AuthResponse'
329 - $ref: '#/components/schemas/AuthCallbackResponse'
330 '400':
331 $ref: '#/components/responses/400_error'
332 '401':
333 $ref: '#/components/responses/unauthorized'
334 '404':
335 $ref: '#/components/responses/not_found_error'
336 '409':
337 $ref: '#/components/responses/invalid_state_error'
338 '422':
339 $ref: '#/components/responses/invalid_request_error'
340 '500':
341 $ref: '#/components/responses/500_error'
342 /auth/customer/{auth_provider}/callback:
343 post:
344 operationId: PostActor_typeAuth_providerCallback
345 summary: Validate Authentication Callback
346 description: |
347 This API route is used by your storefront or frontend application when a third-party provider redirects to it after authentication. It validates the authentication with the third-party provider and, if successful, returns an authentication token. All query parameters received from the third-party provider, such as `code`, `state`, and `error`, must be passed as query parameters to this route.
348 You can decode the JWT token using libraries like [react-jwt](https://www.npmjs.com/package/react-jwt) in the storefront. If the decoded data doesn't have an `actor_id` property, then you must register the customer using the Create Customer API route passing the token in the request's Authorization header.
349 externalDocs:
350 url: https://docs.medusajs.com/resources/storefront-development/customers/third-party-login
351 description: 'Storefront development: Implement third-party (social) login.'
352 x-authenticated: false
353 parameters:
354 - name: auth_provider
355 in: path
356 description: The provider used for authentication.
357 required: true
358 schema:
359 type: string
360 example: google
361 x-codeSamples:
362 - lang: JavaScript
363 label: Google Provider
364 source: |-
365 import Medusa from "@medusajs/js-sdk"
366 import { decodeToken } from "react-jwt"
367
368 let MEDUSA_BACKEND_URL = "http://localhost:9000"
369
370 if (process.env.NEXT_PUBLIC_MEDUSA_BACKEND_URL) {
371 MEDUSA_BACKEND_URL = process.env.NEXT_PUBLIC_MEDUSA_BACKEND_URL
372 }
373
374 export const sdk = new Medusa({
375 baseUrl: MEDUSA_BACKEND_URL,
376 debug: process.env.NODE_ENV === "development",
377 publishableKey: process.env.NEXT_PUBLIC_MEDUSA_PUBLISHABLE_KEY,
378 })
379
380 const token = await sdk.auth.callback(
381 "customer",
382 "google",
383 {
384 code: "123",
385 state: "456"
386 }
387 )
388 // all subsequent requests will use the token in the header
389
390 const decodedToken = decodeToken(token) as { actor_id: string, user_metadata: Record<string, unknown> }
391
392 const shouldCreateCustomer = decodedToken.actor_id === ""
393
394 if (shouldCreateCustomer) {
395 const { customer } = await sdk.store.customer.create({
396 email: decodedToken.user_metadata.email as string,
397 })
398
399 // refresh auth token
400 await sdk.auth.refresh()
401 // all subsequent requests will use the new token in the header
402 } else {
403 // Customer already exists and is authenticated
404 }
405 - lang: TypeScript
406 label: GitHub Provider
407 source: |-
408 import Medusa from "@medusajs/js-sdk"
409 import { decodeToken } from "react-jwt"
410
411 let MEDUSA_BACKEND_URL = "http://localhost:9000"
412
413 if (process.env.NEXT_PUBLIC_MEDUSA_BACKEND_URL) {
414 MEDUSA_BACKEND_URL = process.env.NEXT_PUBLIC_MEDUSA_BACKEND_URL
415 }
416
417 export const sdk = new Medusa({
418 baseUrl: MEDUSA_BACKEND_URL,
419 debug: process.env.NODE_ENV === "development",
420 publishableKey: process.env.NEXT_PUBLIC_MEDUSA_PUBLISHABLE_KEY,
421 })
422
423 const token = await sdk.auth.callback(
424 "customer",
425 "github",
426 {
427 code: "123",
428 state: "456"
429 }
430 )
431 // all subsequent requests will use the token in the header
432
433 const decodedToken = decodeToken(token) as { actor_id: string, user_metadata: Record<string, unknown> }
434
435 const shouldCreateCustomer = decodedToken.actor_id === ""
436
437 if (shouldCreateCustomer) {
438 const { customer } = await sdk.store.customer.create({
439 email: decodedToken.user_metadata.email as string,
440 })
441
442 // refresh auth token
443 await sdk.auth.refresh()
444 // all subsequent requests will use the new token in the header
445 } else {
446 // Customer already exists and is authenticated
447 }
448 tags:
449 - Auth
450 responses:
451 '200':
452 description: OK
453 content:
454 application/json:
455 schema:
456 $ref: '#/components/schemas/AuthResponse'
457 '400':
458 $ref: '#/components/responses/400_error'
459 '401':
460 $ref: '#/components/responses/unauthorized'
461 '404':
462 $ref: '#/components/responses/not_found_error'
463 '409':
464 $ref: '#/components/responses/invalid_state_error'
465 '422':
466 $ref: '#/components/responses/invalid_request_error'
467 '500':
468 $ref: '#/components/responses/500_error'
469 /auth/customer/{auth_provider}/register:
470 post:
471 operationId: PostActor_typeAuth_provider_register
472 summary: Retrieve Registration JWT Token
473 description: This API route retrieves a registration JWT token of a customer that hasn't been registered yet. The token is used in the header of requests that create a customer.
474 externalDocs:
475 url: https://docs.medusajs.com/resources/storefront-development/customers/register
476 description: 'Storefront development: How to register a customer'
477 x-authenticated: false
478 parameters:
479 - name: auth_provider
480 in: path
481 description: The provider used for authentication.
482 required: true
483 schema:
484 type: string
485 example: emailpass
486 requestBody:
487 content:
488 application/json:
489 schema:
490 type: object
491 title: input
492 description: The input data necessary for authentication. For example, for email-pass authentication, pass `email` and `password` properties.
493 example:
494 email: customer@gmail.com
495 password: supersecret
496 x-codeSamples:
497 - lang: JavaScript
498 label: JS SDK
499 source: |-
500 import Medusa from "@medusajs/js-sdk"
501
502 let MEDUSA_BACKEND_URL = "http://localhost:9000"
503
504 if (process.env.NEXT_PUBLIC_MEDUSA_BACKEND_URL) {
505 MEDUSA_BACKEND_URL = process.env.NEXT_PUBLIC_MEDUSA_BACKEND_URL
506 }
507
508 export const sdk = new Medusa({
509 baseUrl: MEDUSA_BACKEND_URL,
510 debug: process.env.NODE_ENV === "development",
511 publishableKey: process.env.NEXT_PUBLIC_MEDUSA_PUBLISHABLE_KEY,
512 })
513
514 await sdk.auth.register(
515 "customer",
516 "emailpass",
517 {
518 email: "customer@gmail.com",
519 password: "supersecret"
520 }
521 )
522
523 // all subsequent requests will use the token in the header
524 const { customer } = await sdk.store.customer.create({
525 email: "customer@gmail.com",
526 password: "supersecret"
527 })
528 - lang: Shell
529 label: cURL
530 source: |-
531 curl -X POST '{backend_url}/auth/customer/emailpass/register' \
532 -H 'Content-Type: application/json' \
533 --data-raw '{
534 "email": "customer@gmail.com",
535 "password": "supersecret"
536 }'
537 tags:
538 - Auth
539 responses:
540 '200':
541 description: OK
542 content:
543 application/json:
544 schema:
545 $ref: '#/components/schemas/AuthResponse'
546 '400':
547 $ref: '#/components/responses/400_error'
548 '401':
549 $ref: '#/components/responses/unauthorized'
550 '404':
551 $ref: '#/components/responses/not_found_error'
552 '409':
553 $ref: '#/components/responses/invalid_state_error'
554 '422':
555 $ref: '#/components/responses/invalid_request_error'
556 '500':
557 $ref: '#/components/responses/500_error'
558 /auth/customer/{auth_provider}/reset-password:
559 post:
560 operationId: PostActor_typeAuth_providerResetPassword
561 summary: Generate Reset Password Token for Customer
562 x-sidebar-summary: Generate Reset Password Token
563 description: |
564 Generate a reset password token for a customer. This API route doesn't reset the customer password or send them the reset instructions in a notification.
565
566 Instead, This API route emits the `auth.password_reset` event, passing it the token as a payload. You can listen to that event in a subscriber as explained in [this guide](https://docs.medusajs.com/resources/commerce-modules/auth/reset-password), then send the customer a notification. The notification is sent using a [Notification Module Provider](https://docs.medusajs.com/resources/infrastructure-modules/notification), and it should have a URL that accepts a `token` query parameter, allowing the customer to reset their password from the storefront.
567
568
569 Use the generated token to update the customer's password using the [Reset Password API route](https://docs.medusajs.com/api/store#auth_postactor_typeauth_providerupdate).
570 externalDocs:
571 url: https://docs.medusajs.com/resources/storefront-development/customers/reset-password#1-request-reset-password-page
572 description: 'Storefront development: How to create the request reset password page.'
573 x-authenticated: false
574 parameters:
575 - name: auth_provider
576 in: path
577 description: The provider used for authentication.
578 required: true
579 schema:
580 type: string
581 example: emailpass
582 requestBody:
583 content:
584 application/json:
585 schema:
586 type: object
587 description: The input data necessary to generate a reset password token.
588 required:
589 - identifier
590 properties:
591 identifier:
592 type: string
593 description: The customer's identifier for the selected auth provider. For example, for the `emailpass` auth provider, the value is the customer's email.
594 example: customer@gmail.com
595 metadata:
596 type: object
597 description: Optional metadata to include with the reset password token generation request.
598 x-codeSamples:
599 - lang: JavaScript
600 label: JS SDK
601 source: |-
602 import Medusa from "@medusajs/js-sdk"
603
604 let MEDUSA_BACKEND_URL = "http://localhost:9000"
605
606 if (process.env.NEXT_PUBLIC_MEDUSA_BACKEND_URL) {
607 MEDUSA_BACKEND_URL = process.env.NEXT_PUBLIC_MEDUSA_BACKEND_URL
608 }
609
610 export const sdk = new Medusa({
611 baseUrl: MEDUSA_BACKEND_URL,
612 debug: process.env.NODE_ENV === "development",
613 publishableKey: process.env.NEXT_PUBLIC_MEDUSA_PUBLISHABLE_KEY,
614 })
615
616 sdk.auth.resetPassword(
617 "customer",
618 "emailpass",
619 {
620 identifier: "customer@gmail.com"
621 }
622 )
623 .then(() => {
624 // user receives token
625 })
626 - lang: Shell
627 label: cURL
628 source: |-
629 curl -X POST '{backend_url}/auth/customer/emailpass/reset-password' \
630 -H 'Content-Type: application/json' \
631 --data-raw '{
632 "identifier": "customer@gmail.com"
633 }'
634 tags:
635 - Auth
636 responses:
637 '201':
638 description: OK
639 '400':
640 $ref: '#/components/responses/400_error'
641 '401':
642 $ref: '#/components/responses/unauthorized'
643 '404':
644 $ref: '#/components/responses/not_found_error'
645 '409':
646 $ref: '#/components/responses/invalid_state_error'
647 '422':
648 $ref: '#/components/responses/invalid_request_error'
649 '500':
650 $ref: '#/components/responses/500_error'
651 x-workflow: generateResetPasswordTokenWorkflow
652 x-events:
653 - name: auth.password_reset
654 payload: |-
655 ```ts
656 {
657 entity_id, // The identifier of the user or customer. For example, an email address.
658 actor_type, // The type of actor. For example, "customer", "user", or custom.
659 token, // The generated token.
660 metadata, // Optional custom metadata passed from the request.
661 }
662 ```
663 description: |-
664 Emitted when a reset password token is generated. You can listen to this event
665 to send a reset password email to the user or customer, for example.
666 deprecated: false
667 /auth/customer/{auth_provider}/update:
668 post:
669 operationId: PostActor_typeAuth_providerUpdate
670 summary: Reset a Customer's Password
671 x-sidebar-summary: Reset Password
672 description: Reset a customer's password using a reset-password token generated with the [Generate Reset Password Token API route](https://docs.medusajs.com/api/store#auth_postactor_typeauth_providerresetpassword). You pass the token as a bearer token in the request's Authorization header.
673 externalDocs:
674 url: https://docs.medusajs.com/resources/storefront-development/customers/reset-password#2-reset-password-page
675 description: 'Storefront development: How to create the reset password page.'
676 x-authenticated: true
677 parameters:
678 - name: auth_provider
679 in: path
680 description: The provider used for authentication.
681 required: true
682 schema:
683 type: string
684 example: emailpass
685 requestBody:
686 content:
687 application/json:
688 schema:
689 type: object
690 title: input
691 description: The input data necessary for authentication with the specified auth provider. For example, for email-pass authentication, pass `email` and `password` properties.
692 example:
693 email: customer@gmail.com
694 password: supersecret
695 x-codeSamples:
696 - lang: JavaScript
697 label: JS SDK
698 source: |-
699 import Medusa from "@medusajs/js-sdk"
700
701 let MEDUSA_BACKEND_URL = "http://localhost:9000"
702
703 if (process.env.NEXT_PUBLIC_MEDUSA_BACKEND_URL) {
704 MEDUSA_BACKEND_URL = process.env.NEXT_PUBLIC_MEDUSA_BACKEND_URL
705 }
706
707 export const sdk = new Medusa({
708 baseUrl: MEDUSA_BACKEND_URL,
709 debug: process.env.NODE_ENV === "development",
710 publishableKey: process.env.NEXT_PUBLIC_MEDUSA_PUBLISHABLE_KEY,
711 })
712
713 sdk.auth.updateProvider(
714 "customer",
715 "emailpass",
716 {
717 password: "supersecret"
718 },
719 token
720 )
721 .then(() => {
722 // password updated
723 })
724 - lang: Shell
725 label: cURL
726 source: |-
727 curl -X POST '{backend_url}/auth/customer/emailpass/update' \
728 -H 'Content-Type: application/json' \
729 -H 'Authorization: Bearer {token}' \
730 --data-raw '{
731 "email": "customer@gmail.com",
732 "password": "supersecret"
733 }'
734 security:
735 - reset_password: []
736 tags:
737 - Auth
738 responses:
739 '200':
740 description: OK
741 content:
742 application/json:
743 schema:
744 type: object
745 required:
746 - success
747 description: Details on the reset password's status.
748 properties:
749 success:
750 type: boolean
751 title: success
752 description: Whether the password was reset successfully.
753 '400':
754 $ref: '#/components/responses/400_error'
755 '401':
756 $ref: '#/components/responses/unauthorized'
757 '404':
758 $ref: '#/components/responses/not_found_error'
759 '409':
760 $ref: '#/components/responses/invalid_state_error'
761 '422':
762 $ref: '#/components/responses/invalid_request_error'
763 '500':
764 $ref: '#/components/responses/500_error'
765 /auth/mfa/challenges/{id}/verify:
766 post:
767 operationId: PostMfaChallengesIdVerify
768 summary: Verify a Multi-Factor Authentication (MFA) Challenge
769 x-sidebar-summary: Verify MFA Challenge
770 description: |
771 Verify a multi-factor authentication (MFA) challenge issued during login. On success, this
772 completes the authentication flow and returns a JWT token that can be used to authenticate
773 subsequent requests.
774 x-authenticated: false
775 externalDocs:
776 description: Learn more about MFA in Medusa
777 url: https://docs.medusajs.com/resources/commerce-modules/auth/mfa
778 parameters:
779 - name: id
780 in: path
781 description: The MFA challenge's ID.
782 required: true
783 schema:
784 type: string
785 requestBody:
786 content:
787 application/json:
788 schema:
789 type: object
790 description: The details required to verify the MFA challenge.
791 required:
792 - method
793 - code
794 properties:
795 method:
796 type: string
797 title: method
798 description: The MFA method used to verify the challenge (for example, `totp` or `recovery-code`).
799 code:
800 type: string
801 title: code
802 description: The verification code generated by the chosen MFA method.
803 x-codeSamples:
804 - lang: JavaScript
805 label: JS SDK
806 source: |-
807 import Medusa from "@medusajs/js-sdk"
808
809 export const sdk = new Medusa({
810 baseUrl: import.meta.env.VITE_BACKEND_URL || "/",
811 debug: import.meta.env.DEV,
812 auth: {
813 type: "session",
814 },
815 })
816
817 const result = await sdk.auth.login("user", "emailpass", {
818 email: "user@example.com",
819 password: "secret"
820 })
821
822 if (typeof result === "object" && "mfa_challenge" in result) {
823 await sdk.auth.mfa.verifyChallenge(result.mfa_challenge.id, {
824 method: "totp",
825 code: "123456"
826 })
827 }
828 - lang: Shell
829 label: cURL
830 source: |-
831 curl -X POST '{backend_url}/auth/mfa/challenges/{id}/verify' \
832 -H 'Content-Type: application/json' \
833 --data-raw '{
834 "method": "{value}",
835 "code": "{value}"
836 }'
837 tags:
838 - Multi-Factor Authentication (MFA) Factors
839 responses:
840 '200':
841 description: OK
842 '400':
843 $ref: '#/components/responses/400_error'
844 '401':
845 $ref: '#/components/responses/unauthorized'
846 '404':
847 $ref: '#/components/responses/not_found_error'
848 '409':
849 $ref: '#/components/responses/invalid_state_error'
850 '422':
851 $ref: '#/components/responses/invalid_request_error'
852 '500':
853 $ref: '#/components/responses/500_error'
854 x-since: 2.15.3
855 /auth/mfa/factors:
856 get:
857 operationId: GetMfaFactors
858 summary: List Multifactor Authentication (MFA) Factors
859 x-sidebar-summary: List MFA Factors
860 description: |
861 Retrieve the list of multi-factor authentication (MFA) factors registered for the authenticated user,
862 including both pending (not yet verified) and enabled factors.
863 x-authenticated: true
864 parameters: []
865 x-codeSamples:
866 - lang: JavaScript
867 label: JS SDK
868 source: |-
869 import Medusa from "@medusajs/js-sdk"
870
871 export const sdk = new Medusa({
872 baseUrl: import.meta.env.VITE_BACKEND_URL || "/",
873 debug: import.meta.env.DEV,
874 auth: {
875 type: "session",
876 },
877 })
878
879 const { mfa_factors } = await sdk.auth.mfa.list()
880 - lang: Shell
881 label: cURL
882 source: curl '{backend_url}/auth/mfa/factors'
883 tags:
884 - Multi-Factor Authentication (MFA) Factors
885 responses:
886 '200':
887 description: OK
888 '400':
889 $ref: '#/components/responses/400_error'
890 '401':
891 $ref: '#/components/responses/unauthorized'
892 '404':
893 $ref: '#/components/responses/not_found_error'
894 '409':
895 $ref: '#/components/responses/invalid_state_error'
896 '422':
897 $ref: '#/components/responses/invalid_request_error'
898 '500':
899 $ref: '#/components/responses/500_error'
900 x-since: 2.15.3
901 post:
902 operationId: PostMfaFactors
903 summary: Start Multi-Factor Authentication (MFA) Factor Enrollment
904 x-sidebar-summary: Start MFA Factor Enrollment
905 description: |
906 Start the enrollment of a new multi-factor authentication (MFA) factor for the authenticated
907 user. The response contains the factor along with provider-specific setup data (such as a
908 secret and an `otpauth_url` for TOTP) that can be used to display a QR code. The factor must
909 then be verified via the verify endpoint before it can be used.
910 x-authenticated: true
911 externalDocs:
912 description: Learn more about MFA in Medusa
913 url: https://docs.medusajs.com/resources/commerce-modules/auth/mfa
914 parameters: []
915 requestBody:
916 content:
917 application/json:
918 schema:
919 type: object
920 description: The details of the MFA factor to enroll.
921 required:
922 - provider
923 properties:
924 provider:
925 type: string
926 title: provider
927 description: The ID of the MFA provider to enroll the factor with (for example, `totp`).
928 label:
929 type: string
930 title: label
931 description: A human-readable label to identify the factor (for example, the name of the authenticator app or device).
932 issuer:
933 type: string
934 title: issuer
935 description: The issuer name shown in authenticator apps for this factor. Defaults to the application name when omitted.
936 metadata:
937 type: object
938 description: Additional provider-specific data to associate with the factor.
939 x-codeSamples:
940 - lang: JavaScript
941 label: JS SDK
942 source: |-
943 import Medusa from "@medusajs/js-sdk"
944
945 export const sdk = new Medusa({
946 baseUrl: import.meta.env.VITE_BACKEND_URL || "/",
947 debug: import.meta.env.DEV,
948 auth: {
949 type: "session",
950 },
951 })
952
953 const setup = await sdk.auth.mfa.start({
954 provider: "totp",
955 label: "Authenticator app"
956 })
957
958 // Render setup.otpauth_url as a QR code or show setup.secret manually.
959 - lang: Shell
960 label: cURL
961 source: |-
962 curl -X POST '{backend_url}/auth/mfa/factors' \
963 -H 'Content-Type: application/json' \
964 --data-raw '{
965 "provider": "{value}"
966 }'
967 tags:
968 - Multi-Factor Authentication (MFA) Factors
969 responses:
970 '200':
971 description: OK
972 '400':
973 $ref: '#/components/responses/400_error'
974 '401':
975 $ref: '#/components/responses/unauthorized'
976 '404':
977 $ref: '#/components/responses/not_found_error'
978 '409':
979 $ref: '#/components/responses/invalid_state_error'
980 '422':
981 $ref: '#/components/responses/invalid_request_error'
982 '500':
983 $ref: '#/components/responses/500_error'
984 x-since: 2.15.3
985 /auth/mfa/factors/{id}:
986 delete:
987 operationId: DeleteMfaFactorsId
988 summary: Disable a Multi-Factor Authentication (MFA) Factor
989 x-sidebar-summary: Disable MFA Factor
990 description: |
991 Disable a multi-factor authentication (MFA) factor for the authenticated user. Once disabled,
992 the factor can no longer be used to verify MFA challenges. When disabling a recovery-code
993 factor, a valid recovery code must be provided in the request body.
994 x-authenticated: true
995 parameters:
996 - name: id
997 in: path
998 description: The MFA factor's ID.
999 required: true
1000 schema:
1001 type: string
1002 requestBody:
1003 content:
1004 application/json:
1005 schema:
1006 type: object
1007 description: The details required to disable the MFA factor.
1008 properties:
1009 method:
1010 type: string
1011 title: method
1012 description: The MFA method used to authorize disabling the factor (for example, `recovery-code`).
1013 code:
1014 type: string
1015 title: code
1016 description: The verification code associated with the provided `method`, used to confirm the disable action.
1017 x-codeSamples:
1018 - lang: JavaScript
1019 label: JS SDK
1020 source: |-
1021 import Medusa from "@medusajs/js-sdk"
1022
1023 export const sdk = new Medusa({
1024 baseUrl: import.meta.env.VITE_BACKEND_URL || "/",
1025 debug: import.meta.env.DEV,
1026 auth: {
1027 type: "session",
1028 },
1029 })
1030
1031 const { mfa_factor } = await sdk.auth.mfa.disable("authmfa_123")
1032 - lang: Shell
1033 label: cURL
1034 source: curl -X DELETE '{backend_url}/auth/mfa/factors/{id}'
1035 tags:
1036 - Multi-Factor Authentication (MFA) Factors
1037 responses:
1038 '200':
1039 description: OK
1040 '400':
1041 $ref: '#/components/responses/400_error'
1042 '401':
1043 $ref: '#/components/responses/unauthorized'
1044 '404':
1045 $ref: '#/components/responses/not_found_error'
1046 '409':
1047 $ref: '#/components/responses/invalid_state_error'
1048 '422':
1049 $ref: '#/components/responses/invalid_request_error'
1050 '500':
1051 $ref: '#/components/responses/500_error'
1052 x-since: 2.15.3
1053 /auth/mfa/factors/{id}/verify:
1054 post:
1055 operationId: PostMfaFactorsIdVerify
1056 summary: Verify and Enable a Multi-Factor Authentication (MFA) Factor
1057 x-sidebar-summary: Verify and Enable MFA Factor
1058 description: |
1059 Verify a pending multi-factor authentication (MFA) factor by submitting a code generated from
1060 it. A successful verification enables the factor, after which it can be used to verify MFA
1061 challenges during login.
1062 x-authenticated: true
1063 externalDocs:
1064 description: Learn more about MFA in Medusa
1065 url: https://docs.medusajs.com/resources/commerce-modules/auth/mfa
1066 parameters:
1067 - name: id
1068 in: path
1069 description: The MFA factor's ID.
1070 required: true
1071 schema:
1072 type: string
1073 requestBody:
1074 content:
1075 application/json:
1076 schema:
1077 type: object
1078 description: The details required to verify and enable the MFA factor.
1079 required:
1080 - code
1081 properties:
1082 code:
1083 type: string
1084 title: code
1085 description: The verification code generated by the MFA factor (for example, the current TOTP code from the authenticator app).
1086 x-codeSamples:
1087 - lang: JavaScript
1088 label: JS SDK
1089 source: |-
1090 import Medusa from "@medusajs/js-sdk"
1091
1092 export const sdk = new Medusa({
1093 baseUrl: import.meta.env.VITE_BACKEND_URL || "/",
1094 debug: import.meta.env.DEV,
1095 auth: {
1096 type: "session",
1097 },
1098 })
1099
1100 const { mfa_factor } = await sdk.auth.mfa.verify("authmfa_123", {
1101 code: "123456"
1102 })
1103 - lang: Shell
1104 label: cURL
1105 source: |-
1106 curl -X POST '{backend_url}/auth/mfa/factors/{id}/verify' \
1107 -H 'Content-Type: application/json' \
1108 --data-raw '{
1109 "code": "{value}"
1110 }'
1111 tags:
1112 - Multi-Factor Authentication (MFA) Factors
1113 responses:
1114 '200':
1115 description: OK
1116 '400':
1117 $ref: '#/components/responses/400_error'
1118 '401':
1119 $ref: '#/components/responses/unauthorized'
1120 '404':
1121 $ref: '#/components/responses/not_found_error'
1122 '409':
1123 $ref: '#/components/responses/invalid_state_error'
1124 '422':
1125 $ref: '#/components/responses/invalid_request_error'
1126 '500':
1127 $ref: '#/components/responses/500_error'
1128 x-since: 2.15.3
1129 /auth/mfa/recovery-codes:
1130 post:
1131 operationId: PostMfaRecoveryCodes
1132 summary: Generate Multi-Factor Authentication (MFA) Recovery Codes
1133 x-sidebar-summary: Generate MFA Recovery Codes
1134 description: |
1135 Generate a new set of single-use recovery codes for the authenticated user. Recovery codes can
1136 be used to verify MFA challenges when the user does not have access to their primary MFA
1137 factor. Generating new codes replaces any previously issued codes, so they should be stored in
1138 a safe place. At least one enabled MFA factor is required to generate recovery codes.
1139 x-authenticated: true
1140 externalDocs:
1141 description: Learn more about MFA in Medusa
1142 url: https://docs.medusajs.com/resources/commerce-modules/auth/mfa
1143 parameters: []
1144 requestBody:
1145 content:
1146 application/json:
1147 schema:
1148 type: object
1149 description: The options to use when generating recovery codes.
1150 properties:
1151 count:
1152 type: number
1153 title: count
1154 description: The number of recovery codes to generate. Must be between 1 and 50. Defaults to the provider's configured value when omitted.
1155 x-codeSamples:
1156 - lang: JavaScript
1157 label: JS SDK
1158 source: |-
1159 import Medusa from "@medusajs/js-sdk"
1160
1161 export const sdk = new Medusa({
1162 baseUrl: import.meta.env.VITE_BACKEND_URL || "/",
1163 debug: import.meta.env.DEV,
1164 auth: {
1165 type: "session",
1166 },
1167 })
1168
1169 const { recovery_codes } = await sdk.auth.mfa.generateRecoveryCodes()
1170 - lang: Shell
1171 label: cURL
1172 source: curl -X POST '{backend_url}/auth/mfa/recovery-codes'
1173 tags:
1174 - Multi-Factor Authentication (MFA) Factors
1175 responses:
1176 '200':
1177 description: OK
1178 '400':
1179 $ref: '#/components/responses/400_error'
1180 '401':
1181 $ref: '#/components/responses/unauthorized'
1182 '404':
1183 $ref: '#/components/responses/not_found_error'
1184 '409':
1185 $ref: '#/components/responses/invalid_state_error'
1186 '422':
1187 $ref: '#/components/responses/invalid_request_error'
1188 '500':
1189 $ref: '#/components/responses/500_error'
1190 x-since: 2.15.3
1191 /auth/session:
1192 post:
1193 operationId: PostSession
1194 summary: Set Authentication Session
1195 description: Set the cookie session ID of a customer. The customer must be previously authenticated with the `/auth/customer/{provider}` API route first, as the JWT token is required in the header of the request.
1196 externalDocs:
1197 url: https://docs.medusajs.com/resources/storefront-development/customers/login#2-using-a-cookie-session
1198 description: 'Storefront development: How to login as a customer'
1199 x-authenticated: true
1200 x-codeSamples:
1201 - lang: Shell
1202 label: cURL
1203 source: |-
1204 curl -X POST '{backend_url}/auth/session' \
1205 -H 'Authorization: Bearer {jwt_token}'
1206 tags:
1207 - Auth
1208 responses:
1209 '200':
1210 description: OK
1211 content:
1212 application/json:
1213 schema:
1214 $ref: '#/components/schemas/AuthStoreSessionResponse'
1215 '400':
1216 $ref: '#/components/responses/400_error'
1217 '401':
1218 $ref: '#/components/responses/unauthorized'
1219 '404':
1220 $ref: '#/components/responses/not_found_error'
1221 '409':
1222 $ref: '#/components/responses/invalid_state_error'
1223 '422':
1224 $ref: '#/components/responses/invalid_request_error'
1225 '500':
1226 $ref: '#/components/responses/500_error'
1227 delete:
1228 operationId: DeleteSession
1229 summary: Delete Authentication Session
1230 description: Deletes the cookie session ID previously set for authentication.
1231 x-authenticated: true
1232 x-codeSamples:
1233 - lang: JavaScript
1234 label: JS SDK
1235 source: |-
1236 import Medusa from "@medusajs/js-sdk"
1237
1238 let MEDUSA_BACKEND_URL = "http://localhost:9000"
1239
1240 if (process.env.NEXT_PUBLIC_MEDUSA_BACKEND_URL) {
1241 MEDUSA_BACKEND_URL = process.env.NEXT_PUBLIC_MEDUSA_BACKEND_URL
1242 }
1243
1244 export const sdk = new Medusa({
1245 baseUrl: MEDUSA_BACKEND_URL,
1246 debug: process.env.NODE_ENV === "development",
1247 publishableKey: process.env.NEXT_PUBLIC_MEDUSA_PUBLISHABLE_KEY,
1248 })
1249
1250 await sdk.auth.logout()
1251
1252 // customer is now logged out
1253 // you can't send any requests that require authentication
1254 - lang: Shell
1255 label: cURL
1256 source: |-
1257 curl -X DELETE '{backend_url}/auth/session' \
1258 -H 'Cookie: connect.sid={sid}'
1259 tags:
1260 - Auth
1261 responses:
1262 '200':
1263 description: OK
1264 content:
1265 application/json:
1266 schema:
1267 type: object
1268 description: The deletion's details.
1269 required:
1270 - success
1271 properties:
1272 success:
1273 type: boolean
1274 title: success
1275 description: Whether the session was deleted successfully.
1276 '400':
1277 $ref: '#/components/responses/400_error'
1278 '401':
1279 $ref: '#/components/responses/unauthorized'
1280 '404':
1281 $ref: '#/components/responses/not_found_error'
1282 '409':
1283 $ref: '#/components/responses/invalid_state_error'
1284 '422':
1285 $ref: '#/components/responses/invalid_request_error'
1286 '500':
1287 $ref: '#/components/responses/500_error'
1288 /auth/token/refresh:
1289 post:
1290 operationId: PostAdminAuthTokenRefresh
1291 summary: Refresh Authentication Token
1292 description: Refresh the authentication token of a customer. This is useful after authenticating a customer with a third-party service to ensure the token holds the new user's details, or when you don't want customers to re-login every day.
1293 externalDocs:
1294 url: https://docs.medusajs.com/resources/storefront-development/customers/third-party-login
1295 description: 'Storefront development: Implement third-party (social) login.'
1296 x-authenticated: true
1297 x-codeSamples:
1298 - lang: JavaScript
1299 label: JS SDK
1300 source: |-
1301 import Medusa from "@medusajs/js-sdk"
1302
1303 let MEDUSA_BACKEND_URL = "http://localhost:9000"
1304
1305 if (process.env.NEXT_PUBLIC_MEDUSA_BACKEND_URL) {
1306 MEDUSA_BACKEND_URL = process.env.NEXT_PUBLIC_MEDUSA_BACKEND_URL
1307 }
1308
1309 export const sdk = new Medusa({
1310 baseUrl: MEDUSA_BACKEND_URL,
1311 debug: process.env.NODE_ENV === "development",
1312 publishableKey: process.env.NEXT_PUBLIC_MEDUSA_PUBLISHABLE_KEY,
1313 })
1314
1315 const token = await sdk.auth.refresh()
1316
1317 // all subsequent requests will use the token in the header
1318 const { customer } = await sdk.store.customer.retrieve()
1319 - lang: Shell
1320 label: cURL
1321 source: |-
1322 curl -X POST '{backend_url}/auth/token/refresh' \
1323 -H 'Authorization: Bearer {token}'
1324 tags:
1325 - Auth
1326 responses:
1327 '200':
1328 description: OK
1329 content:
1330 application/json:
1331 schema:
1332 $ref: '#/components/schemas/AuthResponse'
1333 '400':
1334 $ref: '#/components/responses/400_error'
1335 '401':
1336 $ref: '#/components/responses/unauthorized'
1337 '404':
1338 $ref: '#/components/responses/not_found_error'
1339 '409':
1340 $ref: '#/components/responses/invalid_state_error'
1341 '422':
1342 $ref: '#/components/responses/invalid_request_error'
1343 '500':
1344 $ref: '#/components/responses/500_error'
1345 /auth/verification/confirm:
1346 post:
1347 operationId: PostVerificationConfirm
1348 summary: Confirm Customer Verification
1349 x-sidebar-summary: Confirm Verification
1350 description: Confirm a verification token of the customer. This API route is used as the last step part of the email verification flow. It can also be used for custom flows, such as phone number verification. Once successfully verified, a customer can complete their registration and log into their account.
1351 externalDocs:
1352 url: https://docs.medusajs.com/resources/storefront-development/customers/verify-account
1353 description: 'Storefront guide: Register Customer with Email Verification.'
1354 x-authenticated: false
1355 requestBody:
1356 content:
1357 application/json:
1358 schema:
1359 type: object
1360 description: The verification details
1361 required:
1362 - code
1363 properties:
1364 code:
1365 type: string
1366 title: code
1367 description: The token, OTP, or any other code that was sent to the customer for verification.
1368 code_provider:
1369 type: string
1370 title: code_provider
1371 description: The provider to use for verification. This is optional. When not provided, the default `token` provider is used.
1372 x-codeSamples:
1373 - lang: Shell
1374 label: cURL
1375 source: |-
1376 curl -X POST '{backend_url}/auth/verification/confirm' \
1377 -H 'Content-Type: application/json' \
1378 --data-raw '{
1379 "code": "{value}"
1380 }'
1381 tags:
1382 - Verification
1383 responses:
1384 '200':
1385 description: OK
1386 '400':
1387 $ref: '#/components/responses/400_error'
1388 '401':
1389 $ref: '#/components/responses/unauthorized'
1390 '404':
1391 $ref: '#/components/responses/not_found_error'
1392 '409':
1393 $ref: '#/components/responses/invalid_state_error'
1394 '422':
1395 $ref: '#/components/responses/invalid_request_error'
1396 '500':
1397 $ref: '#/components/responses/500_error'
1398 x-since: 2.16.0
1399 /auth/verification/request:
1400 post:
1401 operationId: PostVerificationRequest
1402 summary: Request Customer Verification
1403 x-sidebar-summary: Request Verification
1404 description: Create a verification request for a customer. This API route is used when a customer logs in, but their email requires verification. It can also be used for custom flows, such as phone number verification. Once successfully requested, a verification code will be generated and an `auth.verification_requested` event will be emitted. You can listen to this event and decide how to deliver the code to the customer.
1405 externalDocs:
1406 url: https://docs.medusajs.com/resources/storefront-development/customers/verify-account
1407 description: 'Storefront guide: Register Customer with Email Verification.'
1408 x-authenticated: false
1409 parameters: []
1410 requestBody:
1411 content:
1412 application/json:
1413 schema:
1414 type: object
1415 description: The verification request details
1416 required:
1417 - entity_id
1418 - entity_type
1419 - code_provider
1420 properties:
1421 entity_id:
1422 type: string
1423 title: entity_id
1424 description: The identifier of the user or customer. For example, an email address.
1425 entity_type:
1426 type: string
1427 title: entity_type
1428 description: The type of identity being verified. For example, "email" or "phone_number".
1429 code_provider:
1430 type: string
1431 title: code_provider
1432 description: The provider to use to create the verification token or code. By default, Medusa provides a `token` provider that generates a random token. You can also implement your own provider to generate a code or OTP.
1433 metadata:
1434 type: object
1435 description: Custom key-value pairs that can be passed to the verification request. This is optional and can be used to store additional information related to the verification request.
1436 x-codeSamples:
1437 - lang: Shell
1438 label: cURL
1439 source: |-
1440 curl -X POST '{backend_url}/auth/verification/request' \
1441 -H 'Content-Type: application/json' \
1442 --data-raw '{
1443 "entity_id": "customer@example.com",
1444 "entity_type": "email",
1445 "code_provider": "token"
1446 }'
1447 tags:
1448 - Verification
1449 responses:
1450 '201':
1451 description: OK
1452 '400':
1453 $ref: '#/components/responses/400_error'
1454 '401':
1455 $ref: '#/components/responses/unauthorized'
1456 '404':
1457 $ref: '#/components/responses/not_found_error'
1458 '409':
1459 $ref: '#/components/responses/invalid_state_error'
1460 '422':
1461 $ref: '#/components/responses/invalid_request_error'
1462 '500':
1463 $ref: '#/components/responses/500_error'
1464 x-workflow: requestVerificationWorkflow
1465 x-events:
1466 - name: auth.verification_requested
1467 payload: |-
1468 ```ts
1469 {
1470 entity_id, // The identifier of the user or customer. For example, an email address.
1471 actor_type, // The type of actor. For example, "customer", "user", or custom.
1472 provider, // The auth provider that requested verification.
1473 auth_identity_id, // The ID of the auth identity being verified.
1474 provider_identity_id, // The ID of the provider identity being verified.
1475 code, // The generated verification code.
1476 expires_at, // The code expiry date.
1477 metadata, // Optional custom metadata passed from the request.
1478 }
1479 ```
1480 description: |-
1481 Emitted when a verification code is generated. You can listen to
1482 this event and decide how to deliver the code to the user or customer.
1483 deprecated: false
1484 since: 2.15.5
1485 x-since: 2.16.0
1486 /store/carts:
1487 post:
1488 operationId: PostCarts
1489 summary: Create Cart
1490 description: Create a cart.
1491 x-authenticated: false
1492 parameters:
1493 - name: x-publishable-api-key
1494 in: header
1495 description: Publishable API Key created in the Medusa Admin.
1496 required: true
1497 schema:
1498 type: string
1499 externalDocs:
1500 url: https://docs.medusajs.com/api/store#publishable-api-key
1501 - name: x-medusa-locale
1502 in: header
1503 description: The locale in BCP 47 format to retrieve localized content.
1504 required: false
1505 schema:
1506 type: string
1507 example: en-US
1508 externalDocs:
1509 url: https://docs.medusajs.com/resources/commerce-modules/translation/storefront
1510 description: Learn more in the Serve Translations in Storefront guide.
1511 - name: fields
1512 in: query
1513 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 fields. without prefix it will replace the entire default fields.
1514 required: false
1515 schema:
1516 type: string
1517 title: fields
1518 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 fields. without prefix it will replace the entire default fields.
1519 externalDocs:
1520 url: '#select-fields-and-relations'
1521 - name: locale
1522 in: query
1523 description: The locale in BCP 47 format to retrieve localized content.
1524 required: false
1525 schema:
1526 type: string
1527 example: en-US
1528 externalDocs:
1529 url: https://docs.medusajs.com/resources/commerce-modules/translation/storefront
1530 description: Learn more in the Serve Translations in Storefront guide.
1531 requestBody:
1532 content:
1533 application/json:
1534 schema:
1535 allOf:
1536 - $ref: '#/components/schemas/StoreCreateCart'
1537 - type: object
1538 description: The cart's details.
1539 properties:
1540 additional_data:
1541 type: object
1542 description: Pass additional custom data to the API route. This data is passed to the underlying workflow under the `additional_data` parameter.
1543 description: The cart's details.
1544 x-codeSamples:
1545 - lang: JavaScript
1546 label: JS SDK
1547 source: |-
1548 import Medusa from "@medusajs/js-sdk"
1549
1550 let MEDUSA_BACKEND_URL = "http://localhost:9000"
1551
1552 if (process.env.NEXT_PUBLIC_MEDUSA_BACKEND_URL) {
1553 MEDUSA_BACKEND_URL = process.env.NEXT_PUBLIC_MEDUSA_BACKEND_URL
1554 }
1555
1556 export const sdk = new Medusa({
1557 baseUrl: MEDUSA_BACKEND_URL,
1558 debug: process.env.NODE_ENV === "development",
1559 publishableKey: process.env.NEXT_PUBLIC_MEDUSA_PUBLISHABLE_KEY,
1560 })
1561
1562 sdk.store.cart.create({
1563 region_id: "reg_123"
1564 })
1565 .then(({ cart }) => {
1566 console.log(cart)
1567 })
1568 - lang: Shell
1569 label: cURL
1570 source: |-
1571 curl -X POST '{backend_url}/store/carts' \
1572 -H 'Content-Type: application/json' \
1573 -H 'x-publishable-api-key: {your_publishable_api_key}' \
1574 --data-raw '{
1575 "region_id": "reg_123"
1576 }'
1577 tags:
1578 - Carts
1579 responses:
1580 '200':
1581 description: OK
1582 content:
1583 application/json:
1584 schema:
1585 $ref: '#/components/schemas/StoreCartResponse'
1586 '400':
1587 $ref: '#/components/responses/400_error'
1588 '401':
1589 $ref: '#/components/responses/unauthorized'
1590 '404':
1591 $ref: '#/components/responses/not_found_error'
1592 '409':
1593 $ref: '#/components/responses/invalid_state_error'
1594 '422':
1595 $ref: '#/components/responses/invalid_request_error'
1596 '500':
1597 $ref: '#/components/responses/500_error'
1598 x-workflow: createCartWorkflow
1599 x-events:
1600 - name: cart.created
1601 payload: |-
1602 ```ts
1603 {
1604 id, // The ID of the cart
1605 }
1606 ```
1607 description: Emitted when a cart is created.
1608 deprecated: false
1609 /store/carts/{id}:
1610 get:
1611 operationId: GetCartsId
1612 summary: Get a Cart
1613 description: Retrieve a cart by its ID. You can expand the cart's relations or select the fields that should be returned.
1614 x-authenticated: false
1615 parameters:
1616 - name: id
1617 in: path
1618 description: The cart's ID.
1619 required: true
1620 schema:
1621 type: string
1622 - name: x-publishable-api-key
1623 in: header
1624 description: Publishable API Key created in the Medusa Admin.
1625 required: true
1626 schema:
1627 type: string
1628 externalDocs:
1629 url: https://docs.medusajs.com/api/store#publishable-api-key
1630 - name: x-medusa-locale
1631 in: header
1632 description: The locale in BCP 47 format to retrieve localized content.
1633 required: false
1634 schema:
1635 type: string
1636 example: en-US
1637 externalDocs:
1638 url: https://docs.medusajs.com/resources/commerce-modules/translation/storefront
1639 description: Learn more in the Serve Translations in Storefront guide.
1640 - name: fields
1641 in: query
1642 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 fields. without prefix it will replace the entire default fields.
1643 required: false
1644 schema:
1645 type: string
1646 title: fields
1647 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 fields. without prefix it will replace the entire default fields.
1648 externalDocs:
1649 url: '#select-fields-and-relations'
1650 - name: locale
1651 in: query
1652 description: The locale in BCP 47 format to retrieve localized content.
1653 required: false
1654 schema:
1655 type: string
1656 example: en-US
1657 externalDocs:
1658 url: https://docs.medusajs.com/resources/commerce-modules/translation/storefront
1659 description: Learn more in the Serve Translations in Storefront guide.
1660 x-codeSamples:
1661 - lang: JavaScript
1662 label: JS SDK
1663 source: |-
1664 import Medusa from "@medusajs/js-sdk"
1665
1666 let MEDUSA_BACKEND_URL = "http://localhost:9000"
1667
1668 if (process.env.NEXT_PUBLIC_MEDUSA_BACKEND_URL) {
1669 MEDUSA_BACKEND_URL = process.env.NEXT_PUBLIC_MEDUSA_BACKEND_URL
1670 }
1671
1672 export const sdk = new Medusa({
1673 baseUrl: MEDUSA_BACKEND_URL,
1674 debug: process.env.NODE_ENV === "development",
1675 publishableKey: process.env.NEXT_PUBLIC_MEDUSA_PUBLISHABLE_KEY,
1676 })
1677
1678 sdk.store.cart.retrieve("cart_123")
1679 .then(({ cart }) => {
1680 console.log(cart)
1681 })
1682 - lang: Shell
1683 label: cURL
1684 source: |-
1685 curl '{backend_url}/store/carts/{id}' \
1686 -H 'x-publishable-api-key: {your_publishable_api_key}'
1687 tags:
1688 - Carts
1689 responses:
1690 '200':
1691 description: OK
1692 content:
1693 application/json:
1694 schema:
1695 $ref: '#/components/schemas/StoreCartResponse'
1696 '400':
1697 $ref: '#/components/responses/400_error'
1698 '401':
1699 $ref: '#/components/responses/unauthorized'
1700 '404':
1701 $ref: '#/components/responses/not_found_error'
1702 '409':
1703 $ref: '#/components/responses/invalid_state_error'
1704 '422':
1705 $ref: '#/components/responses/invalid_request_error'
1706 '500':
1707 $ref: '#/components/responses/500_error'
1708 post:
1709 operationId: PostCartsId
1710 summary: Update a Cart
1711 description: Update a cart's details. This unsets the payment methods chosen before, and the customer would have to choose them again. Also, if the customer has chosen a shipping method whose option isn't valid for the cart's shipping address anymore, the shipping method will be unset. For example, if the shipping option is valid only in the US geo zone, and the shipping address's country code is `DE`, the shipping method will be unset.
1712 x-authenticated: false
1713 parameters:
1714 - name: id
1715 in: path
1716 description: The cart's ID.
1717 required: true
1718 schema:
1719 type: string
1720 - name: x-publishable-api-key
1721 in: header
1722 description: Publishable API Key created in the Medusa Admin.
1723 required: true
1724 schema:
1725 type: string
1726 externalDocs:
1727 url: https://docs.medusajs.com/api/store#publishable-api-key
1728 - name: x-medusa-locale
1729 in: header
1730 description: The locale in BCP 47 format to retrieve localized content.
1731 required: false
1732 schema:
1733 type: string
1734 example: en-US
1735 externalDocs:
1736 url: https://docs.medusajs.com/resources/commerce-modules/translation/storefront
1737 description: Learn more in the Serve Translations in Storefront guide.
1738 - name: fields
1739 in: query
1740 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 fields. without prefix it will replace the entire default fields.
1741 required: false
1742 schema:
1743 type: string
1744 title: fields
1745 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 fields. without prefix it will replace the entire default fields.
1746 externalDocs:
1747 url: '#select-fields-and-relations'
1748 - name: locale
1749 in: query
1750 description: The locale in BCP 47 format to retrieve localized content.
1751 required: false
1752 schema:
1753 type: string
1754 example: en-US
1755 externalDocs:
1756 url: https://docs.medusajs.com/resources/commerce-modules/translation/storefront
1757 description: Learn more in the Serve Translations in Storefront guide.
1758 requestBody:
1759 content:
1760 application/json:
1761 schema:
1762 allOf:
1763 - $ref: '#/components/schemas/UpdateCartData'
1764 - type: object
1765 description: The properties to update in the cart item.
1766 properties:
1767 additional_data:
1768 type: object
1769 description: Pass additional custom data to the API route. This data is passed to the underlying workflow under the `additional_data` parameter.
1770 description: The properties to update in the cart item.
1771 x-codeSamples:
1772 - lang: JavaScript
1773 label: JS SDK
1774 source: |-
1775 import Medusa from "@medusajs/js-sdk"
1776
1777 let MEDUSA_BACKEND_URL = "http://localhost:9000"
1778
1779 if (process.env.NEXT_PUBLIC_MEDUSA_BACKEND_URL) {
1780 MEDUSA_BACKEND_URL = process.env.NEXT_PUBLIC_MEDUSA_BACKEND_URL
1781 }
1782
1783 export const sdk = new Medusa({
1784 baseUrl: MEDUSA_BACKEND_URL,
1785 debug: process.env.NODE_ENV === "development",
1786 publishableKey: process.env.NEXT_PUBLIC_MEDUSA_PUBLISHABLE_KEY,
1787 })
1788
1789 sdk.store.cart.update("cart_123", {
1790 region_id: "reg_123"
1791 })
1792 .then(({ cart }) => {
1793 console.log(cart)
1794 })
1795 - lang: Shell
1796 label: cURL
1797 source: |-
1798 curl -X POST '{backend_url}/store/carts/{id}' \
1799 -H 'x-publishable-api-key: {your_publishable_api_key}'
1800 tags:
1801 - Carts
1802 responses:
1803 '200':
1804 description: OK
1805 content:
1806 application/json:
1807 schema:
1808 type: object
1809 description: The updated cart's details.
1810 required:
1811 - cart
1812 properties:
1813 cart:
1814 $ref: '#/components/schemas/StoreCart'
1815 '400':
1816 $ref: '#/components/responses/400_error'
1817 '401':
1818 $ref: '#/components/responses/unauthorized'
1819 '404':
1820 $ref: '#/components/responses/not_found_error'
1821 '409':
1822 $ref: '#/components/responses/invalid_state_error'
1823 '422':
1824 $ref: '#/components/responses/invalid_request_error'
1825 '500':
1826 $ref: '#/components/responses/500_error'
1827 x-workflow: updateCartWorkflow
1828 x-events:
1829 - name: cart.updated
1830 payload: |-
1831 ```ts
1832 {
1833 id, // The ID of the cart
1834 }
1835 ```
1836 description: Emitted when a cart's details are updated.
1837 deprecated: false
1838 - name: cart.region_updated
1839 payload: |-
1840 ```ts
1841 {
1842 id, // The ID of the cart
1843 }
1844 ```
1845 description: |-
1846 Emitted when the cart's region is updated. This
1847 event is emitted alongside the `cart.updated` event.
1848 deprecated: false
1849 /store/carts/{id}/complete:
1850 post:
1851 operationId: PostCartsIdComplete
1852 summary: Complete Cart
1853 description: Complete a cart and place an order.
1854 x-authenticated: false
1855 externalDocs:
1856 url: https://docs.medusajs.com/resources/storefront-development/checkout/complete-cart
1857 description: 'Storefront guide: How to implement cart completion during checkout.'
1858 parameters:
1859 - name: id
1860 in: path
1861 description: The cart's ID.
1862 required: true
1863 schema:
1864 type: string
1865 - name: x-publishable-api-key
1866 in: header
1867 description: Publishable API Key created in the Medusa Admin.
1868 required: true
1869 schema:
1870 type: string
1871 externalDocs:
1872 url: https://docs.medusajs.com/api/store#publishable-api-key
1873 - name: x-medusa-locale
1874 in: header
1875 description: The locale in BCP 47 format to retrieve localized content.
1876 required: false
1877 schema:
1878 type: string
1879 example: en-US
1880 externalDocs:
1881 url: https://docs.medusajs.com/resources/commerce-modules/translation/storefront
1882 description: Learn more in the Serve Translations in Storefront guide.
1883 - name: fields
1884 in: query
1885 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 fields. without prefix it will replace the entire default fields.
1886 required: false
1887 schema:
1888 type: string
1889 title: fields
1890 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 fields. without prefix it will replace the entire default fields.
1891 externalDocs:
1892 url: '#select-fields-and-relations'
1893 - name: locale
1894 in: query
1895 description: The locale in BCP 47 format to retrieve localized content.
1896 required: false
1897 schema:
1898 type: string
1899 example: en-US
1900 externalDocs:
1901 url: https://docs.medusajs.com/resources/commerce-modules/translation/storefront
1902 description: Learn more in the Serve Translations in Storefront guide.
1903 x-codeSamples:
1904 - lang: JavaScript
1905 label: JS SDK
1906 source: |-
1907 import Medusa from "@medusajs/js-sdk"
1908
1909 let MEDUSA_BACKEND_URL = "http://localhost:9000"
1910
1911 if (process.env.NEXT_PUBLIC_MEDUSA_BACKEND_URL) {
1912 MEDUSA_BACKEND_URL = process.env.NEXT_PUBLIC_MEDUSA_BACKEND_URL
1913 }
1914
1915 export const sdk = new Medusa({
1916 baseUrl: MEDUSA_BACKEND_URL,
1917 debug: process.env.NODE_ENV === "development",
1918 publishableKey: process.env.NEXT_PUBLIC_MEDUSA_PUBLISHABLE_KEY,
1919 })
1920
1921 sdk.store.cart.complete("cart_123")
1922 .then((data) => {
1923 if(data.type === "cart") {
1924 // an error occurred
1925 console.log(data.error, data.cart)
1926 } else {
1927 // order placed successfully
1928 console.log(data.order)
1929 }
1930 })
1931 - lang: Shell
1932 label: cURL
1933 source: |-
1934 curl -X POST '{backend_url}/store/carts/{id}/complete' \
1935 -H 'x-publishable-api-key: {your_publishable_api_key}'
1936 tags:
1937 - Carts
1938 responses:
1939 '200':
1940 description: OK
1941 content:
1942 application/json:
1943 schema:
1944 oneOf:
1945 - type: object
1946 description: The created order's details.
1947 required:
1948 - type
1949 - order
1950 properties:
1951 type:
1952 type: string
1953 title: type
1954 description: The type of the returned object. In this case, the order is returned because the cart was completed successfully.
1955 default: order
1956 order:
1957 $ref: '#/components/schemas/StoreOrder'
1958 - type: object
1959 description: The details of why the cart completion failed.
1960 required:
1961 - type
1962 - cart
1963 - error
1964 properties:
1965 type:
1966 type: string
1967 title: type
1968 description: The type of the returned object. In this case, the cart is returned because an error has occurred.
1969 default: cart
1970 cart:
1971 $ref: '#/components/schemas/StoreCart'
1972 error:
1973 type: object
1974 description: The error's details.
1975 required:
1976 - message
1977 - name
1978 - type
1979 properties:
1980 message:
1981 type: string
1982 title: message
1983 description: The error's message.
1984 name:
1985 type: string
1986 title: name
1987 description: The error's name.
1988 type:
1989 type: string
1990 title: type
1991 description: |
1992 The error's type. Can be a [MedusaError type](https://docs.medusajs.com/learn/fundamentals/api-routes/errors#medusaerror-types) or `payment_authorization_error` or `payment_requires_more_error` for payment-related errors.
1993 '400':
1994 $ref: '#/components/responses/400_error'
1995 '401':
1996 $ref: '#/components/responses/unauthorized'
1997 '404':
1998 $ref: '#/components/responses/not_found_error'
1999 '409':
2000 $ref: '#/components/responses/invalid_state_error'
2001 '422':
2002 $ref: '#/components/responses/invalid_request_error'
2003 '500':
2004 $ref: '#/components/responses/500_error'
2005 x-workflow: completeCartWorkflow
2006 x-events:
2007 - name: order.placed
2008 payload: |-
2009 ```ts
2010 {
2011 id, // The ID of the order
2012 }
2013 ```
2014 description: |-
2015 Emitted when an order is placed, or when a draft order is converted to an
2016 order.
2017 deprecated: false
2018 - name: reservation-item.created
2019 payload: |-
2020 ```ts
2021 {
2022 id, // The ID of the reservation
2023 order_id, // (optional) The ID of the order, if the reservation was created by an order flow
2024 }
2025 ```
2026 description: Emitted when reservations are created.
2027 deprecated: false
2028 since: 2.17.3
2029 /store/carts/{id}/customer:
2030 post:
2031 operationId: PostCartsIdCustomer
2032 summary: Change Cart's Customer to Logged-in Customer
2033 x-sidebar-summary: Change Customer
2034 description: Change the cart's customer to the currently logged-in customer. This is useful when you create the cart for a guest customer, then they log in with their account.
2035 externalDocs:
2036 url: https://docs.medusajs.com/resources/storefront-development/cart/update#set-carts-customer
2037 description: 'Storefront guide: How to set the cart''s customer.'
2038 x-authenticated: true
2039 parameters:
2040 - name: id
2041 in: path
2042 description: The cart's ID.
2043 required: true
2044 schema:
2045 type: string
2046 - name: x-publishable-api-key
2047 in: header
2048 description: Publishable API Key created in the Medusa Admin.
2049 required: true
2050 schema:
2051 type: string
2052 externalDocs:
2053 url: https://docs.medusajs.com/api/store#publishable-api-key
2054 - name: x-medusa-locale
2055 in: header
2056 description: The locale in BCP 47 format to retrieve localized content.
2057 required: false
2058 schema:
2059 type: string
2060 example: en-US
2061 externalDocs:
2062 url: https://docs.medusajs.com/resources/commerce-modules/translation/storefront
2063 description: Learn more in the Serve Translations in Storefront guide.
2064 - name: fields
2065 in: query
2066 description: |-
2067 Comma-separated fields that should be included in the returned data.
2068 if a field is prefixed with `+` it will be added to the default fields, using `-` will remove it from the default fields.
2069 without prefix it will replace the entire default fields.
2070 required: false
2071 schema:
2072 type: string
2073 title: fields
2074 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 fields. Without prefix it will replace the entire default fields.
2075 externalDocs:
2076 url: '#select-fields-and-relations'
2077 - name: locale
2078 in: query
2079 description: The locale in BCP 47 format to retrieve localized content.
2080 required: false
2081 schema:
2082 type: string
2083 example: en-US
2084 externalDocs:
2085 url: https://docs.medusajs.com/resources/commerce-modules/translation/storefront
2086 description: Learn more in the Serve Translations in Storefront guide.
2087 security:
2088 - cookie_auth: []
2089 - jwt_token: []
2090 requestBody:
2091 content:
2092 application/json:
2093 schema:
2094 type: object
2095 description: Optional additional data to pass to the underlying workflow.
2096 properties:
2097 additional_data:
2098 type: object
2099 description: Pass additional custom data to the API route. This data is passed to the underlying workflow under the `additional_data` parameter.
2100 x-codeSamples:
2101 - lang: JavaScript
2102 label: JS SDK
2103 source: |-
2104 import Medusa from "@medusajs/js-sdk"
2105
2106 let MEDUSA_BACKEND_URL = "http://localhost:9000"
2107
2108 if (process.env.NEXT_PUBLIC_MEDUSA_BACKEND_URL) {
2109 MEDUSA_BACKEND_URL = process.env.NEXT_PUBLIC_MEDUSA_BACKEND_URL
2110 }
2111
2112 export const sdk = new Medusa({
2113 baseUrl: MEDUSA_BACKEND_URL,
2114 debug: process.env.NODE_ENV === "development",
2115 publishableKey: process.env.NEXT_PUBLIC_MEDUSA_PUBLISHABLE_KEY,
2116 })
2117
2118 // TODO must be authenticated as the customer to set the cart's customer
2119 sdk.store.cart.transferCart("cart_123")
2120 .then(({ cart }) => {
2121 console.log(cart)
2122 })
2123 - lang: Shell
2124 label: cURL
2125 source: |-
2126 curl -X POST '{backend_url}/store/carts/{id}/customer' \
2127 -H 'Authorization: Bearer {jwt_token}' \
2128 -H 'x-publishable-api-key: {your_publishable_api_key}'
2129 tags:
2130 - Carts
2131 responses:
2132 '200':
2133 description: OK
2134 content:
2135 application/json:
2136 schema:
2137 $ref: '#/components/schemas/StoreCartResponse'
2138 '400':
2139 $ref: '#/components/responses/400_error'
2140 '401':
2141 $ref: '#/components/responses/unauthorized'
2142 '404':
2143 $ref: '#/components/responses/not_found_error'
2144 '409':
2145 $ref: '#/components/responses/invalid_state_error'
2146 '422':
2147 $ref: '#/components/responses/invalid_request_error'
2148 '500':
2149 $ref: '#/components/responses/500_error'
2150 x-workflow: transferCartCustomerWorkflow
2151 x-events:
2152 - name: cart.customer_transferred
2153 payload: |-
2154 ```ts
2155 {
2156 id, // The ID of the cart
2157 customer_id, // The ID of the customer
2158 }
2159 ```
2160 description: Emitted when the customer in the cart is transferred.
2161 deprecated: false
2162 since: 2.8.0
2163 /store/carts/{id}/gift-cards:
2164 post:
2165 operationId: PostCartsIdGiftCards
2166 summary: Add Gift Card to Cart
2167 x-sidebar-summary: Add Gift Card
2168 description: Add a Gift Card to a cart
2169 x-authenticated: false
2170 x-ignoreCleanup: true
2171 parameters:
2172 - name: id
2173 in: path
2174 description: The cart's ID.
2175 required: true
2176 schema:
2177 type: string
2178 - name: x-publishable-api-key
2179 in: header
2180 description: Publishable API Key created in the Medusa Admin.
2181 required: true
2182 schema:
2183 type: string
2184 externalDocs:
2185 url: https://docs.medusajs.com/api/store#publishable-api-key
2186 - name: x-medusa-locale
2187 in: header
2188 description: The locale in BCP 47 format to retrieve localized content.
2189 required: false
2190 schema:
2191 type: string
2192 example: en-US
2193 externalDocs:
2194 url: https://docs.medusajs.com/resources/commerce-modules/translation/storefront
2195 description: Learn more in the Serve Translations in Storefront guide.
2196 - name: locale
2197 in: query
2198 description: The locale in BCP 47 format to retrieve localized content.
2199 required: false
2200 schema:
2201 type: string
2202 example: en-US
2203 externalDocs:
2204 url: https://docs.medusajs.com/resources/commerce-modules/translation/storefront
2205 description: Learn more in the Serve Translations in Storefront guide.
2206 requestBody:
2207 content:
2208 application/json:
2209 schema:
2210 $ref: '#/components/schemas/StoreAddGiftCardToCart'
2211 x-codeSamples:
2212 - lang: Shell
2213 label: cURL
2214 source: |-
2215 curl -X POST '{backend_url}/store/carts/{id}/gift-cards' \
2216 -H 'x-publishable-api-key: {your_publishable_api_key}' \
2217 -H 'Content-Type: application/json' \
2218 --data-raw '{
2219 "code": "{value}"
2220 }'
2221 tags:
2222 - Carts
2223 responses:
2224 '200':
2225 description: OK
2226 content:
2227 application/json:
2228 schema:
2229 $ref: '#/components/schemas/StoreCartResponse'
2230 '400':
2231 $ref: '#/components/responses/400_error'
2232 '401':
2233 $ref: '#/components/responses/unauthorized'
2234 '404':
2235 $ref: '#/components/responses/not_found_error'
2236 '409':
2237 $ref: '#/components/responses/invalid_state_error'
2238 '422':
2239 $ref: '#/components/responses/invalid_request_error'
2240 '500':
2241 $ref: '#/components/responses/500_error'
2242 x-badges:
2243 - text: Plugin
2244 description: |
2245 This API route is only available through the [Loyalty Plugin](https://docs.medusajs.com/resources/commerce-modules/loyalty).
2246 delete:
2247 operationId: DeleteCartsIdGiftCards
2248 summary: Remove Gift Card from Cart
2249 x-sidebar-summary: Remove Gift Card
2250 description: Remove a Gift Card from a cart.
2251 x-authenticated: false
2252 x-ignoreCleanup: true
2253 parameters:
2254 - name: id
2255 in: path
2256 description: The cart's ID.
2257 required: true
2258 schema:
2259 type: string
2260 - name: x-publishable-api-key
2261 in: header
2262 description: Publishable API Key created in the Medusa Admin.
2263 required: true
2264 schema:
2265 type: string
2266 externalDocs:
2267 url: https://docs.medusajs.com/api/store#publishable-api-key
2268 - name: x-medusa-locale
2269 in: header
2270 description: The locale in BCP 47 format to retrieve localized content.
2271 required: false
2272 schema:
2273 type: string
2274 example: en-US
2275 externalDocs:
2276 url: https://docs.medusajs.com/resources/commerce-modules/translation/storefront
2277 description: Learn more in the Serve Translations in Storefront guide.
2278 - name: locale
2279 in: query
2280 description: The locale in BCP 47 format to retrieve localized content.
2281 required: false
2282 schema:
2283 type: string
2284 example: en-US
2285 externalDocs:
2286 url: https://docs.medusajs.com/resources/commerce-modules/translation/storefront
2287 description: Learn more in the Serve Translations in Storefront guide.
2288 requestBody:
2289 content:
2290 application/json:
2291 schema:
2292 $ref: '#/components/schemas/StoreRemoveGiftCardFromCart'
2293 x-codeSamples:
2294 - lang: Shell
2295 label: cURL
2296 source: |-
2297 curl -X DELETE '{backend_url}/store/carts/{id}/gift-cards' \
2298 -H 'x-publishable-api-key: {your_publishable_api_key}' \
2299 -H 'Content-Type: application/json' \
2300 --data-raw '{
2301 "code": "{value}"
2302 }'
2303 tags:
2304 - Carts
2305 responses:
2306 '200':
2307 description: OK
2308 content:
2309 application/json:
2310 schema:
2311 $ref: '#/components/schemas/StoreCartResponse'
2312 '400':
2313 $ref: '#/components/responses/400_error'
2314 '401':
2315 $ref: '#/components/responses/unauthorized'
2316 '404':
2317 $ref: '#/components/responses/not_found_error'
2318 '409':
2319 $ref: '#/components/responses/invalid_state_error'
2320 '422':
2321 $ref: '#/components/responses/invalid_request_error'
2322 '500':
2323 $ref: '#/components/responses/500_error'
2324 x-badges:
2325 - text: Plugin
2326 description: |
2327 This API route is only available through the [Loyalty Plugin](https://docs.medusajs.com/resources/commerce-modules/loyalty).
2328 /store/carts/{id}/line-items:
2329 post:
2330 operationId: PostCartsIdLineItems
2331 summary: Add Line Item to Cart
2332 x-sidebar-summary: Add Line Item
2333 description: Add a product variant as a line item in the cart.
2334 externalDocs:
2335 url: https://docs.medusajs.com/resources/storefront-development/cart/manage-items#add-product-variant-to-cart
2336 description: 'Storefront guide: How to add a product variant to the cart.'
2337 x-authenticated: false
2338 parameters:
2339 - name: id
2340 in: path
2341 description: The cart's ID.
2342 required: true
2343 schema:
2344 type: string
2345 - name: x-publishable-api-key
2346 in: header
2347 description: Publishable API Key created in the Medusa Admin.
2348 required: true
2349 schema:
2350 type: string
2351 externalDocs:
2352 url: https://docs.medusajs.com/api/store#publishable-api-key
2353 - name: x-medusa-locale
2354 in: header
2355 description: The locale in BCP 47 format to retrieve localized content.
2356 required: false
2357 schema:
2358 type: string
2359 example: en-US
2360 externalDocs:
2361 url: https://docs.medusajs.com/resources/commerce-modules/translation/storefront
2362 description: Learn more in the Serve Translations in Storefront guide.
2363 - name: fields
2364 in: query
2365 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 fields. without prefix it will replace the entire default fields.
2366 required: false
2367 schema:
2368 type: string
2369 title: fields
2370 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 fields. without prefix it will replace the entire default fields.
2371 externalDocs:
2372 url: '#select-fields-and-relations'
2373 - name: locale
2374 in: query
2375 description: The locale in BCP 47 format to retrieve localized content.
2376 required: false
2377 schema:
2378 type: string
2379 example: en-US
2380 externalDocs:
2381 url: https://docs.medusajs.com/resources/commerce-modules/translation/storefront
2382 description: Learn more in the Serve Translations in Storefront guide.
2383 requestBody:
2384 content:
2385 application/json:
2386 schema:
2387 allOf:
2388 - type: object
2389 description: The details of the line item to add.
2390 required:
2391 - variant_id
2392 - quantity
2393 properties:
2394 variant_id:
2395 type: string
2396 title: variant_id
2397 description: The ID of the product variant to add as a line item.
2398 quantity:
2399 type: number
2400 title: quantity
2401 description: The item's quantity.
2402 metadata:
2403 type: object
2404 description: The item's metadata, can hold custom key-value pairs.
2405 - type: object
2406 description: The details of the line item to add.
2407 properties:
2408 additional_data:
2409 type: object
2410 description: Pass additional custom data to the API route. This data is passed to the underlying workflow under the `additional_data` parameter.
2411 description: The details of the line item to add.
2412 x-codeSamples:
2413 - lang: JavaScript
2414 label: JS SDK
2415 source: |-
2416 import Medusa from "@medusajs/js-sdk"
2417
2418 let MEDUSA_BACKEND_URL = "http://localhost:9000"
2419
2420 if (process.env.NEXT_PUBLIC_MEDUSA_BACKEND_URL) {
2421 MEDUSA_BACKEND_URL = process.env.NEXT_PUBLIC_MEDUSA_BACKEND_URL
2422 }
2423
2424 export const sdk = new Medusa({
2425 baseUrl: MEDUSA_BACKEND_URL,
2426 debug: process.env.NODE_ENV === "development",
2427 publishableKey: process.env.NEXT_PUBLIC_MEDUSA_PUBLISHABLE_KEY,
2428 })
2429
2430 sdk.store.cart.createLineItem("cart_123", {
2431 variant_id: "variant_123",
2432 quantity: 1
2433 })
2434 .then(({ cart }) => {
2435 console.log(cart)
2436 })
2437 - lang: Shell
2438 label: cURL
2439 source: |-
2440 curl -X POST '{backend_url}/store/carts/{id}/line-items' \
2441 -H 'Content-Type: application/json' \
2442 -H 'x-publishable-api-key: {your_publishable_api_key}' \
2443 --data-raw '{
2444 "variant_id": "{value}",
2445 "quantity": 3360689747918848,
2446 "metadata": {}
2447 }'
2448 tags:
2449 - Carts
2450 responses:
2451 '200':
2452 description: OK
2453 content:
2454 application/json:
2455 schema:
2456 $ref: '#/components/schemas/StoreCartResponse'
2457 '400':
2458 $ref: '#/components/responses/400_error'
2459 '401':
2460 $ref: '#/components/responses/unauthorized'
2461 '404':
2462 $ref: '#/components/responses/not_found_error'
2463 '409':
2464 $ref: '#/components/responses/invalid_state_error'
2465 '422':
2466 $ref: '#/components/responses/invalid_request_error'
2467 '500':
2468 $ref: '#/components/responses/500_error'
2469 x-workflow: addToCartWorkflow
2470 x-events:
2471 - name: cart.updated
2472 payload: |-
2473 ```ts
2474 {
2475 id, // The ID of the cart
2476 }
2477 ```
2478 description: Emitted when a cart's details are updated.
2479 deprecated: false
2480 /store/carts/{id}/line-items/{line_id}:
2481 post:
2482 operationId: PostCartsIdLineItemsLine_id
2483 summary: Update a Line Item in a Cart
2484 x-sidebar-summary: Update Line Item
2485 description: Update a line item's details in the cart.
2486 externalDocs:
2487 url: https://docs.medusajs.com/resources/storefront-development/cart/manage-items#update-line-item-in-cart
2488 description: 'Storefront guide: How to update a cart''s line item.'
2489 x-authenticated: false
2490 parameters:
2491 - name: id
2492 in: path
2493 description: The cart's ID.
2494 required: true
2495 schema:
2496 type: string
2497 - name: line_id
2498 in: path
2499 description: The line item's ID.
2500 required: true
2501 schema:
2502 type: string
2503 - name: x-publishable-api-key
2504 in: header
2505 description: Publishable API Key created in the Medusa Admin.
2506 required: true
2507 schema:
2508 type: string
2509 externalDocs:
2510 url: https://docs.medusajs.com/api/store#publishable-api-key
2511 - name: x-medusa-locale
2512 in: header
2513 description: The locale in BCP 47 format to retrieve localized content.
2514 required: false
2515 schema:
2516 type: string
2517 example: en-US
2518 externalDocs:
2519 url: https://docs.medusajs.com/resources/commerce-modules/translation/storefront
2520 description: Learn more in the Serve Translations in Storefront guide.
2521 - name: fields
2522 in: query
2523 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 fields. without prefix it will replace the entire default fields.
2524 required: false
2525 schema:
2526 type: string
2527 title: fields
2528 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 fields. without prefix it will replace the entire default fields.
2529 externalDocs:
2530 url: '#select-fields-and-relations'
2531 - name: locale
2532 in: query
2533 description: The locale in BCP 47 format to retrieve localized content.
2534 required: false
2535 schema:
2536 type: string
2537 example: en-US
2538 externalDocs:
2539 url: https://docs.medusajs.com/resources/commerce-modules/translation/storefront
2540 description: Learn more in the Serve Translations in Storefront guide.
2541 requestBody:
2542 content:
2543 application/json:
2544 schema:
2545 allOf:
2546 - type: object
2547 description: The details to update in the line item.
2548 required:
2549 - quantity
2550 properties:
2551 quantity:
2552 type: number
2553 title: quantity
2554 description: The item's quantity.
2555 metadata:
2556 type: object
2557 description: The item's metadata, can hold custom key-value pairs.
2558 - type: object
2559 description: The details to update in the line item.
2560 properties:
2561 additional_data:
2562 type: object
2563 description: Pass additional custom data to the API route. This data is passed to the underlying workflow under the `additional_data` parameter.
2564 description: The details to update in the line item.
2565 x-codeSamples:
2566 - lang: JavaScript
2567 label: JS SDK
2568 source: |-
2569 import Medusa from "@medusajs/js-sdk"
2570
2571 let MEDUSA_BACKEND_URL = "http://localhost:9000"
2572
2573 if (process.env.NEXT_PUBLIC_MEDUSA_BACKEND_URL) {
2574 MEDUSA_BACKEND_URL = process.env.NEXT_PUBLIC_MEDUSA_BACKEND_URL
2575 }
2576
2577 export const sdk = new Medusa({
2578 baseUrl: MEDUSA_BACKEND_URL,
2579 debug: process.env.NODE_ENV === "development",
2580 publishableKey: process.env.NEXT_PUBLIC_MEDUSA_PUBLISHABLE_KEY,
2581 })
2582
2583 sdk.store.cart.updateLineItem(
2584 "cart_123",
2585 "li_123",
2586 {
2587 quantity: 1
2588 }
2589 )
2590 .then(({ cart }) => {
2591 console.log(cart)
2592 })
2593 - lang: Shell
2594 label: cURL
2595 source: |-
2596 curl -X POST '{backend_url}/store/carts/{id}/line-items/{line_id}' \
2597 -H 'Content-Type: application/json' \
2598 -H 'x-publishable-api-key: {your_publishable_api_key}' \
2599 --data-raw '{
2600 "quantity": 8980402259623936,
2601 "metadata": {}
2602 }'
2603 tags:
2604 - Carts
2605 responses:
2606 '200':
2607 description: OK
2608 content:
2609 application/json:
2610 schema:
2611 $ref: '#/components/schemas/StoreCartResponse'
2612 '400':
2613 $ref: '#/components/responses/400_error'
2614 '401':
2615 $ref: '#/components/responses/unauthorized'
2616 '404':
2617 $ref: '#/components/responses/not_found_error'
2618 '409':
2619 $ref: '#/components/responses/invalid_state_error'
2620 '422':
2621 $ref: '#/components/responses/invalid_request_error'
2622 '500':
2623 $ref: '#/components/responses/500_error'
2624 x-workflow: updateLineItemInCartWorkflow
2625 x-events:
2626 - name: cart.updated
2627 payload: |-
2628 ```ts
2629 {
2630 id, // The ID of the cart
2631 }
2632 ```
2633 description: Emitted when a cart's details are updated.
2634 deprecated: false
2635 delete:
2636 operationId: DeleteCartsIdLineItemsLine_id
2637 summary: Remove Line Item from Cart
2638 x-sidebar-summary: Remove Line Item
2639 description: Remove a line item from a cart.
2640 externalDocs:
2641 url: https://docs.medusajs.com/resources/storefront-development/cart/manage-items#remove-line-item-from-cart
2642 description: 'Storefront guide: How to remove line item from cart.'
2643 x-authenticated: false
2644 parameters:
2645 - name: id
2646 in: path
2647 description: The cart's ID.
2648 required: true
2649 schema:
2650 type: string
2651 - name: line_id
2652 in: path
2653 description: The line item's ID.
2654 required: true
2655 schema:
2656 type: string
2657 - name: x-publishable-api-key
2658 in: header
2659 description: Publishable API Key created in the Medusa Admin.
2660 required: true
2661 schema:
2662 type: string
2663 externalDocs:
2664 url: https://docs.medusajs.com/api/store#publishable-api-key
2665 - name: x-medusa-locale
2666 in: header
2667 description: The locale in BCP 47 format to retrieve localized content.
2668 required: false
2669 schema:
2670 type: string
2671 example: en-US
2672 externalDocs:
2673 url: https://docs.medusajs.com/resources/commerce-modules/translation/storefront
2674 description: Learn more in the Serve Translations in Storefront guide.
2675 - name: fields
2676 in: query
2677 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 fields. without prefix it will replace the entire default fields.
2678 required: false
2679 schema:
2680 type: string
2681 title: fields
2682 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 fields. without prefix it will replace the entire default fields.
2683 externalDocs:
2684 url: '#select-fields-and-relations'
2685 - name: locale
2686 in: query
2687 description: The locale in BCP 47 format to retrieve localized content.
2688 required: false
2689 schema:
2690 type: string
2691 example: en-US
2692 externalDocs:
2693 url: https://docs.medusajs.com/resources/commerce-modules/translation/storefront
2694 description: Learn more in the Serve Translations in Storefront guide.
2695 x-codeSamples:
2696 - lang: JavaScript
2697 label: JS SDK
2698 source: |-
2699 import Medusa from "@medusajs/js-sdk"
2700
2701 let MEDUSA_BACKEND_URL = "http://localhost:9000"
2702
2703 if (process.env.NEXT_PUBLIC_MEDUSA_BACKEND_URL) {
2704 MEDUSA_BACKEND_URL = process.env.NEXT_PUBLIC_MEDUSA_BACKEND_URL
2705 }
2706
2707 export const sdk = new Medusa({
2708 baseUrl: MEDUSA_BACKEND_URL,
2709 debug: process.env.NODE_ENV === "development",
2710 publishableKey: process.env.NEXT_PUBLIC_MEDUSA_PUBLISHABLE_KEY,
2711 })
2712
2713 sdk.store.cart.deleteLineItem(
2714 "cart_123",
2715 "li_123"
2716 )
2717 .then(({ deleted, parent: cart }) => {
2718 console.log(deleted, cart)
2719 })
2720 - lang: Shell
2721 label: cURL
2722 source: |-
2723 curl -X DELETE '{backend_url}/store/carts/{id}/line-items/{line_id}' \
2724 -H 'x-publishable-api-key: {your_publishable_api_key}'
2725 tags:
2726 - Carts
2727 responses:
2728 '200':
2729 description: OK
2730 content:
2731 application/json:
2732 schema:
2733 allOf:
2734 - type: object
2735 description: The deletion's details.
2736 required:
2737 - id
2738 - object
2739 - deleted
2740 properties:
2741 id:
2742 type: string
2743 title: id
2744 description: The ID of the deleted line item.
2745 object:
2746 type: string
2747 title: object
2748 description: The name of the deleted object.
2749 default: line-item
2750 deleted:
2751 type: boolean
2752 title: deleted
2753 description: Whether the item was deleted.
2754 - type: object
2755 description: The deletion's details.
2756 properties:
2757 parent:
2758 $ref: '#/components/schemas/StoreCart'
2759 description: The cart that the item belonged to.
2760 description: The deletion's details.
2761 '400':
2762 $ref: '#/components/responses/400_error'
2763 '401':
2764 $ref: '#/components/responses/unauthorized'
2765 '404':
2766 $ref: '#/components/responses/not_found_error'
2767 '409':
2768 $ref: '#/components/responses/invalid_state_error'
2769 '422':
2770 $ref: '#/components/responses/invalid_request_error'
2771 '500':
2772 $ref: '#/components/responses/500_error'
2773 x-workflow: deleteLineItemsWorkflow
2774 x-events:
2775 - name: cart.updated
2776 payload: |-
2777 ```ts
2778 {
2779 id, // The ID of the cart
2780 }
2781 ```
2782 description: Emitted when a cart's details are updated.
2783 deprecated: false
2784 /store/carts/{id}/promotions:
2785 post:
2786 operationId: PostCartsIdPromotions
2787 summary: Add Promotions to Cart
2788 x-sidebar-summary: Add Promotions
2789 description: Add a list of promotions to a cart.
2790 x-authenticated: false
2791 externalDocs:
2792 url: https://docs.medusajs.com/resources/storefront-development/cart/manage-promotions#add-promotion-to-cart
2793 description: 'Storefront guide: How to add a promotion to cart.'
2794 parameters:
2795 - name: id
2796 in: path
2797 description: The cart's ID.
2798 required: true
2799 schema:
2800 type: string
2801 - name: x-publishable-api-key
2802 in: header
2803 description: Publishable API Key created in the Medusa Admin.
2804 required: true
2805 schema:
2806 type: string
2807 externalDocs:
2808 url: https://docs.medusajs.com/api/store#publishable-api-key
2809 - name: x-medusa-locale
2810 in: header
2811 description: The locale in BCP 47 format to retrieve localized content.
2812 required: false
2813 schema:
2814 type: string
2815 example: en-US
2816 externalDocs:
2817 url: https://docs.medusajs.com/resources/commerce-modules/translation/storefront
2818 description: Learn more in the Serve Translations in Storefront guide.
2819 - name: fields
2820 in: query
2821 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 fields. without prefix it will replace the entire default fields.
2822 required: false
2823 schema:
2824 type: string
2825 title: fields
2826 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 fields. without prefix it will replace the entire default fields.
2827 externalDocs:
2828 url: '#select-fields-and-relations'
2829 - name: locale
2830 in: query
2831 description: The locale in BCP 47 format to retrieve localized content.
2832 required: false
2833 schema:
2834 type: string
2835 example: en-US
2836 externalDocs:
2837 url: https://docs.medusajs.com/resources/commerce-modules/translation/storefront
2838 description: Learn more in the Serve Translations in Storefront guide.
2839 requestBody:
2840 content:
2841 application/json:
2842 schema:
2843 $ref: '#/components/schemas/StoreCartAddPromotion'
2844 x-codeSamples:
2845 - lang: JavaScript
2846 label: JS SDK
2847 source: |-
2848 import Medusa from "@medusajs/js-sdk"
2849
2850 let MEDUSA_BACKEND_URL = "http://localhost:9000"
2851
2852 if (process.env.NEXT_PUBLIC_MEDUSA_BACKEND_URL) {
2853 MEDUSA_BACKEND_URL = process.env.NEXT_PUBLIC_MEDUSA_BACKEND_URL
2854 }
2855
2856 export const sdk = new Medusa({
2857 baseUrl: MEDUSA_BACKEND_URL,
2858 debug: process.env.NODE_ENV === "development",
2859 publishableKey: process.env.NEXT_PUBLIC_MEDUSA_PUBLISHABLE_KEY,
2860 })
2861
2862 sdk.store.cart.addPromotions("cart_123", {
2863 promo_codes: ["20OFF"]
2864 })
2865 .then(({ cart }) => {
2866 console.log(cart)
2867 })
2868 - lang: Shell
2869 label: cURL
2870 source: |-
2871 curl -X POST '{backend_url}/store/carts/{id}/promotions' \
2872 -H 'Content-Type: application/json' \
2873 -H 'x-publishable-api-key: {your_publishable_api_key}' \
2874 --data-raw '{
2875 "promo_codes": [
2876 "{value}"
2877 ]
2878 }'
2879 tags:
2880 - Carts
2881 responses:
2882 '200':
2883 description: OK
2884 content:
2885 application/json:
2886 schema:
2887 $ref: '#/components/schemas/StoreCartResponse'
2888 '400':
2889 $ref: '#/components/responses/400_error'
2890 '401':
2891 $ref: '#/components/responses/unauthorized'
2892 '404':
2893 $ref: '#/components/responses/not_found_error'
2894 '409':
2895 $ref: '#/components/responses/invalid_state_error'
2896 '422':
2897 $ref: '#/components/responses/invalid_request_error'
2898 '500':
2899 $ref: '#/components/responses/500_error'
2900 x-workflow: updateCartPromotionsWorkflow
2901 x-events: []
2902 delete:
2903 operationId: DeleteCartsIdPromotions
2904 summary: Remove Promotions from Cart
2905 description: Remove a list of promotions from a cart.
2906 x-authenticated: false
2907 externalDocs:
2908 url: https://docs.medusajs.com/resources/storefront-development/cart/manage-promotions#remove-promotion-from-cart
2909 description: 'Storefront guide: How to remove a promotion from cart.'
2910 parameters:
2911 - name: id
2912 in: path
2913 description: The cart's ID.
2914 required: true
2915 schema:
2916 type: string
2917 - name: x-publishable-api-key
2918 in: header
2919 description: Publishable API Key created in the Medusa Admin.
2920 required: true
2921 schema:
2922 type: string
2923 externalDocs:
2924 url: https://docs.medusajs.com/api/store#publishable-api-key
2925 - name: x-medusa-locale
2926 in: header
2927 description: The locale in BCP 47 format to retrieve localized content.
2928 required: false
2929 schema:
2930 type: string
2931 example: en-US
2932 externalDocs:
2933 url: https://docs.medusajs.com/resources/commerce-modules/translation/storefront
2934 description: Learn more in the Serve Translations in Storefront guide.
2935 - name: fields
2936 in: query
2937 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 fields. without prefix it will replace the entire default fields.
2938 required: false
2939 schema:
2940 type: string
2941 title: fields
2942 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 fields. without prefix it will replace the entire default fields.
2943 externalDocs:
2944 url: '#select-fields-and-relations'
2945 - name: locale
2946 in: query
2947 description: The locale in BCP 47 format to retrieve localized content.
2948 required: false
2949 schema:
2950 type: string
2951 example: en-US
2952 externalDocs:
2953 url: https://docs.medusajs.com/resources/commerce-modules/translation/storefront
2954 description: Learn more in the Serve Translations in Storefront guide.
2955 x-codeSamples:
2956 - lang: JavaScript
2957 label: JS SDK
2958 source: |-
2959 import Medusa from "@medusajs/js-sdk"
2960
2961 let MEDUSA_BACKEND_URL = "http://localhost:9000"
2962
2963 if (process.env.NEXT_PUBLIC_MEDUSA_BACKEND_URL) {
2964 MEDUSA_BACKEND_URL = process.env.NEXT_PUBLIC_MEDUSA_BACKEND_URL
2965 }
2966
2967 export const sdk = new Medusa({
2968 baseUrl: MEDUSA_BACKEND_URL,
2969 debug: process.env.NODE_ENV === "development",
2970 publishableKey: process.env.NEXT_PUBLIC_MEDUSA_PUBLISHABLE_KEY,
2971 })
2972
2973 sdk.store.cart.removePromotions("cart_123", {
2974 promo_codes: ["20OFF"]
2975 })
2976 .then(({ cart }) => {
2977 console.log(cart)
2978 })
2979 - lang: Shell
2980 label: cURL
2981 source: |-
2982 curl -X DELETE '{backend_url}/store/carts/{id}/promotions' \
2983 -H 'x-publishable-api-key: {your_publishable_api_key}' \
2984 -H 'Content-Type: application/json' \
2985 --data-raw '{
2986 "promo_codes": ["{value}"]
2987 }'
2988 tags:
2989 - Carts
2990 responses:
2991 '200':
2992 description: OK
2993 content:
2994 application/json:
2995 schema:
2996 type: object
2997 description: The cart's details.
2998 required:
2999 - cart
3000 properties:
3001 cart:
3002 $ref: '#/components/schemas/StoreCart'
3003 '400':
3004 $ref: '#/components/responses/400_error'
3005 '401':
3006 $ref: '#/components/responses/unauthorized'
3007 '404':
3008 $ref: '#/components/responses/not_found_error'
3009 '409':
3010 $ref: '#/components/responses/invalid_state_error'
3011 '422':
3012 $ref: '#/components/responses/invalid_request_error'
3013 '500':
3014 $ref: '#/components/responses/500_error'
3015 x-workflow: updateCartPromotionsWorkflow
3016 requestBody:
3017 content:
3018 application/json:
3019 schema:
3020 $ref: '#/components/schemas/StoreCartRemovePromotion'
3021 x-events: []
3022 /store/carts/{id}/shipping-methods:
3023 post:
3024 operationId: PostCartsIdShippingMethods
3025 summary: Add Shipping Method to Cart
3026 description: Add a Shipping Method to a cart
3027 x-authenticated: false
3028 parameters:
3029 - name: id
3030 in: path
3031 description: The cart's ID.
3032 required: true
3033 schema:
3034 type: string
3035 - name: x-publishable-api-key
3036 in: header
3037 description: Publishable API Key created in the Medusa Admin.
3038 required: true
3039 schema:
3040 type: string
3041 externalDocs:
3042 url: https://docs.medusajs.com/api/store#publishable-api-key
3043 - name: x-medusa-locale
3044 in: header
3045 description: The locale in BCP 47 format to retrieve localized content.
3046 required: false
3047 schema:
3048 type: string
3049 example: en-US
3050 externalDocs:
3051 url: https://docs.medusajs.com/resources/commerce-modules/translation/storefront
3052 description: Learn more in the Serve Translations in Storefront guide.
3053 - name: locale
3054 in: query
3055 description: The locale in BCP 47 format to retrieve localized content.
3056 required: false
3057 schema:
3058 type: string
3059 example: en-US
3060 externalDocs:
3061 url: https://docs.medusajs.com/resources/commerce-modules/translation/storefront
3062 description: Learn more in the Serve Translations in Storefront guide.
3063 - name: fields
3064 in: query
3065 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 fields. Without prefix it will replace the entire default fields.
3066 required: false
3067 schema:
3068 type: string
3069 title: fields
3070 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 fields. Without prefix it will replace the entire default fields.
3071 externalDocs:
3072 url: '#select-fields-and-relations'
3073 requestBody:
3074 content:
3075 application/json:
3076 schema:
3077 oneOf:
3078 - allOf:
3079 - $ref: '#/components/schemas/StoreAddCartShippingMethodsBase'
3080 - type: object
3081 description: SUMMARY
3082 properties:
3083 additional_data:
3084 type: object
3085 description: Pass additional custom data to the API route. This data is passed to the underlying workflow under the `additional_data` parameter.
3086 - allOf:
3087 - type: array
3088 description: SUMMARY
3089 items:
3090 $ref: '#/components/schemas/StoreAddCartShippingMethodsBase'
3091 - type: object
3092 description: SUMMARY
3093 properties:
3094 additional_data:
3095 type: object
3096 description: Pass additional custom data to the API route. This data is passed to the underlying workflow under the `additional_data` parameter.
3097 x-codeSamples:
3098 - lang: JavaScript
3099 label: JS SDK
3100 source: |-
3101 import Medusa from "@medusajs/js-sdk"
3102
3103 let MEDUSA_BACKEND_URL = "http://localhost:9000"
3104
3105 if (process.env.NEXT_PUBLIC_MEDUSA_BACKEND_URL) {
3106 MEDUSA_BACKEND_URL = process.env.NEXT_PUBLIC_MEDUSA_BACKEND_URL
3107 }
3108
3109 export const sdk = new Medusa({
3110 baseUrl: MEDUSA_BACKEND_URL,
3111 debug: process.env.NODE_ENV === "development",
3112 publishableKey: process.env.NEXT_PUBLIC_MEDUSA_PUBLISHABLE_KEY,
3113 })
3114
3115 sdk.store.cart.addShippingMethod("cart_123", {
3116 option_id: "so_123",
3117 data: {
3118 // custom data for fulfillment provider.
3119 }
3120 })
3121 .then(({ cart }) => {
3122 console.log(cart)
3123 })
3124 - lang: Shell
3125 label: cURL
3126 source: |-
3127 curl -X POST '{backend_url}/store/carts/{id}/shipping-methods' \
3128 -H 'x-publishable-api-key: {your_publishable_api_key}'
3129 tags:
3130 - Carts
3131 responses:
3132 '200':
3133 description: OK
3134 content:
3135 application/json:
3136 schema:
3137 $ref: '#/components/schemas/StoreCartResponse'
3138 '400':
3139 $ref: '#/components/responses/400_error'
3140 '401':
3141 $ref: '#/components/responses/unauthorized'
3142 '404':
3143 $ref: '#/components/responses/not_found_error'
3144 '409':
3145 $ref: '#/components/responses/invalid_state_error'
3146 '422':
3147 $ref: '#/components/responses/invalid_request_error'
3148 '500':
3149 $ref: '#/components/responses/500_error'
3150 x-workflow: addShippingMethodToCartWorkflow
3151 x-events:
3152 - name: cart.updated
3153 payload: |-
3154 ```ts
3155 {
3156 id, // The ID of the cart
3157 }
3158 ```
3159 description: Emitted when a cart's details are updated.
3160 deprecated: false
3161 /store/carts/{id}/store-credits:
3162 post:
3163 operationId: PostCartsIdStoreCredits
3164 summary: Add Store Credit to Cart
3165 x-sidebar-summary: Add Store Credit
3166 description: Add a Store Credit to a cart
3167 x-authenticated: false
3168 x-ignoreCleanup: true
3169 parameters:
3170 - name: id
3171 in: path
3172 description: The cart's ID.
3173 required: true
3174 schema:
3175 type: string
3176 - name: x-publishable-api-key
3177 in: header
3178 description: Publishable API Key created in the Medusa Admin.
3179 required: true
3180 schema:
3181 type: string
3182 externalDocs:
3183 url: https://docs.medusajs.com/api/store#publishable-api-key
3184 - name: x-medusa-locale
3185 in: header
3186 description: The locale in BCP 47 format to retrieve localized content.
3187 required: false
3188 schema:
3189 type: string
3190 example: en-US
3191 externalDocs:
3192 url: https://docs.medusajs.com/resources/commerce-modules/translation/storefront
3193 description: Learn more in the Serve Translations in Storefront guide.
3194 - name: locale
3195 in: query
3196 description: The locale in BCP 47 format to retrieve localized content.
3197 required: false
3198 schema:
3199 type: string
3200 example: en-US
3201 externalDocs:
3202 url: https://docs.medusajs.com/resources/commerce-modules/translation/storefront
3203 description: Learn more in the Serve Translations in Storefront guide.
3204 requestBody:
3205 content:
3206 application/json:
3207 schema:
3208 $ref: '#/components/schemas/StoreAddStoreCreditsToCart'
3209 x-codeSamples:
3210 - lang: Shell
3211 label: cURL
3212 source: |-
3213 curl -X POST '{backend_url}/store/carts/{id}/store-credits' \
3214 -H 'x-publishable-api-key: {your_publishable_api_key}' \
3215 -H 'Content-Type: application/json' \
3216 --data-raw '{
3217 "amount": 48
3218 }'
3219 tags:
3220 - Carts
3221 responses:
3222 '200':
3223 description: OK
3224 content:
3225 application/json:
3226 schema:
3227 $ref: '#/components/schemas/StoreCartResponse'
3228 '400':
3229 $ref: '#/components/responses/400_error'
3230 '401':
3231 $ref: '#/components/responses/unauthorized'
3232 '404':
3233 $ref: '#/components/responses/not_found_error'
3234 '409':
3235 $ref: '#/components/responses/invalid_state_error'
3236 '422':
3237 $ref: '#/components/responses/invalid_request_error'
3238 '500':
3239 $ref: '#/components/responses/500_error'
3240 x-badges:
3241 - text: Plugin
3242 description: |
3243 This API route is only available through the [Loyalty Plugin](https://docs.medusajs.com/resources/commerce-modules/loyalty).
3244 /store/carts/{id}/taxes:
3245 post:
3246 operationId: PostCartsIdTaxes
3247 summary: Add Tax to Cart
3248 description: Add a Tax to a cart
3249 x-authenticated: false
3250 parameters:
3251 - name: id
3252 in: path
3253 description: The cart's ID.
3254 required: true
3255 schema:
3256 type: string
3257 - name: x-publishable-api-key
3258 in: header
3259 description: Publishable API Key created in the Medusa Admin.
3260 required: true
3261 schema:
3262 type: string
3263 externalDocs:
3264 url: https://docs.medusajs.com/api/store#publishable-api-key
3265 - name: x-medusa-locale
3266 in: header
3267 description: The locale in BCP 47 format to retrieve localized content.
3268 required: false
3269 schema:
3270 type: string
3271 example: en-US
3272 externalDocs:
3273 url: https://docs.medusajs.com/resources/commerce-modules/translation/storefront
3274 description: Learn more in the Serve Translations in Storefront guide.
3275 - name: locale
3276 in: query
3277 description: The locale in BCP 47 format to retrieve localized content.
3278 required: false
3279 schema:
3280 type: string
3281 example: en-US
3282 externalDocs:
3283 url: https://docs.medusajs.com/resources/commerce-modules/translation/storefront
3284 description: Learn more in the Serve Translations in Storefront guide.
3285 - name: fields
3286 in: query
3287 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 fields. Without prefix it will replace the entire default fields.
3288 required: false
3289 schema:
3290 type: string
3291 title: fields
3292 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 fields. Without prefix it will replace the entire default fields.
3293 externalDocs:
3294 url: '#select-fields-and-relations'
3295 x-codeSamples:
3296 - lang: Shell
3297 label: cURL
3298 source: |-
3299 curl -X POST '{backend_url}/store/carts/{id}/taxes' \
3300 -H 'x-publishable-api-key: {your_publishable_api_key}'
3301 tags:
3302 - Carts
3303 responses:
3304 '200':
3305 description: OK
3306 content:
3307 application/json:
3308 schema:
3309 $ref: '#/components/schemas/StoreCartResponse'
3310 '400':
3311 $ref: '#/components/responses/400_error'
3312 '401':
3313 $ref: '#/components/responses/unauthorized'
3314 '404':
3315 $ref: '#/components/responses/not_found_error'
3316 '409':
3317 $ref: '#/components/responses/invalid_state_error'
3318 '422':
3319 $ref: '#/components/responses/invalid_request_error'
3320 '500':
3321 $ref: '#/components/responses/500_error'
3322 x-workflow: updateTaxLinesWorkflow
3323 x-events: []
3324 /store/collections:
3325 get:
3326 operationId: GetCollections
3327 summary: List Collections
3328 description: Retrieve a list of collections. The collections can be filtered by fields such as `handle`. The collections can also be sorted or paginated.
3329 x-authenticated: false
3330 externalDocs:
3331 url: https://docs.medusajs.com/resources/storefront-development/products/collections/list
3332 description: 'Storefront guide: How to retrieve a list of collections.'
3333 parameters:
3334 - name: x-publishable-api-key
3335 in: header
3336 description: Publishable API Key created in the Medusa Admin.
3337 required: true
3338 schema:
3339 type: string
3340 externalDocs:
3341 url: https://docs.medusajs.com/api/store#publishable-api-key
3342 - name: x-medusa-locale
3343 in: header
3344 description: The locale in BCP 47 format to retrieve localized content.
3345 required: false
3346 schema:
3347 type: string
3348 example: en-US
3349 externalDocs:
3350 url: https://docs.medusajs.com/resources/commerce-modules/translation/storefront
3351 description: Learn more in the Serve Translations in Storefront guide.
3352 - name: fields
3353 in: query
3354 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 fields. without prefix it will replace the entire default fields.
3355 required: false
3356 schema:
3357 type: string
3358 title: fields
3359 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 fields. without prefix it will replace the entire default fields.
3360 externalDocs:
3361 url: '#select-fields-and-relations'
3362 - name: offset
3363 in: query
3364 description: The number of items to skip when retrieving a list.
3365 required: false
3366 schema:
3367 type: number
3368 title: offset
3369 description: The number of items to skip when retrieving a list.
3370 externalDocs:
3371 url: '#pagination'
3372 - name: limit
3373 in: query
3374 description: Limit the number of items returned in the list.
3375 required: false
3376 schema:
3377 type: number
3378 title: limit
3379 description: Limit the number of items returned in the list.
3380 externalDocs:
3381 url: '#pagination'
3382 - name: order
3383 in: query
3384 description: The field to sort the data by. By default, the sort order is ascending. To change the order to descending, prefix the field name with `-`.
3385 required: false
3386 schema:
3387 type: string
3388 title: order
3389 description: The field to sort the data by. By default, the sort order is ascending. To change the order to descending, prefix the field name with `-`.
3390 - name: title
3391 in: query
3392 required: false
3393 schema:
3394 oneOf:
3395 - type: string
3396 title: title
3397 description: Filter by a collection's title.
3398 - type: array
3399 description: Filter by collection titles.
3400 items:
3401 type: string
3402 title: title
3403 description: A title.
3404 - name: created_at
3405 in: query
3406 description: Filter by the collection's creation date.
3407 required: false
3408 schema:
3409 type: object
3410 description: Filter by the collection's creation date.
3411 properties:
3412 $and:
3413 type: array
3414 description: Join query parameters with an AND condition. Each object's content is the same type as the expected query parameters.
3415 items:
3416 type: object
3417 title: $and
3418 $or:
3419 type: array
3420 description: Join query parameters with an OR condition. Each object's content is the same type as the expected query parameters.
3421 items:
3422 type: object
3423 title: $or
3424 $eq:
3425 oneOf:
3426 - type: string
3427 title: $eq
3428 description: Filter by an exact match.
3429 - type: array
3430 description: Filter by multiple exact matches.
3431 items:
3432 type: string
3433 title: $eq
3434 description: An exact match.
3435 $ne:
3436 type: string
3437 title: $ne
3438 description: Filter by values not equal to this parameter.
3439 $in:
3440 type: array
3441 description: Filter by values in this array.
3442 items:
3443 type: string
3444 title: $in
3445 description: The value to match.
3446 $nin:
3447 type: array
3448 description: Filter by values not in this array.
3449 items:
3450 type: string
3451 title: $nin
3452 description: The value not to match.
3453 $not:
3454 oneOf:
3455 - type: string
3456 title: $not
3457 description: Filter by values not matching this parameter.
3458 - type: object
3459 description: Filter by values not matching the conditions in this parameter.
3460 properties:
3461 $and:
3462 type: array
3463 description: Join query parameters with an AND condition. Each object's content is the same type as the expected query parameters.
3464 items:
3465 type: object
3466 title: $and
3467 $or:
3468 type: array
3469 description: Join query parameters with an OR condition. Each object's content is the same type as the expected query parameters.
3470 items:
3471 type: object
3472 title: $or
3473 $eq:
3474 oneOf:
3475 - type: string
3476 title: $eq
3477 description: Filter by an exact match.
3478 - type: array
3479 description: Filter by multiple exact matches.
3480 items:
3481 type: string
3482 title: $eq
3483 description: The value to match.
3484 $ne:
3485 type: string
3486 title: $ne
3487 description: Filter by values not matching this parameter.
3488 $in:
3489 type: array
3490 description: Filter by values in this array.
3491 items:
3492 type: string
3493 title: $in
3494 description: The value to match.
3495 $nin:
3496 type: array
3497 description: Filter by values not in this array.
3498 items:
3499 type: string
3500 title: $nin
3501 description: The value to not match
3502 $not:
3503 oneOf:
3504 - type: string
3505 title: $not
3506 description: Filter by values not matching this parameter
3507 - type: object
3508 description: Filter by values not matching the conditions in this parameter.
3509 - type: array
3510 description: Filter by values not matching the values of this parameter.
3511 items:
3512 type: string
3513 title: $not
3514 description: The values to not match.
3515 $gt:
3516 type: string
3517 title: $gt
3518 description: Filter by values greater than this parameter. Useful for numbers and dates only.
3519 $gte:
3520 type: string
3521 title: $gte
3522 description: Filter by values greater than or equal to this parameter. Useful for numbers and dates only.
3523 $lt:
3524 type: string
3525 title: $lt
3526 description: Filter by values less than this parameter. Useful for numbers and dates only.
3527 $lte:
3528 type: string
3529 title: $lte
3530 description: Filter by values less than or equal to this parameter. Useful for numbers and dates only.
3531 $like:
3532 type: string
3533 title: $like
3534 description: Apply a `like` filter. Useful for strings only.
3535 $re:
3536 type: string
3537 title: $re
3538 description: Apply a regex filter. Useful for strings only.
3539 $ilike:
3540 type: string
3541 title: $ilike
3542 description: Apply a case-insensitive `like` filter. Useful for strings only.
3543 $fulltext:
3544 type: string
3545 title: $fulltext
3546 description: Filter to apply on full-text properties.
3547 $overlap:
3548 type: array
3549 description: Filter arrays that have overlapping values with this parameter.
3550 items:
3551 type: string
3552 title: $overlap
3553 description: The value to match.
3554 $contains:
3555 type: array
3556 description: Filter arrays that contain some of the values of this parameter.
3557 items:
3558 type: string
3559 title: $contains
3560 description: The values to match.
3561 $contained:
3562 type: array
3563 description: Filter arrays that contain all values of this parameter.
3564 items:
3565 type: string
3566 title: $contained
3567 description: The values to match.
3568 $exists:
3569 type: boolean
3570 title: $exists
3571 description: Filter by whether a value for this parameter exists (not `null`).
3572 - type: array
3573 description: Filter by values not matching those in this parameter.
3574 items:
3575 type: string
3576 title: $not
3577 description: The values to not match.
3578 $gt:
3579 type: string
3580 title: $gt
3581 description: Filter by values greater than this parameter. Useful for numbers and dates only.
3582 $gte:
3583 type: string
3584 title: $gte
3585 description: Filter by values greater than or equal to this parameter. Useful for numbers and dates only.
3586 $lt:
3587 type: string
3588 title: $lt
3589 description: Filter by values less than this parameter. Useful for numbers and dates only.
3590 $lte:
3591 type: string
3592 title: $lte
3593 description: Filter by values less than or equal to this parameter. Useful for numbers and dates only.
3594 $like:
3595 type: string
3596 title: $like
3597 description: Apply a `like` filter. Useful for strings only.
3598 $re:
3599 type: string
3600 title: $re
3601 description: Apply a regex filter. Useful for strings only.
3602 $ilike:
3603 type: string
3604 title: $ilike
3605 description: Apply a case-insensitive `like` filter. Useful for strings only.
3606 $fulltext:
3607 type: string
3608 title: $fulltext
3609 description: Filter to apply on full-text properties.
3610 $overlap:
3611 type: array
3612 description: Filter arrays that have overlapping values with this parameter.
3613 items:
3614 type: string
3615 title: $overlap
3616 description: The values to match.
3617 $contains:
3618 type: array
3619 description: Filter arrays that contain some of the values of this parameter.
3620 items:
3621 type: string
3622 title: $contains
3623 description: The values to match.
3624 $contained:
3625 type: array
3626 description: Filter arrays that contain all values of this parameter.
3627 items:
3628 type: string
3629 title: $contained
3630 description: The values to match.
3631 $exists:
3632 type: boolean
3633 title: $exists
3634 description: Filter by whether a value for this parameter exists (not `null`).
3635 title: created_at
3636 - name: updated_at
3637 in: query
3638 description: Filter by the collection's update date.
3639 required: false
3640 schema:
3641 type: object
3642 description: Filter by the collection's update date.
3643 properties:
3644 $and:
3645 type: array
3646 description: Join query parameters with an AND condition. Each object's content is the same type as the expected query parameters.
3647 items:
3648 type: object
3649 title: $and
3650 $or:
3651 type: array
3652 description: Join query parameters with an OR condition. Each object's content is the same type as the expected query parameters.
3653 items:
3654 type: object
3655 title: $or
3656 $eq:
3657 oneOf:
3658 - type: string
3659 title: $eq
3660 description: Filter by an exact match.
3661 - type: array
3662 description: Filter by multiple exact matches.
3663 items:
3664 type: string
3665 title: $eq
3666 description: An exact match.
3667 $ne:
3668 type: string
3669 title: $ne
3670 description: Filter by values not equal to this parameter.
3671 $in:
3672 type: array
3673 description: Filter by values in this array.
3674 items:
3675 type: string
3676 title: $in
3677 description: The value to match.
3678 $nin:
3679 type: array
3680 description: Filter by values not in this array.
3681 items:
3682 type: string
3683 title: $nin
3684 description: The value not to match.
3685 $not:
3686 oneOf:
3687 - type: string
3688 title: $not
3689 description: Filter by values not matching this parameter.
3690 - type: object
3691 description: Filter by values not matching the conditions in this parameter.
3692 properties:
3693 $and:
3694 type: array
3695 description: Join query parameters with an AND condition. Each object's content is the same type as the expected query parameters.
3696 items:
3697 type: object
3698 title: $and
3699 $or:
3700 type: array
3701 description: Join query parameters with an OR condition. Each object's content is the same type as the expected query parameters.
3702 items:
3703 type: object
3704 title: $or
3705 $eq:
3706 oneOf:
3707 - type: string
3708 title: $eq
3709 description: Filter by an exact match.
3710 - type: array
3711 description: Filter by multiple exact matches.
3712 items:
3713 type: string
3714 title: $eq
3715 description: The value to match.
3716 $ne:
3717 type: string
3718 title: $ne
3719 description: Filter by values not matching this parameter.
3720 $in:
3721 type: array
3722 description: Filter by values in this array.
3723 items:
3724 type: string
3725 title: $in
3726 description: The value to match.
3727 $nin:
3728 type: array
3729 description: Filter by values not in this array.
3730 items:
3731 type: string
3732 title: $nin
3733 description: The value to not match
3734 $not:
3735 oneOf:
3736 - type: string
3737 title: $not
3738 description: Filter by values not matching this parameter
3739 - type: object
3740 description: Filter by values not matching the conditions in this parameter.
3741 - type: array
3742 description: Filter by values not matching the values of this parameter.
3743 items:
3744 type: string
3745 title: $not
3746 description: The values to not match.
3747 $gt:
3748 type: string
3749 title: $gt
3750 description: Filter by values greater than this parameter. Useful for numbers and dates only.
3751 $gte:
3752 type: string
3753 title: $gte
3754 description: Filter by values greater than or equal to this parameter. Useful for numbers and dates only.
3755 $lt:
3756 type: string
3757 title: $lt
3758 description: Filter by values less than this parameter. Useful for numbers and dates only.
3759 $lte:
3760 type: string
3761 title: $lte
3762 description: Filter by values less than or equal to this parameter. Useful for numbers and dates only.
3763 $like:
3764 type: string
3765 title: $like
3766 description: Apply a `like` filter. Useful for strings only.
3767 $re:
3768 type: string
3769 title: $re
3770 description: Apply a regex filter. Useful for strings only.
3771 $ilike:
3772 type: string
3773 title: $ilike
3774 description: Apply a case-insensitive `like` filter. Useful for strings only.
3775 $fulltext:
3776 type: string
3777 title: $fulltext
3778 description: Filter to apply on full-text properties.
3779 $overlap:
3780 type: array
3781 description: Filter arrays that have overlapping values with this parameter.
3782 items:
3783 type: string
3784 title: $overlap
3785 description: The value to match.
3786 $contains:
3787 type: array
3788 description: Filter arrays that contain some of the values of this parameter.
3789 items:
3790 type: string
3791 title: $contains
3792 description: The values to match.
3793 $contained:
3794 type: array
3795 description: Filter arrays that contain all values of this parameter.
3796 items:
3797 type: string
3798 title: $contained
3799 description: The values to match.
3800 $exists:
3801 type: boolean
3802 title: $exists
3803 description: Filter by whether a value for this parameter exists (not `null`).
3804 - type: array
3805 description: Filter by values not matching those in this parameter.
3806 items:
3807 type: string
3808 title: $not
3809 description: The values to not match.
3810 $gt:
3811 type: string
3812 title: $gt
3813 description: Filter by values greater than this parameter. Useful for numbers and dates only.
3814 $gte:
3815 type: string
3816 title: $gte
3817 description: Filter by values greater than or equal to this parameter. Useful for numbers and dates only.
3818 $lt:
3819 type: string
3820 title: $lt
3821 description: Filter by values less than this parameter. Useful for numbers and dates only.
3822 $lte:
3823 type: string
3824 title: $lte
3825 description: Filter by values less than or equal to this parameter. Useful for numbers and dates only.
3826 $like:
3827 type: string
3828 title: $like
3829 description: Apply a `like` filter. Useful for strings only.
3830 $re:
3831 type: string
3832 title: $re
3833 description: Apply a regex filter. Useful for strings only.
3834 $ilike:
3835 type: string
3836 title: $ilike
3837 description: Apply a case-insensitive `like` filter. Useful for strings only.
3838 $fulltext:
3839 type: string
3840 title: $fulltext
3841 description: Filter to apply on full-text properties.
3842 $overlap:
3843 type: array
3844 description: Filter arrays that have overlapping values with this parameter.
3845 items:
3846 type: string
3847 title: $overlap
3848 description: The values to match.
3849 $contains:
3850 type: array
3851 description: Filter arrays that contain some of the values of this parameter.
3852 items:
3853 type: string
3854 title: $contains
3855 description: The values to match.
3856 $contained:
3857 type: array
3858 description: Filter arrays that contain all values of this parameter.
3859 items:
3860 type: string
3861 title: $contained
3862 description: The values to match.
3863 $exists:
3864 type: boolean
3865 title: $exists
3866 description: Filter by whether a value for this parameter exists (not `null`).
3867 title: updated_at
3868 - name: handle
3869 in: query
3870 required: false
3871 schema:
3872 oneOf:
3873 - type: string
3874 title: handle
3875 description: Filter by a collection's handle.
3876 - type: array
3877 description: Filter by collection handles.
3878 items:
3879 type: string
3880 title: handle
3881 description: A handle.
3882 - name: q
3883 in: query
3884 description: Search term to filter the collection's searchable properties.
3885 required: false
3886 schema:
3887 type: string
3888 title: q
3889 description: Search term to filter the collection's searchable properties.
3890 - name: $and
3891 in: query
3892 description: Join query parameters with an AND condition. Each object's content is the same type as the expected query parameters.
3893 required: false
3894 schema:
3895 type: array
3896 description: Join query parameters with an AND condition. Each object's content is the same type as the expected query parameters.
3897 items:
3898 type: object
3899 title: $and
3900 - name: $or
3901 in: query
3902 description: Join query parameters with an OR condition. Each object's content is the same type as the expected query parameters.
3903 required: false
3904 schema:
3905 type: array
3906 description: Join query parameters with an OR condition. Each object's content is the same type as the expected query parameters.
3907 items:
3908 type: object
3909 title: $or
3910 - name: with_deleted
3911 in: query
3912 description: Whether to include deleted records in the result.
3913 required: false
3914 schema:
3915 type: boolean
3916 title: with_deleted
3917 description: Whether to include deleted records in the result.
3918 - name: id
3919 in: query
3920 required: false
3921 schema:
3922 oneOf:
3923 - type: string
3924 title: id
3925 description: Filter by a collection's ID.
3926 - type: array
3927 description: Filter by collection IDs.
3928 items:
3929 type: string
3930 title: id
3931 description: The collection's ID.
3932 - name: locale
3933 in: query
3934 description: The locale in BCP 47 format to retrieve localized content.
3935 required: false
3936 schema:
3937 type: string
3938 example: en-US
3939 externalDocs:
3940 url: https://docs.medusajs.com/resources/commerce-modules/translation/storefront
3941 description: Learn more in the Serve Translations in Storefront guide.
3942 - name: external_id
3943 in: query
3944 required: false
3945 schema:
3946 oneOf:
3947 - type: string
3948 title: external_id
3949 description: Filter by a collection's external id.
3950 - type: array
3951 description: Filter by collection external ids.
3952 items:
3953 type: string
3954 title: external_id
3955 description: A collection's external id.
3956 x-codeSamples:
3957 - lang: JavaScript
3958 label: JS SDK
3959 source: |-
3960 import Medusa from "@medusajs/js-sdk"
3961
3962 let MEDUSA_BACKEND_URL = "http://localhost:9000"
3963
3964 if (process.env.NEXT_PUBLIC_MEDUSA_BACKEND_URL) {
3965 MEDUSA_BACKEND_URL = process.env.NEXT_PUBLIC_MEDUSA_BACKEND_URL
3966 }
3967
3968 export const sdk = new Medusa({
3969 baseUrl: MEDUSA_BACKEND_URL,
3970 debug: process.env.NODE_ENV === "development",
3971 publishableKey: process.env.NEXT_PUBLIC_MEDUSA_PUBLISHABLE_KEY,
3972 })
3973
3974 sdk.store.collection.list()
3975 .then(({ collections, count, limit, offset }) => {
3976 console.log(collections)
3977 })
3978 - lang: Shell
3979 label: cURL
3980 source: |-
3981 curl '{backend_url}/store/collections' \
3982 -H 'x-publishable-api-key: {your_publishable_api_key}'
3983 tags:
3984 - Collections
3985 responses:
3986 '200':
3987 description: OK
3988 content:
3989 application/json:
3990 schema:
3991 allOf:
3992 - type: object
3993 description: The paginated list of collections.
3994 required:
3995 - limit
3996 - offset
3997 - count
3998 properties:
3999 limit:
4000 type: number
4001 title: limit
4002 description: The maximum number of items returned.
4003 offset:
4004 type: number
4005 title: offset
4006 description: The number of items skipped before retrieving the returned items.
4007 count:
4008 type: number
4009 title: count
4010 description: The total number of items.
4011 - type: object
4012 description: The paginated list of collections.
4013 required:
4014 - collections
4015 properties:
4016 collections:
4017 type: array
4018 description: The collection's collections.
4019 items:
4020 $ref: '#/components/schemas/StoreCollection'
4021 '400':
4022 $ref: '#/components/responses/400_error'
4023 '401':
4024 $ref: '#/components/responses/unauthorized'
4025 '404':
4026 $ref: '#/components/responses/not_found_error'
4027 '409':
4028 $ref: '#/components/responses/invalid_state_error'
4029 '422':
4030 $ref: '#/components/responses/invalid_request_error'
4031 '500':
4032 $ref: '#/components/responses/500_error'
4033 /store/collections/{id}:
4034 get:
4035 operationId: GetCollectionsId
4036 summary: Get a Collection
4037 description: Retrieve a collection by its ID. You can expand the collection's relations or select the fields that should be returned.
4038 x-authenticated: false
4039 externalDocs:
4040 url: https://docs.medusajs.com/resources/storefront-development/products/collections/retrieve
4041 description: 'Storefront guide: How to retrieve a collection.'
4042 parameters:
4043 - name: id
4044 in: path
4045 description: The collection's ID.
4046 required: true
4047 schema:
4048 type: string
4049 - name: x-publishable-api-key
4050 in: header
4051 description: Publishable API Key created in the Medusa Admin.
4052 required: true
4053 schema:
4054 type: string
4055 externalDocs:
4056 url: https://docs.medusajs.com/api/store#publishable-api-key
4057 - name: x-medusa-locale
4058 in: header
4059 description: The locale in BCP 47 format to retrieve localized content.
4060 required: false
4061 schema:
4062 type: string
4063 example: en-US
4064 externalDocs:
4065 url: https://docs.medusajs.com/resources/commerce-modules/translation/storefront
4066 description: Learn more in the Serve Translations in Storefront guide.
4067 - name: fields
4068 in: query
4069 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 fields. without prefix it will replace the entire default fields.
4070 required: false
4071 schema:
4072 type: string
4073 title: fields
4074 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 fields. without prefix it will replace the entire default fields.
4075 externalDocs:
4076 url: '#select-fields-and-relations'
4077 - name: locale
4078 in: query
4079 description: The locale in BCP 47 format to retrieve localized content.
4080 required: false
4081 schema:
4082 type: string
4083 example: en-US
4084 externalDocs:
4085 url: https://docs.medusajs.com/resources/commerce-modules/translation/storefront
4086 description: Learn more in the Serve Translations in Storefront guide.
4087 x-codeSamples:
4088 - lang: JavaScript
4089 label: JS SDK
4090 source: |-
4091 import Medusa from "@medusajs/js-sdk"
4092
4093 let MEDUSA_BACKEND_URL = "http://localhost:9000"
4094
4095 if (process.env.NEXT_PUBLIC_MEDUSA_BACKEND_URL) {
4096 MEDUSA_BACKEND_URL = process.env.NEXT_PUBLIC_MEDUSA_BACKEND_URL
4097 }
4098
4099 export const sdk = new Medusa({
4100 baseUrl: MEDUSA_BACKEND_URL,
4101 debug: process.env.NODE_ENV === "development",
4102 publishableKey: process.env.NEXT_PUBLIC_MEDUSA_PUBLISHABLE_KEY,
4103 })
4104
4105 sdk.store.collection.retrieve("pcol_123")
4106 .then(({ collection }) => {
4107 console.log(collection)
4108 })
4109 - lang: Shell
4110 label: cURL
4111 source: |-
4112 curl '{backend_url}/store/collections/{id}' \
4113 -H 'x-publishable-api-key: {your_publishable_api_key}'
4114 tags:
4115 - Collections
4116 responses:
4117 '200':
4118 description: OK
4119 content:
4120 application/json:
4121 schema:
4122 $ref: '#/components/schemas/StoreCollectionResponse'
4123 '400':
4124 $ref: '#/components/responses/400_error'
4125 '401':
4126 $ref: '#/components/responses/unauthorized'
4127 '404':
4128 $ref: '#/components/responses/not_found_error'
4129 '409':
4130 $ref: '#/components/responses/invalid_state_error'
4131 '422':
4132 $ref: '#/components/responses/invalid_request_error'
4133 '500':
4134 $ref: '#/components/responses/500_error'
4135 /store/currencies:
4136 get:
4137 operationId: GetCurrencies
4138 summary: List Currencies
4139 description: Retrieve a list of currencies. The currencies can be filtered by fields such as `code`. The currencies can also be sorted or paginated.
4140 x-authenticated: false
4141 parameters:
4142 - name: x-publishable-api-key
4143 in: header
4144 description: Publishable API Key created in the Medusa Admin.
4145 required: true
4146 schema:
4147 type: string
4148 externalDocs:
4149 url: https://docs.medusajs.com/api/store#publishable-api-key
4150 - name: x-medusa-locale
4151 in: header
4152 description: The locale in BCP 47 format to retrieve localized content.
4153 required: false
4154 schema:
4155 type: string
4156 example: en-US
4157 externalDocs:
4158 url: https://docs.medusajs.com/resources/commerce-modules/translation/storefront
4159 description: Learn more in the Serve Translations in Storefront guide.
4160 - name: fields
4161 in: query
4162 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 fields. without prefix it will replace the entire default fields.
4163 required: false
4164 schema:
4165 type: string
4166 title: fields
4167 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 fields. without prefix it will replace the entire default fields.
4168 externalDocs:
4169 url: '#select-fields-and-relations'
4170 - name: offset
4171 in: query
4172 description: The number of items to skip when retrieving a list.
4173 required: false
4174 schema:
4175 type: number
4176 title: offset
4177 description: The number of items to skip when retrieving a list.
4178 externalDocs:
4179 url: '#pagination'
4180 - name: limit
4181 in: query
4182 description: Limit the number of items returned in the list.
4183 required: false
4184 schema:
4185 type: number
4186 title: limit
4187 description: Limit the number of items returned in the list.
4188 externalDocs:
4189 url: '#pagination'
4190 - name: order
4191 in: query
4192 description: The field to sort the data by. By default, the sort order is ascending. To change the order to descending, prefix the field name with `-`.
4193 required: false
4194 schema:
4195 type: string
4196 title: order
4197 description: The field to sort the data by. By default, the sort order is ascending. To change the order to descending, prefix the field name with `-`.
4198 - name: q
4199 in: query
4200 description: Search term to filter the currency's searchable properties.
4201 required: false
4202 schema:
4203 type: string
4204 title: q
4205 description: Search term to filter the currency's searchable properties.
4206 - name: code
4207 in: query
4208 required: false
4209 schema:
4210 oneOf:
4211 - type: string
4212 title: code
4213 description: Filter by a currency code.
4214 - type: array
4215 description: Filter by currency codes.
4216 items:
4217 type: string
4218 title: code
4219 description: A currency code.
4220 - name: $and
4221 in: query
4222 description: Join query parameters with an AND condition. Each object's content is the same type as the expected query parameters.
4223 required: false
4224 schema:
4225 type: array
4226 description: Join query parameters with an AND condition. Each object's content is the same type as the expected query parameters.
4227 items:
4228 type: object
4229 title: $and
4230 - name: $or
4231 in: query
4232 description: Join query parameters with an OR condition. Each object's content is the same type as the expected query parameters.
4233 required: false
4234 schema:
4235 type: array
4236 description: Join query parameters with an OR condition. Each object's content is the same type as the expected query parameters.
4237 items:
4238 type: object
4239 title: $or
4240 - name: with_deleted
4241 in: query
4242 description: Whether to include deleted records in the result.
4243 required: false
4244 schema:
4245 type: boolean
4246 title: with_deleted
4247 description: Whether to include deleted records in the result.
4248 - name: locale
4249 in: query
4250 description: The locale in BCP 47 format to retrieve localized content.
4251 required: false
4252 schema:
4253 type: string
4254 example: en-US
4255 externalDocs:
4256 url: https://docs.medusajs.com/resources/commerce-modules/translation/storefront
4257 description: Learn more in the Serve Translations in Storefront guide.
4258 x-codeSamples:
4259 - lang: Shell
4260 label: cURL
4261 source: |-
4262 curl '{backend_url}/store/currencies' \
4263 -H 'x-publishable-api-key: {your_publishable_api_key}'
4264 tags:
4265 - Currencies
4266 responses:
4267 '200':
4268 description: OK
4269 content:
4270 application/json:
4271 schema:
4272 $ref: '#/components/schemas/StoreCurrencyListResponse'
4273 '400':
4274 $ref: '#/components/responses/400_error'
4275 '401':
4276 $ref: '#/components/responses/unauthorized'
4277 '404':
4278 $ref: '#/components/responses/not_found_error'
4279 '409':
4280 $ref: '#/components/responses/invalid_state_error'
4281 '422':
4282 $ref: '#/components/responses/invalid_request_error'
4283 '500':
4284 $ref: '#/components/responses/500_error'
4285 /store/currencies/{code}:
4286 get:
4287 operationId: GetCurrenciesCode
4288 summary: Get a Currency
4289 description: Retrieve a currency by its code. You can expand the currency's relations or select the fields that should be returned.
4290 x-authenticated: false
4291 parameters:
4292 - name: code
4293 in: path
4294 description: The currency's code.
4295 required: true
4296 schema:
4297 type: string
4298 - name: x-publishable-api-key
4299 in: header
4300 description: Publishable API Key created in the Medusa Admin.
4301 required: true
4302 schema:
4303 type: string
4304 externalDocs:
4305 url: https://docs.medusajs.com/api/store#publishable-api-key
4306 - name: x-medusa-locale
4307 in: header
4308 description: The locale in BCP 47 format to retrieve localized content.
4309 required: false
4310 schema:
4311 type: string
4312 example: en-US
4313 externalDocs:
4314 url: https://docs.medusajs.com/resources/commerce-modules/translation/storefront
4315 description: Learn more in the Serve Translations in Storefront guide.
4316 - name: fields
4317 in: query
4318 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 fields. without prefix it will replace the entire default fields.
4319 required: false
4320 schema:
4321 type: string
4322 title: fields
4323 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 fields. without prefix it will replace the entire default fields.
4324 externalDocs:
4325 url: '#select-fields-and-relations'
4326 - name: locale
4327 in: query
4328 description: The locale in BCP 47 format to retrieve localized content.
4329 required: false
4330 schema:
4331 type: string
4332 example: en-US
4333 externalDocs:
4334 url: https://docs.medusajs.com/resources/commerce-modules/translation/storefront
4335 description: Learn more in the Serve Translations in Storefront guide.
4336 x-codeSamples:
4337 - lang: Shell
4338 label: cURL
4339 source: |-
4340 curl '{backend_url}/store/currencies/{code}' \
4341 -H 'x-publishable-api-key: {your_publishable_api_key}'
4342 tags:
4343 - Currencies
4344 responses:
4345 '200':
4346 description: OK
4347 content:
4348 application/json:
4349 schema:
4350 $ref: '#/components/schemas/StoreCurrencyResponse'
4351 '400':
4352 $ref: '#/components/responses/400_error'
4353 '401':
4354 $ref: '#/components/responses/unauthorized'
4355 '404':
4356 $ref: '#/components/responses/not_found_error'
4357 '409':
4358 $ref: '#/components/responses/invalid_state_error'
4359 '422':
4360 $ref: '#/components/responses/invalid_request_error'
4361 '500':
4362 $ref: '#/components/responses/500_error'
4363 /store/customers:
4364 post:
4365 operationId: PostCustomers
4366 summary: Register Customer
4367 description: Register a customer. Use the `/auth/customer/emailpass/register` API route first to retrieve the registration token and pass it in the header of the request.
4368 externalDocs:
4369 url: https://docs.medusajs.com/resources/storefront-development/customers/register
4370 description: 'Storefront guide: How to register a customer.'
4371 x-authenticated: true
4372 parameters:
4373 - name: x-publishable-api-key
4374 in: header
4375 description: Publishable API Key created in the Medusa Admin.
4376 required: true
4377 schema:
4378 type: string
4379 externalDocs:
4380 url: https://docs.medusajs.com/api/store#publishable-api-key
4381 - name: x-medusa-locale
4382 in: header
4383 description: The locale in BCP 47 format to retrieve localized content.
4384 required: false
4385 schema:
4386 type: string
4387 example: en-US
4388 externalDocs:
4389 url: https://docs.medusajs.com/resources/commerce-modules/translation/storefront
4390 description: Learn more in the Serve Translations in Storefront guide.
4391 - name: fields
4392 in: query
4393 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 fields. without prefix it will replace the entire default fields.
4394 required: false
4395 schema:
4396 type: string
4397 title: fields
4398 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 fields. without prefix it will replace the entire default fields. This API route restricts the fields that can be selected. Learn how to override the retrievable fields in the [Retrieve Custom Links](https://docs.medusajs.com/learn/fundamentals/api-routes/retrieve-custom-links) documentation.
4399 externalDocs:
4400 url: '#select-fields-and-relations'
4401 - name: locale
4402 in: query
4403 description: The locale in BCP 47 format to retrieve localized content.
4404 required: false
4405 schema:
4406 type: string
4407 example: en-US
4408 externalDocs:
4409 url: https://docs.medusajs.com/resources/commerce-modules/translation/storefront
4410 description: Learn more in the Serve Translations in Storefront guide.
4411 requestBody:
4412 content:
4413 application/json:
4414 schema:
4415 $ref: '#/components/schemas/StoreCreateCustomer'
4416 x-codeSamples:
4417 - lang: JavaScript
4418 label: JS SDK
4419 source: |-
4420 import Medusa from "@medusajs/js-sdk"
4421
4422 let MEDUSA_BACKEND_URL = "http://localhost:9000"
4423
4424 if (process.env.NEXT_PUBLIC_MEDUSA_BACKEND_URL) {
4425 MEDUSA_BACKEND_URL = process.env.NEXT_PUBLIC_MEDUSA_BACKEND_URL
4426 }
4427
4428 export const sdk = new Medusa({
4429 baseUrl: MEDUSA_BACKEND_URL,
4430 debug: process.env.NODE_ENV === "development",
4431 publishableKey: process.env.NEXT_PUBLIC_MEDUSA_PUBLISHABLE_KEY,
4432 })
4433
4434 const token = await sdk.auth.register("customer", "emailpass", {
4435 "email": "customer@gmail.com",
4436 "password": "supersecret"
4437 })
4438
4439 sdk.store.customer.create(
4440 {
4441 "email": "customer@gmail.com"
4442 },
4443 {},
4444 {
4445 Authorization: `Bearer ${token}`
4446 }
4447 )
4448 .then(({ customer }) => {
4449 console.log(customer)
4450 })
4451 - lang: Shell
4452 label: cURL
4453 source: |-
4454 curl -X POST '{backend_url}/store/customers' \
4455 -H 'Authorization: Bearer {token}' \
4456 -H 'Content-Type: application/json' \
4457 -H 'x-publishable-api-key: {your_publishable_api_key}' \
4458 --data-raw '{
4459 "email": "Monserrate.Leannon88@yahoo.com",
4460 "company_name": "{value}",
4461 "first_name": "{value}",
4462 "last_name": "{value}",
4463 "phone": "{value}"
4464 }'
4465 tags:
4466 - Customers
4467 responses:
4468 '200':
4469 description: OK
4470 content:
4471 application/json:
4472 schema:
4473 $ref: '#/components/schemas/StoreCustomerResponse'
4474 '400':
4475 $ref: '#/components/responses/400_error'
4476 '401':
4477 $ref: '#/components/responses/unauthorized'
4478 '404':
4479 $ref: '#/components/responses/not_found_error'
4480 '409':
4481 $ref: '#/components/responses/invalid_state_error'
4482 '422':
4483 $ref: '#/components/responses/invalid_request_error'
4484 '500':
4485 $ref: '#/components/responses/500_error'
4486 x-workflow: createCustomerAccountWorkflow
4487 security:
4488 - cookie_auth: []
4489 - jwt_token: []
4490 x-events:
4491 - name: customer.created
4492 payload: |-
4493 ```ts
4494 {
4495 id, // The ID of the customer
4496 }
4497 ```
4498 description: Emitted when a customer is created.
4499 deprecated: false
4500 /store/customers/me:
4501 get:
4502 operationId: GetCustomersMe
4503 summary: Get Logged-in Customer
4504 x-sidebar-summary: Get Customer
4505 description: Retrieve the logged-in customer. You can expand the customer's relations or select the fields that should be returned.
4506 x-authenticated: true
4507 externalDocs:
4508 url: https://docs.medusajs.com/resources/storefront-development/customers/retrieve
4509 description: 'Storefront guide: How to retrieve the logged-in customer.'
4510 parameters:
4511 - name: x-publishable-api-key
4512 in: header
4513 description: Publishable API Key created in the Medusa Admin.
4514 required: true
4515 schema:
4516 type: string
4517 externalDocs:
4518 url: https://docs.medusajs.com/api/store#publishable-api-key
4519 - name: x-medusa-locale
4520 in: header
4521 description: The locale in BCP 47 format to retrieve localized content.
4522 required: false
4523 schema:
4524 type: string
4525 example: en-US
4526 externalDocs:
4527 url: https://docs.medusajs.com/resources/commerce-modules/translation/storefront
4528 description: Learn more in the Serve Translations in Storefront guide.
4529 - name: fields
4530 in: query
4531 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 fields. without prefix it will replace the entire default fields. This API route restricts the fields that can be selected. Learn how to override the retrievable fields in the [Retrieve Custom Links](https://docs.medusajs.com/learn/fundamentals/api-routes/retrieve-custom-links) documentation.
4532 required: false
4533 schema:
4534 type: string
4535 title: fields
4536 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 fields. without prefix it will replace the entire default fields. This API route restricts the fields that can be selected. Learn how to override the retrievable fields in the [Retrieve Custom Links](https://docs.medusajs.com/learn/fundamentals/api-routes/retrieve-custom-links) documentation.
4537 externalDocs:
4538 url: '#select-fields-and-relations'
4539 - name: locale
4540 in: query
4541 description: The locale in BCP 47 format to retrieve localized content.
4542 required: false
4543 schema:
4544 type: string
4545 example: en-US
4546 externalDocs:
4547 url: https://docs.medusajs.com/resources/commerce-modules/translation/storefront
4548 description: Learn more in the Serve Translations in Storefront guide.
4549 security:
4550 - cookie_auth: []
4551 - jwt_token: []
4552 x-codeSamples:
4553 - lang: JavaScript
4554 label: JS SDK
4555 source: |-
4556 import Medusa from "@medusajs/js-sdk"
4557
4558 let MEDUSA_BACKEND_URL = "http://localhost:9000"
4559
4560 if (process.env.NEXT_PUBLIC_MEDUSA_BACKEND_URL) {
4561 MEDUSA_BACKEND_URL = process.env.NEXT_PUBLIC_MEDUSA_BACKEND_URL
4562 }
4563
4564 export const sdk = new Medusa({
4565 baseUrl: MEDUSA_BACKEND_URL,
4566 debug: process.env.NODE_ENV === "development",
4567 publishableKey: process.env.NEXT_PUBLIC_MEDUSA_PUBLISHABLE_KEY,
4568 })
4569
4570 // TODO must be authenticated as the customer to retrieve their details
4571 sdk.store.customer.retrieve()
4572 .then(({ customer }) => {
4573 console.log(customer)
4574 })
4575 - lang: Shell
4576 label: cURL
4577 source: |-
4578 curl '{backend_url}/store/customers/me' \
4579 -H 'Authorization: Bearer {jwt_token}' \
4580 -H 'x-publishable-api-key: {your_publishable_api_key}'
4581 tags:
4582 - Customers
4583 responses:
4584 '200':
4585 description: OK
4586 content:
4587 application/json:
4588 schema:
4589 $ref: '#/components/schemas/StoreCustomerResponse'
4590 '400':
4591 $ref: '#/components/responses/400_error'
4592 '401':
4593 $ref: '#/components/responses/unauthorized'
4594 '404':
4595 $ref: '#/components/responses/not_found_error'
4596 '409':
4597 $ref: '#/components/responses/invalid_state_error'
4598 '422':
4599 $ref: '#/components/responses/invalid_request_error'
4600 '500':
4601 $ref: '#/components/responses/500_error'
4602 post:
4603 operationId: PostCustomersMe
4604 summary: Update Customer
4605 description: Update the logged-in customer's details.
4606 externalDocs:
4607 url: https://docs.medusajs.com/resources/storefront-development/customers/profile
4608 description: 'Storefront guide: How to edit a customer''s profile.'
4609 x-authenticated: true
4610 parameters:
4611 - name: x-publishable-api-key
4612 in: header
4613 description: Publishable API Key created in the Medusa Admin.
4614 required: true
4615 schema:
4616 type: string
4617 externalDocs:
4618 url: https://docs.medusajs.com/api/store#publishable-api-key
4619 - name: x-medusa-locale
4620 in: header
4621 description: The locale in BCP 47 format to retrieve localized content.
4622 required: false
4623 schema:
4624 type: string
4625 example: en-US
4626 externalDocs:
4627 url: https://docs.medusajs.com/resources/commerce-modules/translation/storefront
4628 description: Learn more in the Serve Translations in Storefront guide.
4629 - name: fields
4630 in: query
4631 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 fields. without prefix it will replace the entire default fields.
4632 required: false
4633 schema:
4634 type: string
4635 title: fields
4636 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 fields. without prefix it will replace the entire default fields. This API route restricts the fields that can be selected. Learn how to override the retrievable fields in the [Retrieve Custom Links](https://docs.medusajs.com/learn/fundamentals/api-routes/retrieve-custom-links) documentation.
4637 externalDocs:
4638 url: '#select-fields-and-relations'
4639 - name: locale
4640 in: query
4641 description: The locale in BCP 47 format to retrieve localized content.
4642 required: false
4643 schema:
4644 type: string
4645 example: en-US
4646 externalDocs:
4647 url: https://docs.medusajs.com/resources/commerce-modules/translation/storefront
4648 description: Learn more in the Serve Translations in Storefront guide.
4649 security:
4650 - cookie_auth: []
4651 - jwt_token: []
4652 requestBody:
4653 content:
4654 application/json:
4655 schema:
4656 $ref: '#/components/schemas/StoreUpdateCustomer'
4657 x-codeSamples:
4658 - lang: JavaScript
4659 label: JS SDK
4660 source: |-
4661 import Medusa from "@medusajs/js-sdk"
4662
4663 let MEDUSA_BACKEND_URL = "http://localhost:9000"
4664
4665 if (process.env.NEXT_PUBLIC_MEDUSA_BACKEND_URL) {
4666 MEDUSA_BACKEND_URL = process.env.NEXT_PUBLIC_MEDUSA_BACKEND_URL
4667 }
4668
4669 export const sdk = new Medusa({
4670 baseUrl: MEDUSA_BACKEND_URL,
4671 debug: process.env.NODE_ENV === "development",
4672 publishableKey: process.env.NEXT_PUBLIC_MEDUSA_PUBLISHABLE_KEY,
4673 })
4674
4675 // TODO must be authenticated as the customer to update their details
4676 sdk.store.customer.update({
4677 first_name: "John"
4678 })
4679 .then(({ customer }) => {
4680 console.log(customer)
4681 })
4682 - lang: Shell
4683 label: cURL
4684 source: |-
4685 curl -X POST '{backend_url}/store/customers/me' \
4686 -H 'Authorization: Bearer {jwt_token}' \
4687 -H 'Content-Type: application/json' \
4688 -H 'x-publishable-api-key: {your_publishable_api_key}' \
4689 --data-raw '{
4690 "company_name": "{value}",
4691 "first_name": "{value}",
4692 "last_name": "{value}",
4693 "phone": "{value}"
4694 }'
4695 tags:
4696 - Customers
4697 responses:
4698 '200':
4699 description: OK
4700 content:
4701 application/json:
4702 schema:
4703 $ref: '#/components/schemas/StoreCustomerResponse'
4704 '400':
4705 $ref: '#/components/responses/400_error'
4706 '401':
4707 $ref: '#/components/responses/unauthorized'
4708 '404':
4709 $ref: '#/components/responses/not_found_error'
4710 '409':
4711 $ref: '#/components/responses/invalid_state_error'
4712 '422':
4713 $ref: '#/components/responses/invalid_request_error'
4714 '500':
4715 $ref: '#/components/responses/500_error'
4716 x-workflow: updateCustomersWorkflow
4717 x-events:
4718 - name: customer.updated
4719 payload: |-
4720 ```ts
4721 {
4722 id, // The ID of the customer
4723 }
4724 ```
4725 description: Emitted when a customer is updated.
4726 deprecated: false
4727 /store/customers/me/addresses:
4728 get:
4729 operationId: GetCustomersMeAddresses
4730 summary: List Customer's Addresses
4731 x-sidebary-summary: List Addresses
4732 description: Retrieve the addresses of the logged-in customer. The addresses can be filtered by fields such as `country_code`. The addresses can also be sorted or paginated.
4733 x-authenticated: true
4734 externalDocs:
4735 url: https://docs.medusajs.com/resources/storefront-development/customers/addresses#list-customer-addresses
4736 description: 'Storefront guide: How to retrieve the logged-in customer''s addresses.'
4737 parameters:
4738 - name: x-publishable-api-key
4739 in: header
4740 description: Publishable API Key created in the Medusa Admin.
4741 required: true
4742 schema:
4743 type: string
4744 externalDocs:
4745 url: https://docs.medusajs.com/api/store#publishable-api-key
4746 - name: x-medusa-locale
4747 in: header
4748 description: The locale in BCP 47 format to retrieve localized content.
4749 required: false
4750 schema:
4751 type: string
4752 example: en-US
4753 externalDocs:
4754 url: https://docs.medusajs.com/resources/commerce-modules/translation/storefront
4755 description: Learn more in the Serve Translations in Storefront guide.
4756 - name: city
4757 in: query
4758 description: Filter by the address's city.
4759 required: false
4760 schema:
4761 oneOf:
4762 - type: string
4763 title: city
4764 description: Filter by a city.
4765 - type: array
4766 description: Filter by cities.
4767 items:
4768 type: string
4769 title: city
4770 description: A city.
4771 - name: postal_code
4772 in: query
4773 description: Filter by the address's postal code.
4774 required: false
4775 schema:
4776 oneOf:
4777 - type: string
4778 title: postal_code
4779 description: Filter by a postal code.
4780 - type: array
4781 description: Filter by postal codes.
4782 items:
4783 type: string
4784 title: postal_code
4785 description: A postal code.
4786 - name: country_code
4787 in: query
4788 description: Filter by the address's country code.
4789 required: false
4790 schema:
4791 oneOf:
4792 - type: string
4793 title: country_code
4794 description: Filter by a country code.
4795 - type: array
4796 description: Filter by country codes.
4797 items:
4798 type: string
4799 title: country_code
4800 description: A country code.
4801 - name: q
4802 in: query
4803 description: Search term to filter the address's searchable properties.
4804 required: false
4805 schema:
4806 type: string
4807 title: q
4808 description: Search term to filter the address's searchable properties.
4809 - name: $and
4810 in: query
4811 description: Join query parameters with an AND condition. Each object's content is the same type as the expected query parameters.
4812 required: false
4813 schema:
4814 type: array
4815 description: Join query parameters with an AND condition. Each object's content is the same type as the expected query parameters.
4816 items:
4817 type: object
4818 title: $and
4819 - name: $or
4820 in: query
4821 description: Join query parameters with an OR condition. Each object's content is the same type as the expected query parameters.
4822 required: false
4823 schema:
4824 type: array
4825 description: Join query parameters with an OR condition. Each object's content is the same type as the expected query parameters.
4826 items:
4827 type: object
4828 title: $or
4829 - name: locale
4830 in: query
4831 description: The locale in BCP 47 format to retrieve localized content.
4832 required: false
4833 schema:
4834 type: string
4835 example: en-US
4836 externalDocs:
4837 url: https://docs.medusajs.com/resources/commerce-modules/translation/storefront
4838 description: Learn more in the Serve Translations in Storefront guide.
4839 - name: limit
4840 in: query
4841 description: Limit the number of items returned in the list.
4842 required: false
4843 schema:
4844 type: number
4845 title: limit
4846 description: Limit the number of items returned in the list.
4847 externalDocs:
4848 url: '#pagination'
4849 - name: offset
4850 in: query
4851 description: The number of items to skip when retrieving a list.
4852 required: false
4853 schema:
4854 type: number
4855 title: offset
4856 description: The number of items to skip when retrieving a list.
4857 externalDocs:
4858 url: '#pagination'
4859 - name: order
4860 in: query
4861 description: The field to sort the data by. By default, the sort order is ascending. To change the order to descending, prefix the field name with `-`.
4862 required: false
4863 schema:
4864 type: string
4865 title: order
4866 description: The field to sort the data by. By default, the sort order is ascending. To change the order to descending, prefix the field name with `-`.
4867 externalDocs:
4868 url: '#pagination'
4869 - name: with_deleted
4870 in: query
4871 description: The customer's with deleted.
4872 required: false
4873 schema:
4874 type: boolean
4875 title: with_deleted
4876 description: The customer's with deleted.
4877 - name: fields
4878 in: query
4879 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 fields. Without prefix it will replace the entire default fields.
4880 required: false
4881 schema:
4882 type: string
4883 title: fields
4884 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 fields. Without prefix it will replace the entire default fields.
4885 externalDocs:
4886 url: '#select-fields-and-relations'
4887 security:
4888 - cookie_auth: []
4889 - jwt_token: []
4890 x-codeSamples:
4891 - lang: JavaScript
4892 label: JS SDK
4893 source: |-
4894 import Medusa from "@medusajs/js-sdk"
4895
4896 let MEDUSA_BACKEND_URL = "http://localhost:9000"
4897
4898 if (process.env.NEXT_PUBLIC_MEDUSA_BACKEND_URL) {
4899 MEDUSA_BACKEND_URL = process.env.NEXT_PUBLIC_MEDUSA_BACKEND_URL
4900 }
4901
4902 export const sdk = new Medusa({
4903 baseUrl: MEDUSA_BACKEND_URL,
4904 debug: process.env.NODE_ENV === "development",
4905 publishableKey: process.env.NEXT_PUBLIC_MEDUSA_PUBLISHABLE_KEY,
4906 })
4907
4908 // TODO must be authenticated as the customer to list their addresses
4909 sdk.store.customer.listAddress()
4910 .then(({ addresses, count, offset, limit }) => {
4911 console.log(addresses)
4912 })
4913 - lang: Shell
4914 label: cURL
4915 source: |-
4916 curl '{backend_url}/store/customers/me/addresses' \
4917 -H 'Authorization: Bearer {jwt_token}' \
4918 -H 'x-publishable-api-key: {your_publishable_api_key}'
4919 tags:
4920 - Customers
4921 responses:
4922 '200':
4923 description: OK
4924 content:
4925 application/json:
4926 schema:
4927 $ref: '#/components/schemas/StoreCustomerAddressListResponse'
4928 '400':
4929 $ref: '#/components/responses/400_error'
4930 '401':
4931 $ref: '#/components/responses/unauthorized'
4932 '404':
4933 $ref: '#/components/responses/not_found_error'
4934 '409':
4935 $ref: '#/components/responses/invalid_state_error'
4936 '422':
4937 $ref: '#/components/responses/invalid_request_error'
4938 '500':
4939 $ref: '#/components/responses/500_error'
4940 post:
4941 operationId: PostCustomersMeAddresses
4942 summary: Create Address for Logged-In Customer
4943 x-sidebar-summary: Create Address
4944 description: Create an address for the logged-in customer.
4945 externalDocs:
4946 url: https://docs.medusajs.com/resources/storefront-development/customers/addresses#add-customer-address
4947 description: 'Storefront guide: How to create an address for the logged-in customer.'
4948 x-authenticated: true
4949 parameters:
4950 - name: x-publishable-api-key
4951 in: header
4952 description: Publishable API Key created in the Medusa Admin.
4953 required: true
4954 schema:
4955 type: string
4956 externalDocs:
4957 url: https://docs.medusajs.com/api/store#publishable-api-key
4958 - name: x-medusa-locale
4959 in: header
4960 description: The locale in BCP 47 format to retrieve localized content.
4961 required: false
4962 schema:
4963 type: string
4964 example: en-US
4965 externalDocs:
4966 url: https://docs.medusajs.com/resources/commerce-modules/translation/storefront
4967 description: Learn more in the Serve Translations in Storefront guide.
4968 - name: fields
4969 in: query
4970 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 fields. without prefix it will replace the entire default fields. This API route restricts the fields that can be selected. Learn how to override the retrievable fields in the [Retrieve Custom Links](https://docs.medusajs.com/learn/fundamentals/api-routes/retrieve-custom-links) documentation.
4971 required: false
4972 schema:
4973 type: string
4974 title: fields
4975 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 fields. without prefix it will replace the entire default fields. This API route restricts the fields that can be selected. Learn how to override the retrievable fields in the [Retrieve Custom Links](https://docs.medusajs.com/learn/fundamentals/api-routes/retrieve-custom-links) documentation.
4976 externalDocs:
4977 url: '#select-fields-and-relations'
4978 - name: locale
4979 in: query
4980 description: The locale in BCP 47 format to retrieve localized content.
4981 required: false
4982 schema:
4983 type: string
4984 example: en-US
4985 externalDocs:
4986 url: https://docs.medusajs.com/resources/commerce-modules/translation/storefront
4987 description: Learn more in the Serve Translations in Storefront guide.
4988 security:
4989 - cookie_auth: []
4990 - jwt_token: []
4991 requestBody:
4992 content:
4993 application/json:
4994 schema:
4995 $ref: '#/components/schemas/StoreCreateCustomerAddress'
4996 x-codeSamples:
4997 - lang: JavaScript
4998 label: JS SDK
4999 source: |-
5000 import Medusa from "@medusajs/js-sdk"
Showing first 5,000 of 40,331 lines. View raw