create-resource
Learn how to create Croct resources.
This action creates Croct resources such as components, slots, audiences, and experiences in the workspace.
Creating a resource only provisions it in the workspace. To add it to the project, use add-component for components and add-slot for slots.
Before creating a resource, the action checks whether a similar one already exists based on its ID and definition. When a match is found, the existing resource is reused instead of creating a duplicate.
This makes the action idempotent — running the same template multiple times does not consume additional workspace quota or produce redundant resources.
Because the matched resource may have a different ID or version than the one specified in the template, capturing the result is important when subsequent actions depend on precise identifiers.
Example
The following template creates a component, a slot, an audience, and an experience that personalizes the slot for logged-in users. It also captures the slot ID for use in a subsequent add-slot action:
{ "$schema": "https://schema.croct.com/json/v1/template.json", "title": "Personalized banner", "description": "Creates a personalized banner for logged-in users.", "actions": [ { "name": "create-resource", "resources": { "components": { "top-bar": { "name": "Top bar", "schema": { "type": "structure", "attributes": { "message": { "type": { "type": "text" }, "label": "Message", "position": 0 } } } } }, "slots": { "home-banner": { "name": "Home banner", "component": "top-bar", "content": { "en": { "type": "structure", "attributes": { "message": { "type": "text", "value": { "type": "static", "value": "Welcome to our site!" } } } } } } }, "audiences": { "logged-in-users": { "name": "Logged-in users", "criteria": "user is identified" } }, "experiences": [ { "name": "Logged-in banner", "audiences": ["logged-in-users"], "slots": ["home-banner"], "content": { "default": { "home-banner": { "en": { "type": "structure", "attributes": { "message": { "type": "text", "value": { "type": "static", "value": "Welcome back!" } } } } } } } } ] }, "result": { "slots": { "home-banner": { "id": "bannerSlotId", "version": "bannerSlotVersion" } } } }, { "name": "add-slot", "slots": ["${this.bannerSlotId}@${this.bannerSlotVersion}"] } ]}To apply this template, run:
npx croct@latest use template.json5All resources are provisioned in the workspace. Logged-in users see "Welcome back!" in the banner, while other visitors see the slot's default content. The result captures the slot ID and version so that add-slot references the exact resource, regardless of whether it was newly created or matched from an existing one.
Properties
These are the supported properties:
- namestring
The action identifier. Always create-resource for this action.
- resourcesobject
The resources to create in the workspace.
At least one resource type must be specified.
- components(optional)object
A map of component IDs to component definitions.
- namestring
The display name shown in the interface.
- description(optional)string
A brief description of the component.
Shown in the interface to help editors understand the component's purpose.
- schema
The schema defining the component's structure.
See Content schema for more information.
- name
- slots(optional)object
A map of slot IDs to slot definitions.
- namestring
The display name shown in the interface.
- componentstring
The ID of the component this slot uses.
Must reference a component defined in this template or already existing in the workspace.
- contentRecord<string,Content>
A map of locale codes to content values.
Each locale must exist in the workspace. For example, en or pt-br.
See Content definition for more information.
- name
- audiences(optional)object
- experiences(optional)Array<object>
A list of experience definitions.
- namestring
The display name shown in the interface.
- draft(optional)boolean
Whether the experience starts as a draft.
Draft experiences are not published and can be partially defined. When false, the experience is published immediately.
Default:false- audiencesArray<string>
The audience IDs this experience targets.
Each ID must reference an audience defined in this template or already existing in the workspace.
- slotsArray<string>
The slot IDs this experience personalizes.
Each ID must reference a slot defined in this template or already existing in the workspace.
- contentobject
The personalized content for the experience.
- default(optional)Record<string,Record<string,Content>>
The catch-all content shown when no segmented content matches.
Structured as a map of slot IDs to a map of locale codes to content values.
- segmented(optional)Array<object>
A list of audience-specific content overrides.
Each entry targets one or more audiences with dedicated content.
- audiencesArray<string>
The audience IDs this content applies to.
Users matching any of these audiences see this content.
- contentRecord<string,Record<string,Content>>
The content for this audience group.
Structured as a map of slot IDs to a map of locale codes to content values.
- audiences
- default(optional)
- experiment(optional)object
An A/B experiment to run within this experience.
When specified, the experience splits traffic between variants to measure which performs better.
- namestring
The display name shown in the interface.
- trafficnumber
The percentage of traffic to include in the experiment.
Expressed as a decimal between 0 and 1. For example, 0.5 means 50% of visitors participate in the experiment, while the remaining 50% see the experience's default content.
- variantsArray<object>
The list of experiment variants.
At least two variants are required.
- namestring
The display name shown in the interface.
- contentobject
The personalized content for this variant.
- default(optional)Record<string,Record<string,Content>>
The catch-all content shown when no segmented content matches.
Structured as a map of slot IDs to a map of locale codes to content values.
- segmented(optional)Array<object>
A list of audience-specific content overrides.
Each entry targets one or more audiences with dedicated content.
- audiencesArray<string>
The audience IDs this content applies to.
Users matching any of these audiences see this content.
- contentRecord<string,Record<string,Content>>
The content for this audience group.
Structured as a map of slot IDs to a map of locale codes to content values.
- audiences
- default(optional)
- allocationnumber
The relative traffic weight for this variant.
The ratio between variants determines how traffic is split. For example, values of 2 and 1 give the first variant twice the traffic of the second.
- baseline(optional)boolean
Whether this is the control variant.
The baseline serves as the reference for measuring the performance of other variants.
Default:false
- name
- goalId(optional)string
The identifier of the goal used to measure the experiment's success.
- crossDevice(optional)boolean
Whether to keep variant assignment consistent across devices.
When enabled, identified users see the same variant across all their devices. This relies on the user ID for identification, so it only applies to logged-in users.
Default:false
- name
- name
- components(optional)
- result(optional)object
Variables to capture the IDs and versions of created or matched resources.
The structure mirrors resources, mapping each resource key to variable names. Because duplicate detection may match an existing resource, the captured values can differ from the IDs specified in the template.
- components(optional)object
- slots(optional)object
- audiences(optional)object
A map of audience IDs to variable names.
Each value is the variable name to store the resolved audience ID.
- experiences(optional)object
A map of zero-based indexes to variable names.
Each value is the variable name to store the experience ID.
- experiments(optional)object
A map of zero-based indexes to variable names.
Each value is the variable name to store the experiment ID.
- components(optional)