Skip to main content

πŸ“œ getPolicy() Overview

getPolicy() allows you to fetch a single policy document from Shopify using either:

  • A native Shopify policy (like Privacy or Refund Policy), or
  • A custom CMS page with a specific handle.

It intelligently detects which source to use and gives you back a normalized result.


βœ… When to Use This​

  • You want to render legal or informational pages in your storefront
  • You need to override native Shopify policies with custom content
  • You want to support multi-language handles or CMS logic

🧩 Used with @nextshopkit/pro​

If you are using the Pro SDK client, you can call this function like so:

lib/nextshopkit/client.ts
import {
createShopifyClient,
GetPolicyOptions,
FetchPolicyResult,
} from "@nextshopkit/pro";

const client = createShopifyClient({
shop: process.env.SHOPIFY_STORE_DOMAIN!,
token: process.env.SHOPIFY_ACCESS_TOKEN!,
apiVersion: "2025-01",
enableMemoryCache: true,
defaultCacheTtl: 300,
enableVercelCache: true,
defaultRevalidate: 60,
});

export const getPolicy = async (
args: GetPolicyOptions
): Promise<FetchPolicyResult> =>
client.getPolicy(args, {
cacheTtl: 60,
revalidate: 60,
useMemoryCache: true,
useVercelCache: true,
});

export default client;

Usage:

import { getPolicy } from "lib/nextshopkit/client";

const { data: PolicyData, error: PolicyError } = await getPolicy({
type: type,
customHandles,
debug: true,
});

// Consume PolicyData
// Manage PolicyError

πŸ” Native vs Custom Policies​

There are two types of policies supported:

πŸͺ Native (Shopify)​

Shopify has 4 built-in policies available from the Storefront API:

  • "privacyPolicy"
  • "refundPolicy"
  • "shippingPolicy"
  • "termsOfService"

These are fetched from the shop object and include a url if available.

πŸ“ Custom (CMS)​

You can create custom pages (e.g. β€œLegal Notice”, β€œCookie Policy”) and fetch them using:

customHandles: {
legalNotice: "mentions-legales",
}

You’ll receive raw HTML content (body), title, handle, and publication status.


🧬 Output Shape​

Returns a normalized result of type FetchPolicyResult:

{
data: {
id: string;
title: string;
handle: string;
type: string;
from: "shop" | "page";
published: boolean;
body: string;
url?: string;
};
error: string | null;
}

βœ… Next: Options Reference β†’