Configuration
When you create a customer account UI extension, an app extension configuration shopify.extension.toml
file is automatically generated in your extension's directory.
This guide describes extension targeting, capabilities, metafields, and the settings you can configure in the app extension configuration.
Anchor to how-it-worksHow it works
You define properties for your customer account UI extension in the extension configuration file. The shopify.extension.toml
file contains the extension's configuration, which includes the extension name, targets, capabilities, and settings.
When an extension is published to Shopify, the contents of the settings file are pushed alongside the extension.
You can configure more than one type of extension within a configuration file.
Shopify.extension.toml
Anchor to targetsTargets
Targets represent where your customer account UI extension will be injected. You may have one or many targets defined in your app extension configuration using the targeting
field.
Along with the target
, Shopify needs to know which code to execute for it. You specify the path to your code file by using the module
property.
Anchor to targets-supporting-a-single-extension-targetSupporting a single extension target
Your code should have a default export if it only supports a single extension target.
Anchor to targets-supporting-multiple-extension-targetsSupporting multiple extension targets
You can support multiple extension targets within a single configuration file. However, you must provide a separate file per extension target using the export default
declaration.
Single extension target
Anchor to capabilitiesCapabilities
Defines the capabilities associated with your extension.
Capabilities
shopify.extension.toml
Anchor to api-accessStorefront API access
The following section describes the use cases of the capability and the Storefront API access scopes.
Anchor to When to use Storefront API accessWhen to use Storefront API access
API access is used when your extension needs to retrieve data from the Storefront API. For example, you may need to fetch product data, check the product tags on an item in the order summary.
Shopify handles the authentication for all API calls from an extension.
Anchor to Methods for accessing the Storefront APIMethods for accessing the Storefront API
Enabling the capability allows you to use the Order Status API
query
method and the global fetch
to retrieve data from the Storefront API without manually managing token aquisition and refresh.
query
lets you request a single GraphQL response from the Storefront API.
If you prefer to construct GraphQL requests yourself or you would like to use a full-featured GraphQL client such as Apollo or urql, our custom fetch
global automatically appends the required access tokens.
The GraphQL client of your choice shouldn’t use any DOM APIs, as they aren’t available in a customer account UI extension's Web Worker.
Anchor to Storefront API access scopesStorefront API access scopes
Your extensions will have the following unauthenticated access scopes to the Storefront API:
unauthenticated_read_product_publications
unauthenticated_read_collection_publications
unauthenticated_read_product_listings
unauthenticated_read_product_tags
unauthenticated_read_selling_plans
unauthenticated_read_collection_listings
unauthenticated_read_metaobjects
Enable Storefront API access
shopify.extension.toml
Anchor to network-accessNetwork access
The following section describes use cases for requesting network access, alternatives to requesting network access, and steps for completing a request for network access.
If your extension specifies the capability, you must request access in order to publish your extension.
Anchor to When to request network accessWhen to request network access
If you need to get data that you can't currently get from Shopify, then you should request network access. For example, you might need to fetch additional data to render loyalty points.
Anchor to Alternatives to network accessAlternatives to network access
Instead of fetching data with an external network call, consider retrieving the data from a metafield. Your app can use the Customer Account API to write to metafields on the customer, order, company, or company location.
An app with the ability to query the Admin API can also write to metafields on the shop or product.
Retrieving data from metafields is faster because it doesn't require an external network call. Instead, you can rely on Shopify for the uptime, scaling, and durability of the data storage.
Anchor to Complete a request for network accessComplete a request for network access
Go to your Partner Dashboard.
Click the name of the app that you want to change.
Click API access.
Under Allow network access in checkout and account UI extensions, click Allow network access
Your request is automatically approved and your app is immediately granted the approval scope that's required for your customer account UI extension to make external network calls.
Add
network_access = true
to the[extensions.capabilities]
section of your extension's configuration file.
Anchor to Required CORS headersRequired CORS headers
Since UI extensions run in a Web Worker, they have a null origin. They do not share the storefront or customer account's origin. For network calls to succeed, your server must support cross-origin resource sharing (CORS) for null origins by including this response header:
Access-Control-Allow-Origin: *
Anchor to App ProxyApp Proxy
UI extensions can make fetch requests to App Proxy URLs, but there are some differences and limitations related to the security context within which UI extensions run.
UI extension requests made to the App Proxy will execute as CORS requests. See Required CORS headers above for information about requirements related to CORS.
UI extension requests made to the App Proxy will not assign the logged_in_customer_id
query parameter. Instead use a session token which provides the sub
claim for the logged in customer.
UI extension requests made to the App Proxy of password protected shops is not supported. Extension requests come from a web worker which does not share the same session as the parent window.
The App Proxy doesn't handle all HTTP request methods. Specifically, CONNECT
and TRACE
are unsupported.
Anchor to Security considerationsSecurity considerations
When processing HTTP requests on your API server, you cannot guarantee that your own extension will have made every request. When responding with sensitive data, keep in mind that requests could originate from anywhere on the Internet.
Your extension can pass a session token to your API server but this only guarantees the integrity of its claims. It does not guarantee the request itself originated from Shopify. For example, your API server could trust the session token's sub
claim (the customer ID) but it could not trust a query parameter.
Enable network access
shopify.extension.toml
Anchor to collect-buyer-consentCollect buyer consent
If your extension utilizes the Customer Privacy API to collecting buyer consent, you must first declare that capability in your configuration file.
Anchor to Customer PrivacyCustomer Privacy
In order to collect customer privacy consent, you'll need to add in your toml configuration. This will let you use our Customer Privacy API.
Collect buyer consent
shopify.extension.toml
Anchor to metafieldsMetafields
All customer account UI extension targets can read and write to metafields using the Customer Account API. Learn more about writing to metafields.
Access to metafields on a read-only basis through the Order Status API is available to order status targets and is defined in your configuration. Customer account UI extensions are configured for metafields similarly to checkout UI extensions. Learn more.
Anchor to settings-definitionSettings definition
The settings for a customer account UI extension define a set of fields that the merchant will be able to set a value for from the checkout editor. You can use validation options to apply additional constraints to the data that the setting can store, such as a minimum or maximum value.
Each settings definition can include up to 20 settings.
All setting inputs are optional. You should code the extension so that it still works if the merchant hasn't set a value for the setting.
Anchor to PropertiesProperties
The following table describes the properties that you can use to define a setting:
Property | Required? | Description | Example |
---|---|---|---|
key | Yes | The key of the setting. When a merchant configures a value for this setting, the value will be exposed under this key when running your extension | "banner_title" |
type | Yes | The type of setting. | "single_line_text_field" |
name | Yes | The name of the setting. name is displayed to the merchant in the checkout editor. | "Banner title" |
description | No | The description of the setting. description is displayed to the merchant in the checkout editor. | "Enter a title for the banner." |
validations | No | Constraints on the setting input that Shopify validates. | validations: |
Anchor to Supported setting typesSupported setting types
The setting type determines the type of information that the setting can store. The setting types have built-in validation on the setting input.
Settings can have the following types:
Type | Description | Example value |
---|---|---|
boolean | A true or false value. | true |
date | A date in ISO 8601 format without a presumed time zone. | 2022-02-02 |
| A date and time in ISO 8601 format without a presumed time zone. | 2022-01-01T12:30:00 |
| A single line string. | Canada |
| A multi-line string. | Canada |
| A whole number in the range of +/-9,007,199,254,740,991. | 10 |
| A number with decimal places in the range of +/-9,999,999,999,999.999999999. | 10.4 |
| A globally-unique identifier (GID) for a product variant. | gid://shopify/ProductVariant/1 |
Anchor to Validation optionsValidation options
Each setting can include validation options. Validation options enable you to apply additional constraints to the data that a setting can store, such as a minimum or maximum value, or a regular expression. The setting's type
determines the available validation options.
You can include a validation option for a setting using the validation name
and a corresponding value
. The appropriate value depends on the setting type to which the validation applies.
The following table outlines the available validation options with supported types for applying constraints to a setting:
Validation option | Description | Supported types | Example |
---|---|---|---|
Minimum length | The minimum length of a text value. |
| [[extensions.settings.fields.validations]] |
Maximum length | The maximum length of a text value. |
| [[extensions.settings.fields.validations]] |
Regular expression | A regular expression. Shopify supports RE2. |
| [[extensions.settings.fields.validations]] |
Choices | A list of up to 128 predefined options that limits the values allowed for the metafield. |
| [[extensions.settings.fields.validations]] |
Minimum date | The minimum date in ISO 8601 format. | date | [[extensions.settings.fields.validations]] |
Maximum date | The maximum date in ISO 8601 format. | date | [[extensions.settings.fields.validations]] |
Minimum datetime | The minimum date and time in ISO 8601 format. |
| [[extensions.settings.fields.validations]] |
Maximum datetime | The maximum date and time in ISO 8601 format. |
| [[extensions.settings.fields.validations]] |
Minimum integer | The minimum integer number. |
| [[extensions.settings.fields.validations]] |
Maximum integer | The maximum integer number. |
| [[extensions.settings.fields.validations]] |
Minimum decimal | The minimum decimal number. |
| [[extensions.settings.fields.validations]] |
Maximum decimal | The maximum decimal number. |
| [[extensions.settings.fields.validations]] |
Maximum precision | The maximum number of decimal places to store for a decimal number. |
| [[extensions.settings.fields.validations]] |
Anchor to example-settings-definitionExample settings definition
The following example shows a settings definition that defines a setting named of type
. When the merchant sets a value for this setting from the checkout editor, Shopify validates that the provided value is between 5 and 20 characters in length