Create a new content item
This recipe shows how to create a new content item in draft status using the Content API. The request includes a display name, title, body content, and route segment. Use this when you want to programmatically add new content that is saved as a draft for later review or publishing.
curl --request POST \
--url https://api.cms.optimizely.com/v1/content \
--header 'Accept: application/json' \
--header 'Authorization: Bearer {access_token}' \
--header 'content-type: application/json' \
--data '{
"contentType": "ArticlePage",
"container": "{container_key}",
"initialVersion": {
"displayName": "My First Article",
"locale": "en",
"routeSegment": "my-first-article",
"properties": {
"heading": {
"value": "Hello World"
}
}
}
}'
Define the request method and endpoint
Use POST to create a new content item at the Content API endpoint.
This corresponds to the following section in the code:
curl --request POST \
--url https://api.cms.optimizely.com/v1/content \Set required headers
Add headers to specify content type and authentication.
- Accept – Response format.
- Authorization – Your bearer token.
- content-type – Request body format.
This corresponds to the following section in code:
--header 'Accept: application/json' \
--header 'Authorization: Bearer {access_token}' \
--header 'content-type: application/json' \Provide the request body
Define the content item properties. In this example, the content item is created as a draft with a title, body text, and a route segment. Note that the v1 API uses a NewContent structure with initialVersion for version-specific data, and property values are wrapped in {"value": ...} objects.
This corresponds to the following section in code:
--data '{
"contentType": "ArticlePage",
"container": "{container_key}",
"initialVersion": {
"displayName": "My First Article",
"locale": "en",
"routeSegment": "my-first-article",
"properties": {
"heading": {
"value": "Hello World"
}
}
}
}'