---
title: Fulfillment Service
description: Contains functions for verifying fulfillment service requests.
api_version: v2
source_url:
  html: >-
    https://shopify.dev/docs/api/shopify-app-remix/v2/authenticate/fulfillment-service
  md: >-
    https://shopify.dev/docs/api/shopify-app-remix/v2/authenticate/fulfillment-service.md
api_name: shopify-app-remix
---

# Fulfillment Service

Contains functions for verifying fulfillment service requests.

See the [fulfillment service documentation](https://shopify.dev/docs/apps/fulfillment/fulfillment-service-apps) for more information.

## authenticate.fulfillmentService(**[request](#authenticatefulfillmentservice-propertydetail-request)**)

Verifies requests coming from Shopify to fulfillment service apps.

### Parameters

* **request**

  **Request**

  **required**

### Returns

* **Promise\<FulfillmentServiceContext\<Resources>>**

### FulfillmentServiceContext

* admin

  An admin context for the fulfillment service request. Returned only if there is a session for the shop.

  ```ts
  AdminApiContext<Resources>
  ```

* payload

  The payload from the fulfillment service request.

  ```ts
  Record<string, any> & { kind: string; }
  ```

* session

  A session with an offline token for the shop. Returned only if there is a session for the shop.

  ```ts
  Session
  ```

### AdminApiContext

Provides utilities that apps can use to make requests to the Admin API.

* graphql

  Methods for interacting with the Shopify Admin GraphQL API

  ```ts
  GraphQLClient<AdminOperations>
  ```

* rest

  Methods for interacting with the Shopify Admin REST API There are methods for interacting with individual REST resources. You can also make \`GET\`, \`POST\`, \`PUT\` and \`DELETE\` requests should the REST resources not meet your needs.

  ```ts
  RestClientWithResources<Resources>
  ```

### GraphQLClient

* query

  ```ts
  Operation extends keyof Operations
  ```

* options

  ```ts
  GraphQLQueryOptions<Operation, Operations>
  ```

returns

```ts
interface Promise<T> {
    /**
     * Attaches callbacks for the resolution and/or rejection of the Promise.
     * @param onfulfilled The callback to execute when the Promise is resolved.
     * @param onrejected The callback to execute when the Promise is rejected.
     * @returns A Promise for the completion of which ever callback is executed.
     */
    then<TResult1 = T, TResult2 = never>(onfulfilled?: ((value: T) => TResult1 | PromiseLike<TResult1>) | undefined | null, onrejected?: ((reason: any) => TResult2 | PromiseLike<TResult2>) | undefined | null): Promise<TResult1 | TResult2>;

    /**
     * Attaches a callback for only the rejection of the Promise.
     * @param onrejected The callback to execute when the Promise is rejected.
     * @returns A Promise for the completion of the callback.
     */
    catch<TResult = never>(onrejected?: ((reason: any) => TResult | PromiseLike<TResult>) | undefined | null): Promise<T | TResult>;
}, interface Promise<T> {}, Promise: PromiseConstructor, interface Promise<T> {
    readonly [Symbol.toStringTag]: string;
}, interface Promise<T> {
    /**
     * Attaches a callback that is invoked when the Promise is settled (fulfilled or rejected). The
     * resolved value cannot be modified from the callback.
     * @param onfinally The callback to execute when the Promise is settled (fulfilled or rejected).
     * @returns A Promise for the completion of the callback.
     */
    finally(onfinally?: (() => void) | undefined | null): Promise<T>;
}
```

### GraphQLQueryOptions

* apiVersion

  The version of the API to use for the request.

  ```ts
  ApiVersion
  ```

* headers

  Additional headers to include in the request.

  ```ts
  Record<string, any>
  ```

* tries

  The total number of times to try the request if it fails.

  ```ts
  number
  ```

* variables

  The variables to pass to the operation.

  ```ts
  ApiClientRequestOptions<Operation, Operations>
  ```

### RestClientWithResources

```ts
RemixRestClient & {resources: Resources}
```

### RemixRestClient

* session

  ```ts
  Session
  ```

* get

  Performs a GET request on the given path.

  ```ts
  (params: GetRequestParams) => Promise<Response>
  ```

* post

  Performs a POST request on the given path.

  ```ts
  (params: PostRequestParams) => Promise<Response>
  ```

* put

  Performs a PUT request on the given path.

  ```ts
  (params: PostRequestParams) => Promise<Response>
  ```

* delete

  Performs a DELETE request on the given path.

  ```ts
  (params: GetRequestParams) => Promise<Response>
  ```

### Examples

* #### Consume a fulfillment service notification request

  ##### Description

  Handle a fulfillment service notification call

  ##### /app/routes/\*\*.ts

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

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

  export const action = async ({request}: ActionFunctionArgs) => {
    const {admin, payload} = await authenticate.flow(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();
  };
  ```

* #### 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

  ```ts
  import { ActionFunctionArgs } from "@remix-run/node";
  import { authenticate } from "../shopify.server";

  export async function action({ request }: ActionFunctionArgs) {
    const { admin } = await authenticate.fulfillmentService(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();
    return json({ data: fulfillments.data });
  }
  ```

* #### Fulfillment service request payload

  ##### 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.fulfillmentService(request);
    if (payload.kind === 'FULFILLMENT_REQUEST') {
      // handle fulfillment request
    } else if (payload.kind === 'CANCELLATION_REQUEST') {
      // handle cancellation request
    }
    return new Response();
  };
  ```

* #### Shopify session for the fulfillment service notification request

  ##### Description

  Use the session associated with this request to use REST resources.

  ##### /app/routes/fulfillment\_service\_notification.tsx

  ```ts
  import { ActionFunctionArgs } from "@remix-run/node";
  import { authenticate } from "../shopify.server";

    export const action = async ({ request }: ActionFunctionArgs) => {
    const { session, admin } = await authenticate.fulfillmentService(request);

    const products = await admin?.rest.resources.Product.all({ session });
    // Use products

    return new Response();
  };
  ```

***

## Related

[Interact with the Admin API. - Admin API context](https://shopify.dev/docs/api/shopify-app-remix/v2/apis/admin-api)

[Receive fulfillment requests and cancellations. - Manage Fulfillments](https://shopify.dev/docs/apps/fulfillment/fulfillment-service-apps/manage-fulfillments)

***
