📜 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.
For fetching all policies at once, see getPolicies()
which is also available in the PRO tier.
✅ 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-04",
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-04",
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.