🎤 Builder Talk: The Story Behind Lady Gaga’s Digital Experience – Register now

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.
https://sanity-io-land.slack.com/archives/C01T1B5GVEG/p1624550975405600
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


client.create(obj);
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 <https://sapper.svelte.dev/docs#Route_conflicts>
 */
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'
    });

    res.end(JSON.stringify({
      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?

Related answers

Get more help in the community Slack

TopicCategoriesFeaturedRepliesLast Updated
Hey all - what’s the quickest way to batch delete all documents of a certain type? It looks like the `sanity` cli tool allows...Jan 29, 2021
Deploying Next JS on VercelJan 20, 2021
In the tutorial, there is samples of what the API returns as JSON. Is there a way to view these ?Jan 11, 2021
DOMParser is not defined at defaultParseHtmlDec 3, 2020
Warning: Data for Page Exceeds the Threshold of 128 kBAug 17, 2022
Custom Document Views - Is it Even Possible to Use the Structure Builder?Apr 21, 2022
How to get the number of nested/children components in a GROQ query.Jan 19, 2024
Issue with fetching data from an array of references and non-references in a groq query.Dec 14, 2023
Error in Next.js tutorial with event handlers in server components.Feb 28, 2024
GraphQL query resolving references on a _raw field in GatsbyMay 17, 2022

Related contributions

Turbo Start Sanity
- Template

The battle-tested Sanity template that powers Roboto Studio's websites

Go to Turbo Start Sanity

Schema UI - Next.js Sanity Starter
- Template

A Next.js starter template with Next.js 15, Tailwind CSS, shadcn/ui, and Sanity CMS with Live Editing. Get production-ready React components with matching Sanity schemas and queries. Build dynamic pages faster while keeping full control over customization.

Serge Ovcharenko
Go to Schema UI - Next.js Sanity Starter

The Swaddle
- Made with Sanity

A new brand identity to represent a more mature company, to signify The Swaddle’s evolution from publisher to production house, combined with an easier to navigate platform that can surface multiple content types - drawing readers through The Swaddle’s content offering.

Nightjar
Go to The Swaddle