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