Skip to main content

Intents API

The Intents API lets you invoke built-in customer account workflows like updating payment methods on subscription contracts. Use this API to trigger standard Shopify actions from your extension without rebuilding complex flows from scratch.

Intents can be invoked using either a structured object or a string query format. Both approaches return an activity handle that you can await to track the workflow's completion.

Note

The Intents API currently supports a single resource: opening the payment method replacement flow for subscription contracts. See Supported resources for details.

  • Update subscription payment methods: Open the built-in payment method replacement flow for a subscription contract, letting customers swap their vaulted card without leaving the extension.
  • Trigger standard account workflows: Invoke Shopify-managed experiences for common tasks instead of building custom UI for each one.
  • Track workflow outcomes: Await the result of shopify.intents.invoke() to detect when a workflow completes and update your extension's UI accordingly.
Support
Targets (24)

The invoke method opens a Shopify-managed workflow for managing resources. The method returns a promise that resolves to an activity handle you can await to get the workflow result.

The method accepts either:

  • String query: ${action}:${type},${value} with optional second parameter (IntentQueryOptions)
  • Object: Properties for action, type, value, and data

IntentQueryOptions parameters

Optional parameters for the invoke method when using the string query format:

  • value (string): The resource identifier (for example, 'gid://shopify/SubscriptionContract/123'). Required when opening existing resources.
  • data ({ [key: string]: unknown }): Additional context required by specific resource types. For example, subscription contracts require { field: 'paymentMethod' }.
Anchor to invoke
invoke
{ (query: ): Promise<>; (intentURL: string, options?: ): Promise<>; }
required

Triggers a built-in Shopify workflow by passing a structured intent object. Specify an action (such as 'open'), a resource type, and an optional value identifying the resource. Returns a promise that resolves to an IntentActivity you can use to track completion.

Triggers a built-in Shopify workflow using a URL string in the format action:type[,value][?params]. Use this overload when composing intents from dynamic strings rather than structured objects.

The following table shows which resource types you can open and what values you need to pass for value and data.

Anchor to Subscription contractSubscription contract

Subscription contracts represent recurring billing agreements. Use this to open the payment method replacement flow for an active subscription.

ActionTypeValueData
openshopify/SubscriptionContractgid://shopify/SubscriptionContract/{id}{ field: 'paymentMethod' }

The result returned when an intent workflow completes. Check the code property to determine the outcome:

  • 'ok': The customer completed the workflow successfully.
  • 'error': The workflow failed due to validation or other errors.
  • 'closed': The customer cancelled without completing.
Anchor to ClosedIntentResponse

ClosedIntentResponse

'closed'
required

Always 'closed' when the user dismissed the workflow without completing it.

'error'

Set to 'error' when present. This property is optional.

Anchor to issues
issues
{ path?: string[]; message?: string; }[]

Structured details for validation or field-specific problems, following the Standard Schema convention.

Anchor to message
message
string

A human-readable summary of the failure.

Anchor to SuccessIntentResponse

SuccessIntentResponse

'ok'
required

Always 'ok' for a successful response.

Record<string, unknown>
required

Validated output payload produced by the workflow.

The shape is intent-specific. Consumers should narrow by code === 'ok' before accessing.


  • Prefer object syntax for dynamic intents: When building the intent parameters programmatically from variables, use the structured object format. It's easier to read and less error-prone than string interpolation.
  • Use string syntax for static intents: When the action, type, and value are known at write time, the compact string format keeps your code concise.
  • Always await the activity handle: Call await activity.complete to detect when the workflow finishes. This lets you refresh data or update UI in response to the customer's action.
  • Check the response code before acting on results: Verify that response.code is 'ok' before using response.data. The workflow may be cancelled or fail, and your extension should handle those cases gracefully.

  • Intent workflows pause your extension until completion. You can't run other operations while an intent is open.
  • The workflow UI can't be customized. Field order, labels, and validation messages are controlled by Shopify and can't be modified.

Was this page helpful?