0

I am getting this warning in the console and could not able to clearly understand the documentation.

warnings.js:16 Using the Sanity client without specifying an API version is deprecated. See https://docs.sanity.io/help/js-client-api-version

I would like it to always have the latest API version. Here is how my connection looks like

import santiyClient from "@sanity/client";

export default santiyClient({
  projectId: "myProjectID",
  dataset: "production",
  useCdn: true,
});
harsha20599
  • 119
  • 3
  • 11

2 Answers2

2

You can specify an API version when you configure your client:

import sanityClient from "@sanity/client";

export default sanityClient({
  projectId: "myProjectID",
  dataset: "production",
  useCdn: true,
  apiVersion: "2022-02-03"
});

It's best to hard code your API version to the date you implement it. That way, it's guaranteed to work as you expect. If you were to use a JavaScript Date to always return whatever today is, a breaking change could be put in place that causes the client to no longer work. There are a few more details in the documentation here.

Geoff Ball
  • 743
  • 3
  • 14
0

You should also create token and pass the token:

import sanityClient from '@sanity/client'

export const client = sanityClient({
  projectId: 'projectId',
  dataset: 'production',
  apiVersion: '2021-03-25',
  token: 'click API tab and add new token',
  useCdn: false,
})
Yilmaz
  • 35,338
  • 10
  • 157
  • 202