--- title: Webhook description: Contains functions for verifying Shopify webhooks. api_version: v1 api_name: shopify-app-remix source_url: html: 'https://shopify.dev/docs/api/shopify-app-remix/v1/authenticate/webhook' md: 'https://shopify.dev/docs/api/shopify-app-remix/v1/authenticate/webhook.md' --- # Webhook Contains functions for verifying Shopify webhooks. ## authenticate.​webhook([request](#authenticatewebhook-propertydetail-request)​) Verifies requests coming from Shopify webhooks. ### Parameters * request Request required ### Returns * Promise< WebhookContext\ | WebhookContextWithSession\ > ### WebhookContext * session ```ts undefined ``` * admin ```ts undefined ``` * apiVersion The API version used for the webhook. ```ts string ``` * shop The shop where the webhook was triggered. ```ts string ``` * topic The topic of the webhook. ```ts Topics ``` * webhookId A unique ID for the webhook. Useful to keep track of which events your app has already processed. ```ts string ``` * payload The payload from the webhook request. ```ts JSONValue ``` ```ts export interface WebhookContext extends Context { session: undefined; admin: undefined; } ``` ### JSONValue ```ts string | number | boolean | null | JSONObject | JSONArray ``` ### JSONObject * \[x: string] ```ts JSONValue ``` ```ts interface JSONObject { [x: string]: JSONValue; } ``` ### JSONArray * length Gets or sets the length of the array. This is a number one higher than the highest index in the array. ```ts number ``` * toString Returns a string representation of an array. ```ts () => string ``` * toLocaleString Returns a string representation of an array. The elements are converted to string using their toLocaleString methods. ```ts () => string ``` * pop Removes the last element from an array and returns it. If the array is empty, undefined is returned and the array is not modified. ```ts () => JSONValue ``` * push Appends new elements to the end of an array, and returns the new length of the array. ```ts (...items: JSONValue[]) => number ``` * concat Combines two or more arrays. This method returns a new array without modifying any existing arrays. ```ts { (...items: ConcatArray[]): JSONValue[]; (...items: (JSONValue | ConcatArray)[]): JSONValue[]; } ``` * join Adds all the elements of an array into a string, separated by the specified separator string. ```ts (separator?: string) => string ``` * reverse Reverses the elements in an array in place. This method mutates the array and returns a reference to the same array. ```ts () => JSONValue[] ``` * shift Removes the first element from an array and returns it. If the array is empty, undefined is returned and the array is not modified. ```ts () => JSONValue ``` * slice Returns a copy of a section of an array. For both start and end, a negative index can be used to indicate an offset from the end of the array. For example, -2 refers to the second to last element of the array. ```ts (start?: number, end?: number) => JSONValue[] ``` * sort Sorts an array in place. This method mutates the array and returns a reference to the same array. ```ts (compareFn?: (a: JSONValue, b: JSONValue) => number) => JSONArray ``` * splice Removes elements from an array and, if necessary, inserts new elements in their place, returning the deleted elements. ```ts { (start: number, deleteCount?: number): JSONValue[]; (start: number, deleteCount: number, ...items: JSONValue[]): JSONValue[]; } ``` * unshift Inserts new elements at the start of an array, and returns the new length of the array. ```ts (...items: JSONValue[]) => number ``` * indexOf Returns the index of the first occurrence of a value in an array, or -1 if it is not present. ```ts (searchElement: JSONValue, fromIndex?: number) => number ``` * lastIndexOf Returns the index of the last occurrence of a specified value in an array, or -1 if it is not present. ```ts (searchElement: JSONValue, fromIndex?: number) => number ``` * every Determines whether all the members of an array satisfy the specified test. ```ts { (predicate: (value: JSONValue, index: number, array: JSONValue[]) => value is S, thisArg?: any): this is S[]; (predicate: (value: JSONValue, index: number, array: JSONValue[]) => unknown, thisArg?: any): boolean; } ``` * some Determines whether the specified callback function returns true for any element of an array. ```ts (predicate: (value: JSONValue, index: number, array: JSONValue[]) => unknown, thisArg?: any) => boolean ``` * forEach Performs the specified action for each element in an array. ```ts (callbackfn: (value: JSONValue, index: number, array: JSONValue[]) => void, thisArg?: any) => void ``` * map Calls a defined callback function on each element of an array, and returns an array that contains the results. ```ts (callbackfn: (value: JSONValue, index: number, array: JSONValue[]) => U, thisArg?: any) => U[] ``` * filter Returns the elements of an array that meet the condition specified in a callback function. ```ts { (predicate: (value: JSONValue, index: number, array: JSONValue[]) => value is S, thisArg?: any): S[]; (predicate: (value: JSONValue, index: number, array: JSONValue[]) => unknown, thisArg?: any): JSONValue[]; } ``` * reduce Calls the specified callback function for all the elements in an array. The return value of the callback function is the accumulated result, and is provided as an argument in the next call to the callback function. ```ts { (callbackfn: (previousValue: JSONValue, currentValue: JSONValue, currentIndex: number, array: JSONValue[]) => JSONValue): JSONValue; (callbackfn: (previousValue: JSONValue, currentValue: JSONValue, currentIndex: number, array: JSONValue[]) => JSONValue, initialValue: JSONValue): JSONValue; (callbackfn: (previousValue: U, currentValue: JSONValue, currentIndex: number, array: JSONValue[]) => U, initialValue: U): U; } ``` * reduceRight Calls the specified callback function for all the elements in an array, in descending order. The return value of the callback function is the accumulated result, and is provided as an argument in the next call to the callback function. ```ts { (callbackfn: (previousValue: JSONValue, currentValue: JSONValue, currentIndex: number, array: JSONValue[]) => JSONValue): JSONValue; (callbackfn: (previousValue: JSONValue, currentValue: JSONValue, currentIndex: number, array: JSONValue[]) => JSONValue, initialValue: JSONValue): JSONValue; (callbackfn: (previousValue: U, currentValue: JSONValue, currentIndex: number, array: JSONValue[]) => U, initialValue: U): U; } ``` * find Returns the value of the first element in the array where predicate is true, and undefined otherwise. ```ts { (predicate: (this: void, value: JSONValue, index: number, obj: JSONValue[]) => value is S, thisArg?: any): S; (predicate: (value: JSONValue, index: number, obj: JSONValue[]) => unknown, thisArg?: any): JSONValue; } ``` * findIndex Returns the index of the first element in the array where predicate is true, and -1 otherwise. ```ts (predicate: (value: JSONValue, index: number, obj: JSONValue[]) => unknown, thisArg?: any) => number ``` * fill Changes all array elements from \`start\` to \`end\` index to a static \`value\` and returns the modified array ```ts (value: JSONValue, start?: number, end?: number) => JSONArray ``` * copyWithin Returns the this object after copying a section of the array identified by start and end to the same array starting at position target ```ts (target: number, start: number, end?: number) => JSONArray ``` * entries Returns an iterable of key, value pairs for every entry in the array ```ts () => IterableIterator<[number, JSONValue]> ``` * keys Returns an iterable of keys in the array ```ts () => IterableIterator ``` * values Returns an iterable of values in the array ```ts () => IterableIterator ``` * includes Determines whether an array includes a certain element, returning true or false as appropriate. ```ts (searchElement: JSONValue, fromIndex?: number) => boolean ``` * flatMap Calls a defined callback function on each element of an array. Then, flattens the result into a new array. This is identical to a map followed by flat with depth 1. ```ts (callback: (this: This, value: JSONValue, index: number, array: JSONValue[]) => U | readonly U[], thisArg?: This) => U[] ``` * flat Returns a new array with all sub-array elements concatenated into it recursively up to the specified depth. ```ts (this: A, depth?: D) => FlatArray[] ``` * \_\_@iterator\@526 Iterator ```ts () => IterableIterator ``` * \_\_@unscopables\@528 Returns an object whose properties have the value 'true' when they will be absent when used in a 'with' statement. ```ts () => { copyWithin: boolean; entries: boolean; fill: boolean; find: boolean; findIndex: boolean; keys: boolean; values: boolean; } ``` * at Takes an integer value and returns the item at that index, allowing for positive and negative integers. Negative integers count back from the last item in the array. ```ts (index: number) => JSONValue ``` ```ts interface JSONArray extends Array {} ``` ### WebhookContextWithSession * session A session with an offline token for the shop. Returned only if there is a session for the shop. ```ts Session ``` * admin An admin context for the webhook. Returned only if there is a session for the shop. ```ts { rest: RestClient & Resources; graphql: GraphqlClient; } ``` * apiVersion The API version used for the webhook. ```ts string ``` * shop The shop where the webhook was triggered. ```ts string ``` * topic The topic of the webhook. ```ts Topics ``` * webhookId A unique ID for the webhook. Useful to keep track of which events your app has already processed. ```ts string ``` * payload The payload from the webhook request. ```ts JSONValue ``` ```ts export interface WebhookContextWithSession< Topics = string | number | symbol, Resources extends ShopifyRestResources = any, > extends Context { /** * A session with an offline token for the shop. * * Returned only if there is a session for the shop. */ session: Session; /** * An admin context for the webhook. * * Returned only if there is a session for the shop. */ admin: { /** A REST client. */ rest: InstanceType & Resources; /** A GraphQL client. */ graphql: InstanceType; }; } ``` Examples ### Examples * #### Webhook API version ##### Description Get the API version used for webhook request. ##### Example ```typescript import { ActionFunction } from "@remix-run/node"; import { authenticate } from "../shopify.server"; export const action: ActionFunction = async ({ request }) => { const { apiVersion } = await authenticate.webhook(request); return new Response(); }; ``` * #### Webhook shop ##### Description Get the shop that triggered a webhook. ##### Example ```typescript import { ActionFunction } from "@remix-run/node"; import { authenticate } from "../shopify.server"; export const action: ActionFunction = async ({ request }) => { const { shop } = await authenticate.webhook(request); return new Response(); }; ``` * #### Webhook topic ##### Description Get the event topic for the webhook. ##### Example ```typescript import { ActionFunction } from "@remix-run/node"; import { authenticate } from "../shopify.server"; export const action: ActionFunction = async ({ request }) => { const { topic } = await authenticate.webhook(request); switch (topic) { case "APP_UNINSTALLED": // Do something when the app is uninstalled. break; } return new Response(); }; ``` * #### Webhook ID ##### Description Get the webhook ID. ##### Example ```typescript import { ActionFunction } from "@remix-run/node"; import { authenticate } from "../shopify.server"; export const action: ActionFunction = async ({ request }) => { const { webhookId } = await authenticate.webhook(request); return new Response(); }; ``` * #### Webhook payload ##### Description Get the request's POST payload. ##### Example ```typescript import { ActionFunction } from "@remix-run/node"; import { authenticate } from "../shopify.server"; export const action: ActionFunction = async ({ request }) => { const { payload } = await authenticate.webhook(request); return new Response(); }; ```