How AI is powering better personalization in e-commerce [with Vercel]. Sign up now

Different results between curl query and Sanity client fetch methods

8 repliesLast updated: Nov 29, 2025

Hello! Is there any reason I would get different results between these two methods of querying data?

curl <https://xuaf19yr.api.sanity.io/v1/data/query/production>\?query\=\*%5B_type%20%3D%3D%20%22articlePage%22%5D%20%7B%0A%09...%0A%7D

const sanity = require('@sanity/client')

const sanityClient = sanity({
  projectId: 'xuaf19yr',
  dataset: 'production',
  useCdn: false,
})

await sanityClient.fetch(`
  *[_type == "articlePage"] {
    ...
  }
`)
Any help appreciated!
AI Update

Yes! The most likely reason you're getting different results is due to API versioning and perspective differences between your two query methods.

The Key Differences

1. API Version Default

Your curl request is hitting the API directly without specifying an apiVersion, which means it defaults to v1 of the API. However, your @sanity/client code also doesn't specify an apiVersion, which similarly defaults to v1 - but there's a catch with how the client behaves.

2. Perspective Default (Most Likely Culprit)

The bigger issue is likely the perspective. As of API version 2025-02-19, the default perspective changed from raw to published. However, when you use an authenticated token with @sanity/client, the behavior can differ:

The Solution

Make your @sanity/client configuration explicit to ensure consistent behavior:

const sanity = require('@sanity/client')

const sanityClient = sanity({
  projectId: 'xuaf19yr',
  dataset: 'production',
  useCdn: false,
  apiVersion: '2025-02-19', // Always specify this!
  perspective: 'published',  // Explicitly set perspective
})

await sanityClient.fetch(`
  *[_type == "articlePage"] {
    ...
  }
`)

Why This Matters

Without specifying apiVersion and perspective:

The perspective setting controls which document versions you see:

Always explicitly set both apiVersion and perspective in your client configuration to avoid surprises!

Show original thread
8 replies

Was this answer helpful?

Sanity – Build the way you think, not the way your CMS thinks

Sanity is the developer-first content operating system that gives you complete control. Schema-as-code, GROQ queries, and real-time APIs mean no more workarounds or waiting for deployments. Free to start, scale as you grow.

Related contributions