Private Models
When you need a model that is only privately accessible, you can adjust the configuration of your model, use a Private API Key, as well as the Content API to ensure privacy.
Making a model private
By default, Builder Page, Section, and Data models are publicly readable.
To make a model private:
- Go to Models.
- Open your page model.
- Go to Advanced.
- Switch the Public Readable toggle to off.
- Click Save.
- Create content entries from this model for any that you'd like to be private.
The following video shows how to toggle off the Public Readable setting for a Page model, but you can change this setting on any kind of model.
Creating a Private API Key
To leverage a private model, you need to create a Private API Key in your Organization Settings. Follow the instructions in the Managing Private Keys section of the API Keys documentation.
When you have your Private API Key, continue with the instructions below.
Adding the code
Use the Content API with your Private API key with the following code, where you replace these values with your own:
modelName
yourPublicAPIKey
yourPrivateAPIKey
let apiUrl = 'https://cdn.builder.io/api/v2/content'
let modelName = 'private-page'
let content = await request(`${apiUrl}/${modelName}?apiKey=${yourPublicAPIKey}&limit=1&userAttributes.urlPath=/some-page`, {
headers: { Authorization: `Bearer ${yourPrivateAPIKey}` },
})
Next, pass the JSON to render as needed; for example as in this React snippet for a model named private-page:
let page = content.results[0];
if (page) {
return <BuilderComponent model="private-page" content={page} />
}