π 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:
- TypeScript
- JavaScript
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;
const { createShopifyClient } = require("@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,
});
const getPolicy = async (args) => {
return await client.getPolicy(args, {
cacheTtl: 60,
revalidate: 60,
useMemoryCache: true,
useVercelCache: true,
});
};
export default client;
Usage:
- TypeScript
- JavaScript
import { getPolicy } from "lib/nextshopkit/client";
const { data: PolicyData, error: PolicyError } = await getPolicy({
type: type,
customHandles,
debug: true,
});
// Consume PolicyData
// Manage PolicyError
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 β
Description
Fetch a single Shopify policy using either the Storefront API or a custom CMS page.