AdminPublishableApiKeyResource
This class is used to send requests to Admin Publishable API Key API Routes. All its method
are available in the JS Client under the medusa.admin.publishableApiKeys
property.
All methods in this class require user authentication.
Publishable API Keys can be used to scope Store API calls with an API key, determining what resources are retrieved when querying the API. For example, a publishable API key can be associated with one or more sales channels. When it is passed in the header of a request to the List Product store API Route, the sales channels are inferred from the key and only products associated with those sales channels are retrieved. Admins can manage publishable API keys and their associated resources. Currently, only Sales Channels are supported as a resource.
Related Guide: How to manage publishable API keys.
Methods
addSalesChannelsBatch
Add a list of sales channels to a publishable API key.
Example
import Medusa from "@medusajs/medusa-js"
const medusa = new Medusa({ baseUrl: MEDUSA_BACKEND_URL, maxRetries: 3 })
// must be previously logged in or use api token
medusa.admin.publishableApiKeys.addSalesChannelsBatch(publishableApiKeyId, {
sales_channel_ids: [
{
id: channelId
}
]
})
.then(({ publishable_api_key }) => {
console.log(publishable_api_key.id);
})
Parameters
id
stringRequiredThe sales channels to add.
customHeaders
Record<string, any>RequiredDefault: {}
Returns
ResponsePromise
ResponsePromise<AdminPublishableApiKeysRes>RequiredResolves to the publishbale API key's details.
ResponsePromise
ResponsePromise<AdminPublishableApiKeysRes>Requiredcreate
Create a publishable API key.
Example
Parameters
The publishable API key to be created.
customHeaders
Record<string, any>RequiredDefault: {}
Returns
ResponsePromise
ResponsePromise<AdminPublishableApiKeysRes>RequiredResolves to the publishbale API key's details.
ResponsePromise
ResponsePromise<AdminPublishableApiKeysRes>Requireddelete
Delete a publishable API key. Associated resources, such as sales channels, are not deleted.
Example
Parameters
id
stringRequiredcustomHeaders
Record<string, any>RequiredDefault: {}
Returns
ResponsePromise
ResponsePromise<DeleteResponse>RequiredResolves to the delete operation's details.
ResponsePromise
ResponsePromise<DeleteResponse>RequireddeleteSalesChannelsBatch
Remove a list of sales channels from a publishable API key. This doesn't delete the sales channels and only removes the association between them and the publishable API key.
Example
import Medusa from "@medusajs/medusa-js"
const medusa = new Medusa({ baseUrl: MEDUSA_BACKEND_URL, maxRetries: 3 })
// must be previously logged in or use api token
medusa.admin.publishableApiKeys.deleteSalesChannelsBatch(publishableApiKeyId, {
sales_channel_ids: [
{
id: channelId
}
]
})
.then(({ publishable_api_key }) => {
console.log(publishable_api_key.id);
})
Parameters
id
stringRequiredThe sales channels to delete from the publishable API key.
customHeaders
Record<string, any>RequiredDefault: {}
Returns
ResponsePromise
ResponsePromise<AdminPublishableApiKeysRes>RequiredResolves to the publishbale API key's details.
ResponsePromise
ResponsePromise<AdminPublishableApiKeysRes>Requiredlist
Retrieve a list of publishable API keys. The publishable API keys can be filtered by fields such as q
passed in query
. The publishable API keys can also be paginated.
Example
To list publishable API keys:
By default, only the first 20
records are retrieved. You can control pagination by specifying the limit
and offset
properties:
import Medusa from "@medusajs/medusa-js"
const medusa = new Medusa({ baseUrl: MEDUSA_BACKEND_URL, maxRetries: 3 })
// must be previously logged in or use api token
medusa.admin.publishableApiKeys.list({
limit,
offset
})
.then(({ publishable_api_keys, count, limit, offset }) => {
console.log(publishable_api_keys)
})
Parameters
Filters and pagination configurations to apply on the retrieved publishable API keys.
customHeaders
Record<string, any>RequiredDefault: {}
Returns
ResponsePromise
ResponsePromise<AdminPublishableApiKeysListRes>RequiredResolves to the list of publishable API keys with pagination fields.
ResponsePromise
ResponsePromise<AdminPublishableApiKeysListRes>RequiredlistSalesChannels
List the sales channels associated with a publishable API key. The sales channels can be filtered by fields such as q
passed in the query
parameter.
Example
Parameters
id
stringRequiredFilters to apply on the retrieved sales channels.
customHeaders
Record<string, any>RequiredDefault: {}
Returns
ResponsePromise
ResponsePromise<AdminPublishableApiKeysListSalesChannelsRes>RequiredResolves to the list of sales channels.
ResponsePromise
ResponsePromise<AdminPublishableApiKeysListSalesChannelsRes>Requiredretrieve
Retrieve a publishable API key's details.
Example
Parameters
id
stringRequiredquery
Record<string, any>RequiredDefault: {}
customHeaders
Record<string, any>RequiredDefault: {}
Returns
ResponsePromise
ResponsePromise<AdminPublishableApiKeysRes>RequiredResolves to the publishable API key's details.
ResponsePromise
ResponsePromise<AdminPublishableApiKeysRes>Requiredrevoke
Revoke a publishable API key. Revoking the publishable API Key can't be undone, and the key can't be used in future requests.
Example
Parameters
id
stringRequiredcustomHeaders
Record<string, any>RequiredDefault: {}
Returns
ResponsePromise
ResponsePromise<AdminPublishableApiKeysRes>RequiredResolves to the publishbale API key's details.
ResponsePromise
ResponsePromise<AdminPublishableApiKeysRes>Requiredupdate
Update a publishable API key's details.
Example
import Medusa from "@medusajs/medusa-js"
const medusa = new Medusa({ baseUrl: MEDUSA_BACKEND_URL, maxRetries: 3 })
// must be previously logged in or use api token
medusa.admin.publishableApiKeys.update(publishableApiKeyId, {
title: "new title"
})
.then(({ publishable_api_key }) => {
console.log(publishable_api_key.id)
})
Parameters
id
stringRequiredThe attributes to update in the publishable API key.
customHeaders
Record<string, any>RequiredDefault: {}
Returns
ResponsePromise
ResponsePromise<AdminPublishableApiKeysRes>RequiredResolves to the publishbale API key's details.
ResponsePromise
ResponsePromise<AdminPublishableApiKeysRes>Required