Webhookobject
Contains functions for verifying Shopify webhooks.
Verifies requests coming from Shopify webhooks.
- Anchor to requestrequestRequestrequired
AuthenticateWebhook
- request
Request
Promise<
WebhookContext<Topics> | WebhookContextWithSession<Topics, Resources>
>
export type AuthenticateWebhook<
Resources extends ShopifyRestResources = ShopifyRestResources,
Topics = string | number | symbol,
> = (
request: Request,
) => Promise<
WebhookContext<Topics> | WebhookContextWithSession<Topics, Resources>
>;
WebhookContext
- session
undefined
- admin
undefined
- apiVersion
The API version used for the webhook.
string
- shop
The shop where the webhook was triggered.
string
- topic
The topic of the webhook.
Topics
- webhookId
A unique ID for the webhook. Useful to keep track of which events your app has already processed.
string
- payload
The payload from the webhook request.
JSONValue
export interface WebhookContext<Topics = string | number | symbol>
extends Context<Topics> {
session: undefined;
admin: undefined;
}
JSONValue
string | number | boolean | null | JSONObject | JSONArray
JSONObject
- [x: string]
JSONValue
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.
number
- toString
Returns a string representation of an array.
() => string
- toLocaleString
Returns a string representation of an array. The elements are converted to string using their toLocaleString methods.
() => 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.
() => JSONValue
- push
Appends new elements to the end of an array, and returns the new length of the array.
(...items: JSONValue[]) => number
- concat
Combines two or more arrays. This method returns a new array without modifying any existing arrays.
{ (...items: ConcatArray<JSONValue>[]): JSONValue[]; (...items: (JSONValue | ConcatArray<JSONValue>)[]): JSONValue[]; }
- join
Adds all the elements of an array into a string, separated by the specified separator string.
(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.
() => 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.
() => 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.
(start?: number, end?: number) => JSONValue[]
- sort
Sorts an array in place. This method mutates the array and returns a reference to the same array.
(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.
{ (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.
(...items: JSONValue[]) => number
- indexOf
Returns the index of the first occurrence of a value in an array, or -1 if it is not present.
(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.
(searchElement: JSONValue, fromIndex?: number) => number
- every
Determines whether all the members of an array satisfy the specified test.
{ <S extends JSONValue>(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.
(predicate: (value: JSONValue, index: number, array: JSONValue[]) => unknown, thisArg?: any) => boolean
- forEach
Performs the specified action for each element in an array.
(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.
<U>(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.
{ <S extends JSONValue>(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.
{ (callbackfn: (previousValue: JSONValue, currentValue: JSONValue, currentIndex: number, array: JSONValue[]) => JSONValue): JSONValue; (callbackfn: (previousValue: JSONValue, currentValue: JSONValue, currentIndex: number, array: JSONValue[]) => JSONValue, initialValue: JSONValue): JSONValue; <U>(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.
{ (callbackfn: (previousValue: JSONValue, currentValue: JSONValue, currentIndex: number, array: JSONValue[]) => JSONValue): JSONValue; (callbackfn: (previousValue: JSONValue, currentValue: JSONValue, currentIndex: number, array: JSONValue[]) => JSONValue, initialValue: JSONValue): JSONValue; <U>(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.
{ <S extends JSONValue>(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.
(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
(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
(target: number, start: number, end?: number) => JSONArray
- entries
Returns an iterable of key, value pairs for every entry in the array
() => IterableIterator<[number, JSONValue]>
- keys
Returns an iterable of keys in the array
() => IterableIterator<number>
- values
Returns an iterable of values in the array
() => IterableIterator<JSONValue>
- includes
Determines whether an array includes a certain element, returning true or false as appropriate.
(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.
<U, This = undefined>(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.
<A, D extends number = 1>(this: A, depth?: D) => FlatArray<A, D>[]
- __@iterator@526
Iterator
() => IterableIterator<JSONValue>
- __@unscopables@528
Returns an object whose properties have the value 'true' when they will be absent when used in a 'with' statement.
() => { 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.
(index: number) => JSONValue
interface JSONArray extends Array<JSONValue> {}
WebhookContextWithSession
- session
A session with an offline token for the shop. Returned only if there is a session for the shop.
Session
- admin
An admin context for the webhook. Returned only if there is a session for the shop.
{ rest: RestClient & Resources; graphql: GraphqlClient; }
- apiVersion
The API version used for the webhook.
string
- shop
The shop where the webhook was triggered.
string
- topic
The topic of the webhook.
Topics
- webhookId
A unique ID for the webhook. Useful to keep track of which events your app has already processed.
string
- payload
The payload from the webhook request.
JSONValue
export interface WebhookContextWithSession<
Topics = string | number | symbol,
Resources extends ShopifyRestResources = any,
> extends Context<Topics> {
/**
* 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<Shopify['clients']['Rest']> & Resources;
/** A GraphQL client. */
graphql: InstanceType<Shopify['clients']['Graphql']>;
};
}
Anchor to examplesExamples
Anchor to example-apiversionapiVersion
Anchor to example-webhook-api-versionWebhook API version
Get the API version used for webhook request.
Webhook API version
Example
examples
Webhook API version
description
Get the API version used for webhook request.
Example
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(); };
Anchor to example-webhook-shopWebhook shop
Get the shop that triggered a webhook.
Webhook shop
Example
examples
Webhook shop
description
Get the shop that triggered a webhook.
Example
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(); };
Anchor to example-webhook-topicWebhook topic
Get the event topic for the webhook.
Webhook topic
Example
examples
Webhook topic
description
Get the event topic for the webhook.
Example
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(); };
Anchor to example-webhookidwebhookId
Anchor to example-webhook-idWebhook ID
Get the webhook ID.
Webhook ID
Example
examples
Webhook ID
description
Get the webhook ID.
Example
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(); };
Anchor to example-payloadpayload
Anchor to example-webhook-payloadWebhook payload
Get the request's POST payload.
Webhook payload
Example
examples
Webhook payload
description
Get the request's POST payload.
Example
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(); };