👀 See Sanity in action: Watch product demo now →

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
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.io – build remarkable experiences at scale

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