--- 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 * admin ```ts undefined ``` * apiVersion The API version used for the webhook. ```ts string ``` * payload The payload from the webhook request. ```ts JSONValue ``` * session ```ts undefined ``` * 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 ``` ### JSONValue ```ts string | number | boolean | null | JSONObject | JSONArray ``` ### JSONObject * \[x: string] ```ts JSONValue ``` ### JSONArray * \_\_@iterator\@410 Iterator ```ts () => IterableIterator ``` * \_\_@unscopables\@412 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 ```ts (index: number) => JSONValue ``` * 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[]; } ``` * 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]> ``` * 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; } ``` * 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 ``` * 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[]; } ``` * 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 ``` * 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[] ``` * 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[] ``` * forEach Performs the specified action for each element in an array. ```ts (callbackfn: (value: JSONValue, index: number, array: JSONValue[]) => void, thisArg?: any) => void ``` * includes Determines whether an array includes a certain element, returning true or false as appropriate. ```ts (searchElement: JSONValue, fromIndex?: number) => boolean ``` * 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 ``` * join Adds all the elements of an array into a string, separated by the specified separator string. ```ts (separator?: string) => string ``` * keys Returns an iterable of keys in the array ```ts () => IterableIterator ``` * 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 ``` * length Gets or sets the length of the array. This is a number one higher than the highest index in the array. ```ts number ``` * 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[] ``` * 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 ``` * 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; } ``` * 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[] ``` * 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 ``` * 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[]; } ``` * toLocaleString Returns a string representation of an array. The elements are converted to string using their toLocaleString methods. ```ts () => string ``` * toString Returns a string representation of an array. ```ts () => string ``` * unshift Inserts new elements at the start of an array, and returns the new length of the array. ```ts (...items: JSONValue[]) => number ``` * values Returns an iterable of values in the array ```ts () => IterableIterator ``` ### WebhookContextWithSession * 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 ``` * payload The payload from the webhook request. ```ts JSONValue ``` * session A session with an offline token for the shop. Returned only if there is a session for the shop. ```ts Session ``` * 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 ``` Examples ### Examples * #### ##### Description Get the API version used for webhook request. ##### Example ```ts 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(); }; ``` * #### ##### Description Get the request's POST payload. ##### Example ```ts 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(); }; ``` * #### ##### Description Get the shop that triggered a webhook. ##### Example ```ts 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(); }; ``` * #### ##### Description Get the event topic for the webhook. ##### Example ```ts 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(); }; ``` * #### ##### Description Get the webhook ID. ##### Example ```ts 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(); }; ``` ***