Fulfillment Serviceobject
Contains functions for verifying fulfillment service requests.
See the fulfillment service documentation for more information.
Verifies requests coming from Shopify to fulfillment service apps
- Anchor to requestrequestRequestrequired
AuthenticateFulfillmentService
- request
Request
Promise<FulfillmentServiceContext<ConfigArg, Resources>>
export type AuthenticateFulfillmentService<
ConfigArg extends AppConfigArg,
Resources extends ShopifyRestResources = ShopifyRestResources,
> = (
request: Request,
) => Promise<FulfillmentServiceContext<ConfigArg, Resources>>;
FulfillmentServiceContext
- admin
An admin context for the fulfillment service request. Returned only if there is a session for the shop.
AdminApiContext<ConfigArg, Resources>
- payload
The payload from the fulfillment service request.
FulfillmentServicePayload
- session
A session with an offline token for the shop. Returned only if there is a session for the shop.
Session
export interface FulfillmentServiceContext<
ConfigArg extends AppConfigArg,
Resources extends ShopifyRestResources = ShopifyRestResources,
> {
/**
* A session with an offline token for the shop.
*
* Returned only if there is a session for the shop.
* @example
* <caption>Shopify session for the fulfillment service notification request.</caption>
* <description>Use the session associated with this request.</description>
* ```ts
* // /app/routes/fulfillment_service_notification.tsx
* import { ActionFunctionArgs } from "@remix-run/node";
* import { authenticate } from "../shopify.server";
*
* export const action = async ({ request }: ActionFunctionArgs) => {
* const { session, admin } = await authenticate.fulfillmentService(request);
*
* console.log(session.id)
*
* return new Response();
* };
* ```
* */
session: Session;
/**
*
* An admin context for the fulfillment service request.
*
* Returned only if there is a session for the shop.
* @example
* <caption>Shopify session for the fulfillment service request.</caption>
* <description>Use the session associated with this request to use the Admin GraphQL API </description>
* ```ts
* // /app/routes/fulfillment_order_notification.ts
* import { ActionFunctionArgs } from "@remix-run/node";
* import { authenticate } from "../shopify.server";
*
* export async function action({ request }: ActionFunctionArgs) {
* const { admin, session } = await authenticate.fulfillmentService(request);
*
* console.log(session.id)
*
* return new Response();
* }
* ```
*/
admin: AdminApiContext<ConfigArg, Resources>;
/**
* The payload from the fulfillment service request.
*
* @example
* <caption>Fulfillment service request payload.</caption>
* <description>Get the request's POST payload.</description>
* ```ts
* /app/routes/fulfillment_order_notification.ts
* import { ActionFunction } from "@remix-run/node";
* import { authenticate } from "../shopify.server";
*
* export const action: ActionFunction = async ({ request }) => {
* const { payload } = await authenticate.fulfillmentService(request);
* if(payload.kind === 'FULFILLMENT_REQUEST') {
* // handle fulfillment request
* } else if (payload.kind === 'CANCELLATION_REQUEST') {
* // handle cancellation request
* };
* return new Response();
* ```
*/
payload: FulfillmentServicePayload;
}
FulfillmentServicePayload
Record<string, any> & {
kind: string;
}
Consume a fulfillment service notification request
/app/routes/**.ts
examples
Consume a fulfillment service notification request
description
Handle a fulfillment service notification call
/app/routes/**.ts
import {type ActionFunctionArgs} from '@remix-run/node'; import {authenticate} from '../shopify.server'; export const action = async ({request}: ActionFunctionArgs) => { const {admin, payload} = await authenticate.fulfillmentService(request); const kind = payload.kind; if (kind === 'FULFILLMENT_REQUEST') { const response = await admin?.graphql( `#graphql query { shop { assignedFulfillmentOrders(first: 10, assignmentStatus: FULFILLMENT_REQUESTED) { edges { node { id destination { firstName lastName } lineItems(first: 10) { edges { node { id productTitle sku remainingQuantity } } } merchantRequests(first: 10, kind: FULFILLMENT_REQUEST) { edges { node { message } } } } } } } }`, ); const fulfillments = await response.json(); console.log(fulfillments); } return new Response(); };
Anchor to examplesExamples
Anchor to example-shopify-session-for-the-fulfillment-service-requestShopify session for the fulfillment service request
Use the session associated with this request to use the Admin GraphQL API
Shopify session for the fulfillment service request
/app/routes/fulfillment_order_notification.ts
examples
Shopify session for the fulfillment service request
description
Use the session associated with this request to use the Admin GraphQL API
/app/routes/fulfillment_order_notification.ts
import { ActionFunctionArgs } from "@remix-run/node"; import { authenticate } from "../shopify.server"; export async function action({ request }: ActionFunctionArgs) { const { admin, session } = await authenticate.fulfillmentService(request); console.log(session.id) return new Response(); }
Anchor to example-payloadpayload
Anchor to example-fulfillment-service-request-payloadFulfillment service request payload
Get the request's POST payload.
Fulfillment service request payload
Example
examples
Fulfillment service request payload
description
Get the request's POST payload.
Example
/app/routes/fulfillment_order_notification.ts import { ActionFunction } from "@remix-run/node"; import { authenticate } from "../shopify.server"; export const action: ActionFunction = async ({ request }) => { const { payload } = await authenticate.fulfillmentService(request); if(payload.kind === 'FULFILLMENT_REQUEST') { // handle fulfillment request } else if (payload.kind === 'CANCELLATION_REQUEST') { // handle cancellation request }; return new Response();
Anchor to example-sessionsession
Anchor to example-shopify-session-for-the-fulfillment-service-notification-requestShopify session for the fulfillment service notification request
Use the session associated with this request.
Shopify session for the fulfillment service notification request
/app/routes/fulfillment_service_notification.tsx
examples
Shopify session for the fulfillment service notification request
description
Use the session associated with this request.
/app/routes/fulfillment_service_notification.tsx
import { ActionFunctionArgs } from "@remix-run/node"; import { authenticate } from "../shopify.server"; export const action = async ({ request }: ActionFunctionArgs) => { const { session, admin } = await authenticate.fulfillmentService(request); console.log(session.id) return new Response(); };