Issue with creating documents in Sanity project not being published

10 replies
Last updated: Jul 6, 2021
Hi! I already asked this question without answer, and it seem to have been buried so I ask it again.
I have created a Node (Javascript) script to input data into my dataset with the sanity client.

I create my client like this (with real values):

const sanityClient = require('@sanity/client')
const client = sanityClient({
  projectId: 'your-project-id',
  dataset: 'bikeshop',
  apiVersion: '2019-01-29', // use current UTC date - see "specifying API version"!
  token: 'sanity-auth-token', // or leave blank for unauthenticated usage
  useCdn: true, // `false` if you want to ensure fresh data
Then I create a matching javascript object and call

All works fine and the document is created but it is not published. (this is an issue because I need to create a few hundred documents so I dont want to manually publish them).
Jul 6, 2021, 8:19 AM
The left pic is my document created with the javascript code, then right one is one I manually added.
When I fetch these with a query I only get the ones I manually publish, the other ones does not show up, neither in my local fe, nor my public one.
Jul 6, 2021, 8:21 AM
There is no pencil icon or anything next to the post either.
Jul 6, 2021, 8:21 AM
I tried running a patch but it still doesnt publish.
Jul 6, 2021, 8:48 AM
I actually tried without it, and I just tried setting up a new sanity project, and there it works fine.
In my current (faulty) project i tried fetching through the routes the way it is done in the template:

import { client } from '../../sanityClient';

 * This route is called 'all' instead of index to prevent route conflicts.
 * @see <>
export async function get (req, res) {
  try {
    const posts = await client.fetch('*[_type == "productContent" && defined(slug.current)]')
    res.end(JSON.stringify({ posts }));
  } catch (err) {
    res.writeHead(500, {
      'Content-Type': 'application/json'

      message: err.message
And this still doesnt show the new document
Jul 6, 2021, 2:59 PM
So it's for sure an issue with our Sanity project. Since I input and fetch the same in both the projects.
Jul 6, 2021, 3:00 PM
Such a bittersweet feeling in those cases where you’re happy your code works but frustrated trying to figure out why it won’t work on this project.
Jul 6, 2021, 3:01 PM
exactly haha. We have a theory that it could be the "intl-input" plugin.
Jul 6, 2021, 3:03 PM
user A
you were actually right my man.I added the i18n_lang field and now it works
Jul 6, 2021, 3:22 PM
so thank you!
Jul 6, 2021, 3:22 PM
Great! Glad to hear it. 🙌
Jul 6, 2021, 3:27 PM

Sanity– build remarkable experiences at scale

Sanity is a modern headless CMS that treats content as data to power your digital business. Free to get started, and pay-as-you-go on all plans.

Was this answer helpful?