# Agent API


The Agent API allows AI agents to take direct action in Sitecore through secure REST endpoints. It supports common digital experience tasks such as creating pages, adding components, and updating content.

As part of Sitecore's [*interoperability*](https://doc.sitecore.com/xmc/en/users/xm-cloud/integrating-sitecore-with-agentic-platforms.html) approach, the Agent API allows agentic platforms and other connected systems to interact directly with Sitecore. When an AI agent receives a natural language request, it can call the appropriate Agent API endpoints to complete the task. For example, a request to create a new landing page might trigger an endpoint in Sitecore that automatically builds the page. If the AI agent performs an unintended action, you can use the job ID to revert it. Each operation is tracked to ensure safe rollback when needed.

All Agent API actions follow the built-in security and approval rules in Sitecore, keeping work safe, traceable, and auditable.

In addition to AI agent-driven workflows, developers can also use the REST API directly to interact with the following objects:

- **Sites** - retrieve and manage sites and their pages.
- **Pages** - create and manage pages and components.
- **Content** - create and organize content items.
- **Components** - retrieve and manage components and datasources.
- **Assets** - upload and manage digital assets.
- **Environments** - retrieve environment and language details.
- **Personalization** - manage personalized content variants.
- **Jobs** - view or revert job operations. 
- **Brand kits** - retrieve brand kits and their details. 
- **Briefs** - retrieve brief types, generate and create briefs.


Note the following:

- To use this REST API, you authenticate your API requests.
- All API requests are made in your production environment.

The Agent API also powers the Marketer MCP, which uses these endpoints to perform agentic operations in Sitecore. Read more about the [Marketer MCP](https://doc.sitecore.com/xmc/en/users/xm-cloud/marketer-mcp.html/).

# Authorization
 To authorize your requests, use environment automation client credentials and generate a JSON Web Token (JWT). You can also register an OAuth app if your integration requires the OAuth 2.0 authorization code flow.

Note: To create client credentials, you must be an [Organization Admin](https://doc.sitecore.com/portal/en/developers/sitecore-cloud-portal/roles.html) or Organization Owner.

## Create an automation client
 1. In the Sitecore Cloud Portal, open SitecoreAI Deploy.
 2. Click **Credentials** > **Environment** > **Create credentials** > **Automation**.
 3. Fill out the automation client details, then click **Create**.
 4. Copy the client ID and the client secret because you won't be able to view them again in SitecoreAI Deploy. You'll use them to request a JWT.

## Register an OAuth app for the Agent API 
The Agent API uses the OAuth 2.0 authorization code flow to securely authenticate requests from external applications.

 Each application must have an OAuth app registration, which identifies the app and defines the parts of the Sitecore platform it can access. 

 If you plan to register an OAuth app that uses the Agent API, you must submit a registration request to Sitecore Support and request the following scopes:
 - `xmcloud.cm:admin` 
 - `personalize.exp:mng` 
 - `personalize.tmpl:r` 
 - `personalize.pos:mng` 
 - `ai.org.bri:r` 
 - `co.briefs:r` 
 - `co.briefs:w`  
- `ai.org.brd:r` 
- `ai.org.bri:w`  
## Request a JWT

Run the following cURL command to request a JWT. Replace the placeholder values with your client ID and client secret.

```curl
  curl -X POST 'https://auth.sitecorecloud.io/oauth/token' \
  --header 'Content-Type: application/x-www-form-urlencoded' \ 
  --data-urlencode 'client_id={YOUR_CLIENT_ID}' \
  --data-urlencode 'client_secret={YOUR_CLIENT_SECRET}' \
  --data-urlencode 'grant_type=client_credentials' \
  --data-urlencode 'audience=https://api.sitecorecloud.io'
```

In the response, the `access_token` key contains the JWT:

```json
  {
    "access_token": "{YOUR_JWT}",
    "scope": "xmcloud.cm:admin",
    "expires_in": 86400,
    "token_type": "Bearer"
  }
```

The JWT expires in 24 hours. If your requests unexpectedly return a response with status `401 Unauthorized`, request a new JWT by repeating this `POST` request.

We recommend that you cache the JWT for 24 hours to avoid repeating this `POST` request while the JWT is still valid.

## Include the JWT in the request header

You can now start making REST API requests. You must include the JWT in the request header of every request. For example:
```curl
  curl -X GET '{YOUR_BASE_URL}/...' \
  -H 'Authorization: Bearer {YOUR_JWT}' \
  -H 'Accept: application/json'
```


Version: v1.0
License: Closed source
Metadata:
  - product: SitecoreAI

## Servers

Production server
```
https://edge-platform.sitecorecloud.io/stream/ai-agent-api
```

## Security

### HTTPBearer

Type: http
Scheme: bearer
Bearer Format: JWT

## Download OpenAPI description

[Agent API](https://api-docs.sitecore.com/_bundle/sai/agent-api/index.yaml)

## Sites

The Sites API lets you retrieve all sites, retrieve details about a specific site, list pages of a site, and retrieve a site ID associated with an item ID.

### List sites

 - [GET /api/v1/sites](https://api-docs.sitecore.com/sai/agent-api/sites/sites-get_sites_list.md): Retrieves a list of available sites with their basic information including name, display name, and URL.

### Retrieve the site details

 - [GET /api/v1/sites/{siteId}](https://api-docs.sitecore.com/sai/agent-api/sites/sites-get_site_details.md): Retrieves the details of a specific site including its  ID, name, and root path.

### List pages of a site

 - [GET /api/v1/sites/{siteName}/pages](https://api-docs.sitecore.com/sai/agent-api/sites/sites-get_all_pages_by_site.md): Retrieves a list of pages for a specific site, including each page's ID and path. You can optionally filter the pages by language.

### Retrieve a site ID from an item ID

 - [GET /api/v1/sites/site-id-from-item/{itemId}](https://api-docs.sitecore.com/sai/agent-api/sites/sites-get_site_id_from_item.md): Retrieves the site ID associated with a specific item ID. This is useful for determining which site an item belongs to.

## Pages

The Pages API lets you create new pages, add new language versions or components to a page, search for pages on a site, set the component datasource on a page, retrieve page components, paths, HTML, preview URL, screenshots, templates, details, and allowed components.

### Create a page

 - [POST /api/v1/pages/create](https://api-docs.sitecore.com/sai/agent-api/pages/pages-create_page.md): Creates a new page using the specified template under the parent page. You can set field values and the language for the new page.

### Add a language version to a page

 - [POST /api/v1/pages/{pageId}/add-language](https://api-docs.sitecore.com/sai/agent-api/pages/pages-add_language_to_page.md): Adds a new language version for an existing page. This allows you to have the same page content available in multiple languages.

### Add a component to a page

 - [POST /api/v1/pages/{pageId}/components](https://api-docs.sitecore.com/sai/agent-api/pages/pages-add_component_on_page.md): Adds a component to a specific placeholder on a page. You can specify the component type, placeholder location, and configure its initial settings. Optionally, you can specify its position relative to an existing component.

### Retrieve components on a page

 - [GET /api/v1/pages/{pageId}/components](https://api-docs.sitecore.com/sai/agent-api/pages/pages-get_components_on_page.md): Retrieves a list of components that are currently added to a specific page.

### Set the component datasource

 - [POST /api/v1/pages/{pageId}/components/{componentId}/datasource](https://api-docs.sitecore.com/sai/agent-api/pages/pages-set_component_datasource.md): Sets the datasource for a specific component on a page. You can specify a new data source item or clear the existing one.

### Search for pages on a site

 - [GET /api/v1/pages/search](https://api-docs.sitecore.com/sai/agent-api/pages/pages-search_site.md): Searches for all  pages in a specific site using a search term that matches page titles and content. The response returns the matching pages with their details including the page ID, path, and name.

### Retrieve the page path by live URL

 - [GET /api/v1/pages/path-by-url](https://api-docs.sitecore.com/sai/agent-api/pages/pages-get_page_path_by_live_url.md): Retrieves the page item path that corresponds to a live URL on a website.

### Retrieve the screenshot of a page

 - [GET /api/v1/pages/{pageId}/screenshot](https://api-docs.sitecore.com/sai/agent-api/pages/pages-get_page_screenshot.md): Retrieves the screenshot of a specific page. This endpoint captures and returns a base64-encoded image of the live page.

### Retrieve the page HTML

 - [GET /api/v1/pages/{pageId}/html](https://api-docs.sitecore.com/sai/agent-api/pages/pages-get_page_html.md): Retrieves the HTML content of a specific page. This endpoint returns the raw HTML of the page as it would appear in the browser.

### Retrieve the page preview URL

 - [GET /api/v1/pages/{pageId}/preview-url](https://api-docs.sitecore.com/sai/agent-api/pages/pages-get_page_preview_url.md): Retrieves the preview URL of a specific page. This endpoint returns the URL that can be used to preview the page.

### Retrieve the page template by ID

 - [GET /api/v1/pages/template-by-id](https://api-docs.sitecore.com/sai/agent-api/pages/pages-get_page_template_by_id.md): Retrieves the details of a specific page template, including its fields and settings. Use this endpoint to understand the structure and available fields of a template before creating a page.

### Retrieve the page details

 - [GET /api/v1/pages/{pageId}](https://api-docs.sitecore.com/sai/agent-api/pages/pages-get_page.md): Retrieves the details about a page including its ID, name, and path location. This endpoint provides the information you need to understand and modify the page's structure.

### List allowed components for a placeholder

 - [GET /api/v1/pages/{pageId}/placeholders/{placeholderName}/allowed-components](https://api-docs.sitecore.com/sai/agent-api/pages/pages-get_allowed_components_by_placeholder.md): Retrieves the list of components that can be added to a specific placeholder on a page. This ensures only compatible components are used in each placeholder. You can use * to fetch all components.

## Content

The Content API lets you create, retrieve, update, delete and organize structured content items, and retrieve insert options.

### Create content item

 - [POST /api/v1/content/create](https://api-docs.sitecore.com/sai/agent-api/content/content-create_content_item.md): Creates a new content item using the specified template and field values.

### Retrieve a content item by ID

 - [GET /api/v1/content/{itemId}](https://api-docs.sitecore.com/sai/agent-api/content/content-get_content_item_by_id.md): Retrieves the details of a specific content item by specifying its ID.

### Update a content item

 - [PUT /api/v1/content/{itemId}](https://api-docs.sitecore.com/sai/agent-api/content/content-update_content.md): Updates an existing content item, including its fields and language.

### Delete a content item

 - [DELETE /api/v1/content/{itemId}](https://api-docs.sitecore.com/sai/agent-api/content/content-delete_content.md): Deletes a content item and optionally all of its child items.

### Retrieve a content item by path

 - [GET /api/v1/content](https://api-docs.sitecore.com/sai/agent-api/content/content-get_content_item_by_path.md): Retrieves the details of a content item by specifying its path in the content tree.

### List insert options

 - [GET /api/v1/content/{itemId}/insert-options](https://api-docs.sitecore.com/sai/agent-api/content/content-list_available_insertoptions.md): Retrieves a list of content templates that can be inserted as child items under the specified parent item.

## Components

The Components API lets you retrieve components, get the details of a specific component, search datasources in a component, and create a component datasource.

### Create a component datasource

 - [POST /api/v1/components/{componentId}/datasources](https://api-docs.sitecore.com/sai/agent-api/components/components-create_component_datasource.md): Creates a new datasource item for a specific component using the provided data field values. The datasource will be created in the appropriate location based on the component's configuration.

### Search for component datasources

 - [GET /api/v1/components/{componentId}/datasources/search](https://api-docs.sitecore.com/sai/agent-api/components/components-search_component_datasources.md): Searches for available datasources that can be used with a specific component. This helps you find existing content to use as datasources.

### List components

 - [GET /api/v1/components](https://api-docs.sitecore.com/sai/agent-api/components/components-list_components.md): Retrieves a list of components available for a specific site, including both built-in components and custom components that can be used on pages.

### Retrieve the component details

 - [GET /api/v1/components/{componentId}](https://api-docs.sitecore.com/sai/agent-api/components/components-get_component.md): Retrieves the details of a specific component, including its ID, name, and datasource options.

## Assets

The Assets API lets you upload, search assets, retrieve asset details, and update asset metadata.

### Upload an asset

 - [POST /api/v1/assets/upload](https://api-docs.sitecore.com/sai/agent-api/assets/assets-upload_asset.md): Uploads a new digital asset to the system and stores it with the provided metadata.

### Search for assets

 - [GET /api/v1/assets/search](https://api-docs.sitecore.com/sai/agent-api/assets/assets-search_assets.md): Searches for digital assets such as videos, images, and documents using query terms, file types, or tags.

### Retrieve the asset details

 - [GET /api/v1/assets/{assetId}](https://api-docs.sitecore.com/sai/agent-api/assets/assets-get_asset_information.md): Retrieves the details of a specific digital asset by specifying its ID.

### Update an asset

 - [PUT /api/v1/assets/{assetId}](https://api-docs.sitecore.com/sai/agent-api/assets/assets-update_asset.md): Updates the metadata and properties of an existing digital asset, such as alt text, description, and tags.

## Environments

The Environments API lets you retrieve available languages in your environment. 

### List languages

 - [GET /api/v1/environments/languages](https://api-docs.sitecore.com/sai/agent-api/environments/environments-list_languages.md): Retrieves all languages available.

## Personalization

The Personalization API lets you create personalized variants for different audiences by showing targeted content based on certain conditions.

### Create a personalization variant

 - [POST /api/v1/personalization/{pageId}/versions](https://api-docs.sitecore.com/sai/agent-api/personalization/personalization-create_personalization_version.md): Creates a new personalization variant of a page, enabling you to define targeting rules for different audiences.

### List personalization variants by page

 - [GET /api/v1/personalization/by-page/{pageId}](https://api-docs.sitecore.com/sai/agent-api/personalization/personalization-get_personalization_versions_by_page.md): Retrieves all personalization variants defined for a specific page, including IDs, names, creation dates, and associated variants.

### List personalization condition templates

 - [GET /api/v1/personalization/condition-templates](https://api-docs.sitecore.com/sai/agent-api/personalization/personalization-get_condition_templates.md): Retrieves all available condition templates for personalization.

### Retrieve a personalization condition template

 - [GET /api/v1/personalization/condition-templates/{template_id}](https://api-docs.sitecore.com/sai/agent-api/personalization/personalization-get_condition_template_by_id.md): Retrieves a condition template by ID including its parameters for creating a personalization variant on a page.

## Jobs

The Jobs API lets you retrieve all details and operations of a specific job or revert a job to undo changes made during an operation.

### Revert a job

 - [POST /api/v1/jobs/{jobId}/revert](https://api-docs.sitecore.com/sai/agent-api/jobs/jobs-revert_job.md): Reverts the operations linked to a specific job ID, restoring the state prior to execution. This is useful for undoing changes made by automated processes.

### Retrieve job details

 - [GET /api/v1/jobs/{jobId}](https://api-docs.sitecore.com/sai/agent-api/jobs/jobs-get_job.md): Retrieves the details of a specific job.

### List job operations

 - [GET /api/v1/jobs/{jobId}/operations](https://api-docs.sitecore.com/sai/agent-api/jobs/jobs-list_operations.md): Retrieves a list of actions associated with a specific job ID, including operation type, status, and timestamps, to support tracing and potential reversion of those actions.

## Brand kits

The Brand kits API lets you retrieve a list of brand kits and details of a specific brandkit.

### List brand kits

 - [GET /api/v1/brandkits](https://api-docs.sitecore.com/sai/agent-api/brand-kits/brandkits-list_brandkits.md): Retrieves all brand kits available within an organization.

### Retrieve a brand kit by ID

 - [GET /api/v1/brandkits/{brandkitId}](https://api-docs.sitecore.com/sai/agent-api/brand-kits/brandkits-get_brandkit_by_id.md): Retrieves a brand kit by ID, including its sections and associated fields (subsections).

## Briefs

The Briefs API lets you retrieve available brief types, generate briefs based on a brief type and brand kit, and create briefs and save it as a draft.

### List brief types

 - [GET /api/v1/brief/brief-types](https://api-docs.sitecore.com/sai/agent-api/briefs/list-brief_types.md): Retrieves a list of all available brief types, including their metadata and field definitions such as field types, labels, validation rules, and other information used by AI when generating briefs.

### Create a brief

 - [POST /api/v1/brief](https://api-docs.sitecore.com/sai/agent-api/briefs/brief-create_brief.md): Creates a brief using the specified brief type ID, locale, and provided data fields. The new brief is saved as a draft in the Brief management tool.

### Generate a brief

 - [POST /api/v1/briefs/generate](https://api-docs.sitecore.com/sai/agent-api/briefs/briefs-generate_brief.md): Generates a brief and the content of its fields, using the specified brief type, brand kit, and prompt. This endpoint does not save the generated brief. You can copy the response and use the Create a brief endpoint to save it in the Brief management tool.

