--- displayed_sidebar: jsClientSidebar slug: /references/js-client/AdminPublishableApiKeyResource --- import ParameterTypes from "@site/src/components/ParameterTypes" # AdminPublishableApiKeyResource This class is used to send requests to [Admin Publishable API Key API Routes](https://docs.medusajs.com/api/admin#publishable-api-keys). All its method are available in the JS Client under the `medusa.admin.publishableApiKeys` property. All methods in this class require [user authentication](AdminAuthResource.mdx#createsession). 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](https://docs.medusajs.com/development/publishable-api-keys/admin/manage-publishable-api-keys). ## Methods ### addSalesChannelsBatch Add a list of sales channels to a publishable API key. #### Example ```ts 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 `", "description": "Custom headers to attach to the request.", "optional": false, "defaultValue": "{}", "expandable": false, "children": [] } ]} /> #### Returns ___ ### create Create a publishable API key. #### Example ```ts 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 .create({ title, }) .then(({ publishable_api_key }) => { console.log(publishable_api_key.id) }) ``` #### Parameters `", "description": "Custom headers to attach to the request.", "optional": false, "defaultValue": "{}", "expandable": false, "children": [] } ]} /> #### Returns ___ ### delete Delete a publishable API key. Associated resources, such as sales channels, are not deleted. #### Example ```ts 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 .delete(publishableApiKeyId) .then(({ id, object, deleted }) => { console.log(id) }) ``` #### Parameters `", "description": "Custom headers to attach to the request.", "optional": false, "defaultValue": "{}", "expandable": false, "children": [] } ]} /> #### Returns ___ ### deleteSalesChannelsBatch 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 ```ts 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 `", "description": "Custom headers to attach to the request.", "optional": false, "defaultValue": "{}", "expandable": false, "children": [] } ]} /> #### Returns ___ ### list 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: ```ts 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() .then(({ publishable_api_keys, count, limit, offset }) => { console.log(publishable_api_keys) }) ``` By default, only the first `20` records are retrieved. You can control pagination by specifying the `limit` and `offset` properties: ```ts 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 `", "description": "Custom headers to attach to the request.", "optional": false, "defaultValue": "{}", "expandable": false, "children": [] } ]} /> #### Returns ___ ### listSalesChannels 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 ```ts 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 .listSalesChannels() .then(({ sales_channels }) => { console.log(sales_channels.length) }) ``` #### Parameters `", "description": "Custom headers to attach to the request.", "optional": false, "defaultValue": "{}", "expandable": false, "children": [] } ]} /> #### Returns `", "description": "An optional key-value map with additional details", "optional": false, "defaultValue": "", "expandable": false, "children": [] }, { "name": "name", "type": "`string`", "description": "The name of the sales channel.", "optional": false, "defaultValue": "", "expandable": false, "children": [] }, { "name": "updated_at", "type": "`Date`", "description": "The date with timezone at which the resource was updated.", "optional": false, "defaultValue": "", "expandable": false, "children": [] } ] } ] } ] } ]} /> ___ ### retrieve Retrieve a publishable API key's details. #### Example ```ts 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 .retrieve(publishableApiKeyId) .then(({ publishable_api_key }) => { console.log(publishable_api_key.id) }) ``` #### Parameters `", "description": "", "optional": false, "defaultValue": "{}", "expandable": false, "children": [] }, { "name": "customHeaders", "type": "`Record`", "description": "Custom headers to attach to the request.", "optional": false, "defaultValue": "{}", "expandable": false, "children": [] } ]} /> #### Returns ___ ### revoke 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 ```ts 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 .revoke(publishableApiKeyId) .then(({ publishable_api_key }) => { console.log(publishable_api_key.id) }) ``` #### Parameters `", "description": "Custom headers to attach to the request.", "optional": false, "defaultValue": "{}", "expandable": false, "children": [] } ]} /> #### Returns ___ ### update Update a publishable API key's details. #### Example ```ts 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 `", "description": "Custom headers to attach to the request.", "optional": false, "defaultValue": "{}", "expandable": false, "children": [] } ]} /> #### Returns