Skip to main content

Webhook

Contains functions for verifying Shopify webhooks.

Note

The format of the admin object returned by this function changes with the v3_webhookAdminContext future flag. Learn more about gradual feature adoption.

Verifies requests coming from Shopify webhooks.

Request
required

Promise<<Future, Resources, Topics>>
Examples

/app/routes/**.ts

import {type ActionFunctionArgs} from '@remix-run/node';

import {authenticate} from '../shopify.server';

export const action = async ({request}: ActionFunctionArgs) => {
const {topic, admin, payload} = await authenticate.webhook(request);

switch (topic) {
case 'PRODUCTS_UPDATE':
await admin.graphql(
`#graphql
mutation setMetafield($productId: ID!, $time: String!) {
metafieldsSet(metafields: {
ownerId: $productId
namespace: "my-app",
key: "webhook_received_at",
value: $time,
type: "string",
}) {
metafields {
key
value
}
}
}
`,
{
variables: {
productId: payload.admin_graphql_api_id,
time: new Date().toISOString(),
},
},
);

return new Response();
}

throw new Response();
};
Was this page helpful?