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
    • Customer Login (JWT)
      POST
    • Customer Login (JWT)
      POST
    • Check if Email Exists
      GET
    • Get Current Customer
      GET
    • Customer Log out
      DELETE
    • Customer Login
      POST
  • Carts
    • Create Payment Sessions
      POST
    • Refresh a Payment Session
      POST
    • Create a Cart
      POST
    • Complete a Cart
      POST
    • Select a Payment Session
      POST
    • Delete a Payment Session
      DELETE
    • Update a Payment Session
      POST
    • Get a Cart
      GET
    • Update a Cart
      POST
    • Add Shipping Method
      POST
    • Update a Line Item
      POST
    • Delete a Line Item
      DELETE
    • Add a Line Item
      POST
    • Calculate Cart Taxes
      POST
    • Remove Discount
      DELETE
  • Customers
    • Request Password Reset
    • Get Saved Payment Methods
    • Add a Shipping Address
    • Update Customer
    • Get a Customer
    • Update a Shipping Address
    • Delete an Address
    • Create a Customer
    • Reset Password
    • List Orders
  • Gift Cards
    • Get Gift Card by Code
  • Orders
    • Claim Order
    • Verify Order Claim
    • Get an Order
    • Look Up an Order
    • Get by Cart ID
  • Order Edits
    • Complete an Order Edit
    • Retrieve an Order Edit
    • Decline an Order Edit
  • Payment Collections
    • Authorize Payment Session
    • Authorize Payment Sessions
    • Refresh a Payment Session
    • Get a PaymentCollection
    • Manage Payment Sessions
    • Create a Payment Session
  • Products
    • Search Products
    • List Products
    • Get a Product
  • Product Variants
    • Get a Product Variant
    • Get Product Variants
  • Product Tags
    • List Product Tags
  • Product Categories
    • List Product Categories
    • Get a Product Category
  • Product Collections
    • Get a Collection
    • List Collections
  • Product Types
    • List Product Types
  • Regions
    • List Regions
    • Get a Region
  • Returns
    • Create Return
  • Return Reasons
    • List Return Reasons
    • Get a Return Reason
  • Shipping Options
    • List for Cart
    • Get Shipping Options
  • Swaps
    • Get by Cart ID
    • Create a Swap
  1. Getting Started

Publishable API Key

Publishable API Keys allow you to send a request with a pre-defined scope. You can associate the publishable API key with one or more resources, such as sales channels, then include the publishable
API key in the header of your requests.
The Medusa backend will infer the scope of the current request based on the publishable API key. At the moment, publishable API keys only work with sales channels.
It's highly recommended to create a publishable API key and pass it in the header of all your requests to the store APIs.
You can learn more about publishable API keys and how to use them in this documentation.

How to Create a Publishable API Key#

You can create a publishable API key either using the admin REST APIs,
or using the Medusa admin.

How to Use a Publishable API Key#

You can pass the publishable API key in the header x-publishable-api-key in all your requests to the store APIs:
If you're using Medusa's JS or Medusa React clients, you can pass the publishable API key when you first initialize either clients. Then, the publishable API key will be automatically included in all your requests:
Medusa JS Client:
Medusa React:
import { MedusaProvider } from "medusa-react"

// define query client...

const App = () => {
  return (
    <MedusaProvider
      queryClientProviderProps={{ client: queryClient }}
      baseUrl="http://localhost:9000"
      // ...
      publishableApiKey={publishableApiKey}
    >
      <MyStorefront />
    </MedusaProvider>
  )
}
Modified at 2023-10-10 11:56:42
Previous
HTTP Compression
Next
Expanding Fields
Built with