Watch a live product demo 👀 See how Sanity powers richer commerce experiences

How to Automate Creating Schema during the Create Project Flow

6 replies
Last updated: May 12, 2021
Just touching base here again - really would like to know if there is a way to automate creating the Schema during the create project flow. I can add assets without issue, but it seems I need to add a schema before I can add the documents (which makes sense). The less-clear part is why there doesn't seem to be a way to do this with the API. Fortunately, there are tons of providers that enable you to create content types through the API; I'd just be surprised if Sanity didn't offer that, and I'd much prefer to stick with Sanity, if possible.
With that being said, if there isn't currently a way to automate creating the schema before populating a project with documents, then I may need to find an alternative solution
😕
May 12, 2021, 3:32 PM
For comparison, Contentful does allow you to create content types through their API, but they strongly discourage it (no idea why, though)
Flotiq (probably going to be my next best bet) touts being able to create and manage content types through the API, which is pretty much exactly what I am looking for. I can't find a way to do this with Sanity, though - still digging where I can, but reaching the end of my road here.
May 12, 2021, 3:34 PM
As far as I know, the schema and the API aren’t really related. The schema is a studio document so I expect you’d want to create it as part of the project bootstrapping process. Using the API to create a Sanity project is one small part of the bigger project creation process (like the starters at sanity.io/create all do). There are some details here but I’ve never tried creating a starter myself so I could be wrong.
May 12, 2021, 3:47 PM
The problem with that flow is that I need to create the schema in the process of creating the project. I figured the content API is unrelated, but most of these providers also have some kind of "account management" API, which I thought may have been the place to do this, but seems not.
I can explore creating a starter, but that's really not what I intended for this tool I am making; it's geared towards helping newer developers get started hosting their Minecraft mod content on a well-formatted site template. Since they are new developers, I'm trying to not have them get "too tied into" any one provider.

In other words, I don't want them to have to become "Sanity experts" just to moderate their site content (though I would like for them to customize later once they are more comfortable). The application I'm making is a standalone CLI that can hypothetically link into
any CMS provider; I'm just at the junction where I need to decide which CMS providers I should support.
It's starting to sound like the solution for Sanity would be a highly-customized approach that would only be applicable for Sanity - is that the case?
May 12, 2021, 4:10 PM
I get that the schema is a document - the "easiest" solution I could find would be to have the user
cd
into their sanity studio and then download some schema files (or, riskier approach, code generation based on selected fields).
The problem there is that it's an entirely separate step in a different location; I'd like to have this flow work straight from the CLI so that the user can switch over to the studio and just start firing away with site content moderation.
May 12, 2021, 4:13 PM
That’s fair. The reason there are so many starters is because each generates its own schema to meet its particular needs. I’m not sure how you would best proceed when you want to bootstrap their project but also give them significant leeway.
For the last bit, I would probably chain commands in package.json so they only need to know the one command:


"scripts": {
  "go": "sanity init -y --create-project Minecraft --dataset production --output-path=./studio && cd studio && ..."
}
May 12, 2021, 4:23 PM
Thanks for the feedback,
user A
!
So, it sounds like the only way is to make a starter; got it. Looks like I have some more learning to do! Thanks for the assistance
🙂
May 12, 2021, 4:51 PM

Sanity– build remarkable experiences at scale

The Sanity Composable Content Cloud is the 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.

Related answers

Get more help in the community Slack

TopicCategoriesFeaturedRepliesLast Updated
After adding the subtitle and running this code npm run graphql-deploy It does nothingSep 15, 2020
how to limit a reference to just one entry in Studio reference input side versus the default as-many-entries-as-you-fill-in-an-array...Sep 18, 2020
Is it possible to fetch more than one "_type" using GROQ?Nov 2, 2020
I want to add a view with the Structure builder (S.view.component) where I list similar documents based on the title. What...Sep 23, 2020
Is there a structure builder example where the format of each preview for the document list is modified?Feb 3, 2021
I have an array of references to a country schema type but it always just returns NULL values for meJan 30, 2021
Hi, I need help with a query for getting the url of an image asset. Here is what I've been trying, but I only get the _ref...Dec 1, 2020
Sanity UI looks brilliant :smiley: Is something like the current date picker possible at the moment? I’m not sure if anicon...Dec 21, 2020
Hey everyone. I have been coding and may have potentially accidentally deleted something. Does anyone know how to resolve...Dec 26, 2020
Hello everyone and happy new year :raised_hands::skin-tone-2:, I have a problem with outputting Portable Text :disappointed:...Jan 1, 2021

Related contributions

Clean Next.js + Sanity app
- Template

Official(made by Sanity team)

A clean example of Next.js with embedded Sanity ready for recomposition.

Cody Olsen
Go to Clean Next.js + Sanity app

Blog with Built-in Content Editing
- Template

Official(made by Sanity team)

A Sanity-powered blog with built-in content editing and instant previews.

Go to Blog with Built-in Content Editing