Skip to main content
Migrate to Polaris

Version 2025-07 is the last API version to support React-based UI components. Later versions use web components, native UI elements with built-in accessibility, better performance, and consistent styling with Shopify's design system. Check out the migration guide to upgrade your extension.

Customer Segment Template Extension API

Requires the CustomerSegmentTemplate component.

The Customer Segment Template Extension API lets you build a customer segment template extension. Merchants can use your templates to set up customer segments based on custom criteria.

  • Segment templates: Build custom segment template interfaces for customer segmentation.
  • Rule configuration: Configure customer segment rules with custom criteria.
  • Template management: Manage segment template settings and metadata.
  • Segment logic: Define logic for identifying customers matching segment criteria.

The Customer Segment Template API object includes tools for creating segment templates and translating content. Access the following properties on the API object in the admin.customers.segmentation-templates.render target.

required

Provides methods for authenticating calls to your app backend. Use the idToken() method to retrieve a signed JWT token that verifies the current user's identity for secure server-side operations.

Anchor to extension
extension
{ target: ; }
required

The identifier of the running extension target. Use this to determine which target your extension is rendering in and conditionally adjust functionality or UI based on the extension context.

required

Utilities for translating template content into the merchant's language.

Anchor to intents
intents
required

Provides information to the receiver of an intent. Use this to access data passed from other extensions or parts of the admin when your extension is launched through intent-based navigation.

Anchor to query
query
< = unknown, Variables = { [key: string]: unknown; }>(query: string, options?: { variables?: Variables; version?: Omit<, "2023-04">; }) => Promise<{ data?: ; errors?: []; }>
required

Executes GraphQL queries against the GraphQL Admin API. Use this to fetch shop data, manage resources, or perform mutations. Queries are automatically authenticated with the current user's permissions. Optionally specify GraphQL variables and API version for your query.


  • Test queries in admin before shipping: Template queries aren't validated until merchants save them. Test query syntax in the Shopify admin segment editor before shipping to avoid merchant-facing errors.
  • Declare all metafield dependencies: Use both standardMetafields (for Shopify-defined metafields) and customMetafields (for app-defined metafields) in the dependencies object. Missing dependencies cause queries to fail when merchants lack required metafields.
  • Use queryToInsert for formatted display queries: If your query includes formatting or comments for readability, then provide a clean executable version in queryToInsert. If omitting queryToInsert, then ensure query has no comments that would break execution.

  • Query validation only occurs when merchants save. Syntax errors in queries aren't caught by the API and only surface in the admin when merchants attempt to save the segment.
  • Your extension can't programmatically create segments. Templates only provide the query and metadata. Merchants must manually save templates as segments.
  • Dependencies don't auto-create metafields. If required metafields don't exist, then merchants see errors when trying to use the template. The API only declares dependencies, it doesn't create them.
  • Dynamic query generation isn't supported. Queries must be static strings. You can't parameterize queries based on merchant input or shop configuration.

Was this page helpful?