Skip to main content

Intents

The Intents API provides a way to invoke existing customer account workflows for managing buyer information.

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, edit or open)
  • type - The resource type (e.g., shopify/SubscriptionContract)
  • value - The resource identifier

Supported resources

Subscription contract

ActionTypeValueData
openshopify/SubscriptionContractgid://shopify/SubscriptionContract/{id}{ field: 'paymentMethod' }
Anchor to invoke
invoke
{ (query: ): Promise<>; (intentURL: string, options?: ): Promise<>; }
required

Invoke an intent using the object or URL syntax.

Object format: {action, type, value?, data?}

URL format: action:type[,value][?params]

Supported actions that can be performed on resources.

  • create: Opens a creation workflow for a new resource
  • open: Opens a workflow for an existing resource (requires value parameter)
'create' | 'open' | string

Structured description of an intent to invoke. Use this object form when programmatically composing an intent at runtime.

Anchor to action
action
required

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.

string
required

The resource type (e.g. shopify/SubscriptionContract).

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 value
value
string

The resource identifier for edit actions (e.g. gid://shopify/SubscriptionContract/123).

Options for invoking intents when using the query string format.

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 value
value
string

The resource identifier for edit actions (e.g. gid://shopify/SubscriptionContract/123).

Activity handle for tracking intent workflow progress.

Anchor to complete
complete
Promise<>
required

A Promise that resolves when the intent workflow completes, returning the response.

Response object returned when the intent workflow completes.

Anchor to ClosedIntentResponse

ClosedIntentResponse

'closed'
required
'error'
Anchor to issues
issues
{ path?: string[]; message?: string; }[]
Anchor to message
message
string
Anchor to SuccessIntentResponse

SuccessIntentResponse

'ok'
required
Record<string, unknown>
required

Validated output payload produced by the workflow.

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

Examples
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>
);
}
Was this page helpful?