Intents
The Intents API provides a way to invoke existing customer account workflows for managing buyer information.
Anchor to invokeinvoke
The invoke API is a function that accepts either a string query or an options object describing the intent to invoke and returns a Promise that resolves to an activity handle for the workflow.
Intent format
Intents are invoked using a string query format: ${action}:${type},${value}
Where:
action- The operation to perform (create,editoropen)type- The resource type (e.g.,)value- The resource identifier
Supported resources
Subscription contract
| Action | Type | Value | Data |
|---|---|---|---|
open | | | |
- Anchor to invokeinvokeinvoke{ (query: IntentQuery): Promise<IntentActivity>; (intentURL: string, options?: IntentQueryOptions): Promise<IntentActivity>; }{ (query: IntentQuery): Promise<IntentActivity>; (intentURL: string, options?: IntentQueryOptions): Promise<IntentActivity>; }requiredrequired
Invoke an intent using the object or URL syntax.
Object format:
{action, type, value?, data?}URL format:
action:type[,value][?params]
IntentQuery
Structured description of an intent to invoke. Use this object form when programmatically composing an intent at runtime. It pairs an action (verb) with a resource type and optional inputs.
- action
Verb describing the operation to perform on the target resource. Common values include `create` and `open`. The set of allowed verbs is intent-specific; unknown verbs will fail validation.
IntentAction - data
Optional input payload passed to the intent. Used to seed forms or supply parameters. The accepted shape is intent-specific. For example: - Replacing a payment method on a subscription contract requires { field: 'paymentMethod' }
Record<string, unknown> - type
The resource type (e.g. `shopify/SubscriptionContract`).
string - value
The resource identifier for edit actions (e.g. `gid://shopify/SubscriptionContract/123`).
string
IntentAction
Allowed actions that can be performed by an intent. Common actions include: - `'create'`: Initiate creation of a new resource. - `'open'`: Modify an existing resource.
'create' | 'open' | stringIntentActivity
Activity handle for tracking intent workflow progress.
- complete
A Promise that resolves when the intent workflow completes, returning the response.
Promise<IntentResponse>
IntentResponse
Result of an intent activity. Discriminated union representing all possible completion outcomes for an invoked intent.
SuccessIntentResponse | ErrorIntentResponse | ClosedIntentResponseSuccessIntentResponse
Successful intent completion. - `code` is always `'ok'` - `data` contains the output payload
- code
'ok' - data
Validated output payload produced by the workflow. The shape is intent-specific. Consumers should narrow by `code === 'ok'` before accessing.
Record<string, unknown>
ErrorIntentResponse
Failed intent completion. - `code` is always `'error'` - `message` summarizes the failure - `issues` optionally provides structured details for validation or field-specific problems following the Standard Schema convention
- code
'error' - issues
{ path?: string[]; message?: string; }[] - message
string
ClosedIntentResponse
User dismissed or closed the workflow without completing it. Distinct from `error`: no failure occurred, the activity was simply abandoned by the user.
- code
'closed'
IntentQueryOptions
Options for URL-based invocations. When invoking via URL syntax, `action` and `type` are parsed from the string. This companion type captures the remaining optional fields that can be provided alongside the URL.
- data
Optional input payload passed to the intent. Used to seed forms or supply parameters. The accepted shape is intent-specific. For example: - Replacing a payment method on a subscription contract requires { field: 'paymentMethod' }
Record<string, unknown> - value
The resource identifier for edit actions (e.g. `gid://shopify/SubscriptionContract/123`).
string
Anchor to intentactionIntentAction
Supported actions that can be performed on resources.
create: Opens a creation workflow for a new resourceopen: Opens a workflow for an existing resource (requiresvalueparameter)
'create' | 'open' | string'create' | 'open' | stringAnchor to intentqueryIntentQuery
Structured description of an intent to invoke. Use this object form when programmatically composing an intent at runtime.
- Anchor to actionactionactionIntentActionIntentActionrequiredrequired
Verb describing the operation to perform on the target resource.
Common values include
createandopen. The set of allowed verbs is intent-specific; unknown verbs will fail validation.- Anchor to typetypetypestringstringrequiredrequired
The resource type (e.g.
).- Anchor to datadatadataRecord<string, unknown>Record<string, unknown>
Optional input payload passed to the intent.
Used to seed forms or supply parameters. The accepted shape is intent-specific. For example:
- Replacing a payment method on a subscription contract requires { field: 'paymentMethod' }
- Anchor to valuevaluevaluestringstring
The resource identifier for edit actions (e.g.
).
IntentAction
Allowed actions that can be performed by an intent. Common actions include: - `'create'`: Initiate creation of a new resource. - `'open'`: Modify an existing resource.
'create' | 'open' | stringAnchor to intentqueryoptionsIntentQueryOptions
Options for invoking intents when using the query string format.
- Anchor to datadatadataRecord<string, unknown>Record<string, unknown>
Optional input payload passed to the intent.
Used to seed forms or supply parameters. The accepted shape is intent-specific. For example:
- Replacing a payment method on a subscription contract requires { field: 'paymentMethod' }
- Anchor to valuevaluevaluestringstring
The resource identifier for edit actions (e.g.
).
Anchor to intentactivityIntentActivity
Activity handle for tracking intent workflow progress.
- Anchor to completecompletecompletePromise<IntentResponse>Promise<IntentResponse>requiredrequired
A Promise that resolves when the intent workflow completes, returning the response.
IntentResponse
Result of an intent activity. Discriminated union representing all possible completion outcomes for an invoked intent.
SuccessIntentResponse | ErrorIntentResponse | ClosedIntentResponseSuccessIntentResponse
Successful intent completion. - `code` is always `'ok'` - `data` contains the output payload
- code
'ok' - data
Validated output payload produced by the workflow. The shape is intent-specific. Consumers should narrow by `code === 'ok'` before accessing.
Record<string, unknown>
ErrorIntentResponse
Failed intent completion. - `code` is always `'error'` - `message` summarizes the failure - `issues` optionally provides structured details for validation or field-specific problems following the Standard Schema convention
- code
'error' - issues
{ path?: string[]; message?: string; }[] - message
string
ClosedIntentResponse
User dismissed or closed the workflow without completing it. Distinct from `error`: no failure occurred, the activity was simply abandoned by the user.
- code
'closed'
Anchor to intentresponseIntentResponse
Response object returned when the intent workflow completes.
SuccessIntentResponse | ErrorIntentResponse | ClosedIntentResponseSuccessIntentResponse | ErrorIntentResponse | ClosedIntentResponseClosedIntentResponse
- Anchor to codecodecode'closed''closed'requiredrequired
ErrorIntentResponse
- Anchor to codecodecode'error''error'
- Anchor to issuesissuesissues{ path?: string[]; message?: string; }[]{ path?: string[]; message?: string; }[]
- Anchor to messagemessagemessagestringstring
SuccessIntentResponse
- Anchor to codecodecode'ok''ok'requiredrequired
- Anchor to datadatadataRecord<string, unknown>Record<string, unknown>requiredrequired
Validated output payload produced by the workflow.
The shape is intent-specific. Consumers should narrow by
code === 'ok'before accessing.
SuccessIntentResponse
Successful intent completion. - `code` is always `'ok'` - `data` contains the output payload
- code
'ok' - data
Validated output payload produced by the workflow. The shape is intent-specific. Consumers should narrow by `code === 'ok'` before accessing.
Record<string, unknown>
ErrorIntentResponse
Failed intent completion. - `code` is always `'error'` - `message` summarizes the failure - `issues` optionally provides structured details for validation or field-specific problems following the Standard Schema convention
- code
'error' - issues
{ path?: string[]; message?: string; }[] - message
string
ClosedIntentResponse
User dismissed or closed the workflow without completing it. Distinct from `error`: no failure occurred, the activity was simply abandoned by the user.
- code
'closed'
Examples
Replace payment method with object syntax
Default
import '@shopify/ui-extensions/preact'; import {render} from 'preact'; export default async () => { render(<Extension />, document.body); }; function Extension() { async function handleReplacePaymentMethod() { const activity = await shopify.intents.invoke( { action: 'open', type: 'shopify/SubscriptionContract', value: 'gid://shopify/SubscriptionContract/123', data: {field: 'paymentMethod'}, }, ); const response = await activity.complete; if (response.code === 'ok') { console.log( 'Intent completed successfully', response.data, ); } } return ( <s-button onClick={handleReplacePaymentMethod} > Edit subscription payment method </s-button> ); }Replace payment method with string syntax
Description
Replace the payment method on an active subscription contract. Opens a modal with vaulted cards.
Default
import '@shopify/ui-extensions/preact'; import {render} from 'preact'; export default async () => { render(<Extension />, document.body); }; function Extension() { async function handleReplacePaymentMethod() { const activity = await shopify.intents.invoke( 'open:shopify/SubscriptionContract,gid://shopify/SubscriptionContract/123?field=paymentMethod', ); const response = await activity.complete; if (response.code === 'ok') { console.log( 'Intent completed successfully', response.data, ); } } return ( <s-button onClick={handleReplacePaymentMethod} > Edit subscription payment method </s-button> ); }