Medusa
Store APIAdmin API
Store APIAdmin API
Discord
Twitter
Linkedin
Github
  1. Getting Started
  • Getting Started
    • Introduction
    • Authentication
    • HTTP Compression
    • Publishable API Key
    • Expanding Fields
    • Selecting Fields
    • Query Parameter Types
    • Pagination
  • Auth
    • Check if Email Exists
      GET
    • Customer Login (JWT)
      POST
    • Customer Login (JWT)
      POST
    • Customer Log out
      DELETE
    • Get Current Customer
      GET
    • Customer Login
      POST
  • Carts
    • Create Payment Sessions
      POST
    • Update a Payment Session
      POST
    • Delete a Payment Session
      DELETE
    • Create a Cart
      POST
    • Get a Cart
      GET
    • Update a Cart
      POST
    • Remove Discount
      DELETE
    • Add a Line Item
      POST
    • Update a Line Item
      POST
    • Delete a Line Item
      DELETE
    • Select a Payment Session
      POST
    • Refresh a Payment Session
      POST
    • Add Shipping Method
      POST
    • Calculate Cart Taxes
      POST
    • Complete a Cart
      POST
  • Customers
    • Get Saved Payment Methods
    • Request Password Reset
    • Update a Shipping Address
    • Delete an Address
    • Create a Customer
    • Get a Customer
    • Update Customer
    • Add a Shipping Address
    • Reset Password
    • List Orders
  • Gift Cards
    • Get Gift Card by Code
  • Orders
    • Claim Order
    • Verify Order Claim
    • Look Up an Order
    • Get by Cart ID
    • Get an Order
  • Order Edits
    • Retrieve an Order Edit
    • Decline an Order Edit
    • Complete an Order Edit
  • Payment Collections
    • Refresh a Payment Session
    • Authorize Payment Session
    • Get a PaymentCollection
    • Create a Payment Session
    • Manage Payment Sessions
    • Authorize Payment Sessions
  • Products
    • Search Products
    • Get a Product
    • List Products
  • Product Variants
    • Get Product Variants
    • Get a Product Variant
  • Product Categories
    • Get a Product Category
    • List Product Categories
  • Product Collections
    • List Collections
    • Get a Collection
  • Product Tags
    • List Product Tags
  • Product Types
    • List Product Types
  • Regions
    • Get a Region
    • List Regions
  • Returns
    • Create Return
  • Return Reasons
    • List Return Reasons
    • Get a Return Reason
  • Shipping Options
    • List for Cart
    • Get Shipping Options
  • Swaps
    • Create a Swap
    • Get by Cart ID
  1. Getting Started

Authentication

There are two ways to send authenticated requests to the Medusa server: Using a JWT token or using a Cookie Session ID.

JWT Token#

Use a JWT token to send authenticated requests. Authentication state is managed by the client, which is ideal for Jamstack applications and mobile applications.

How to Obtain the JWT Token#

JWT tokens are obtained by sending a request to the Customer Login (JWT) endpoint passing it the customer's email and password in the request body. For example:
If authenticated successfully, an object is returned in the response with the property access_token being the JWT token.

How to Use the JWT Token#

The JWT token can be used for Bearer Authentication. It's passed in the
Authorization header as the following:

Cookie Session ID#

Use a cookie session to send authenticated requests.

How to Obtain the Cookie Session#

If you're sending requests through a browser, using Medusa's JS and Medusa React clients, or using
tools like Postman, the cookie session should be automatically set when
the customer is logged in.
If you're sending requests using cURL, you must set the Session ID in the cookie manually.
To do that, send a request to authenticate the customer and pass the cURL option -v:
The headers will be logged in the terminal as well as the response. You should find in the headers a Cookie header similar to this:
Copy the value after connect.sid (without the ; at the end) and pass it as a cookie in subsequent requests as the following:
Where {sid} is the value of connect.sid that you copied.
If you're sending requests using JavaScript's Fetch API, you must pass the credentials option with the value include to all the requests you're sending. For example:
Modified at 2023-10-07 12:55:51
Previous
Introduction
Next
HTTP Compression
Built with