# Content Types API

Use the SitecoreAI Content Types API to manage content types. A content type is a template that defines the structure of content items. 

 This REST API lets you: 

 - Retrieve content types. 

 - Create content types. 

 - Update content types. 

 - Retrieve the field source configuration for a content model, if one exists. 

# Authorization
To authorize your requests, use environment automation client credentials and generate a JSON Web Token (JWT).

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 the Deploy app.
 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 the Deploy app. You'll use them to request a JWT.

## 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
License: Apache 2.0
Metadata:
  - product: SitecoreAI

## Servers

Staging server
```
https://xmapps-componentsapi-staging.sitecore-staging.cloud
```

Production server
```
https://edge-platform.sitecorecloud.io/authoring
```

## Security

### Bearer

Enter your bearer token in the text input below.

Type: http
Scheme: Bearer

## Download OpenAPI description

[Content Types API](https://api-docs.sitecore.com/_bundle/sai/content-types-api/index.yaml)

## Content Types

The Content Types API lets you manage content types.

### Retrieve a content type

 - [GET /api/v1/content-types/{modelId}](https://api-docs.sitecore.com/sai/content-types-api/content-types/retrievecontentmodel.md): Retrieves details about a content type.

### Update a content type

 - [PATCH /api/v1/content-types/{modelId}](https://api-docs.sitecore.com/sai/content-types-api/content-types/patchcontentmodel.md): Update a content type.

### Update a content type

 - [PUT /api/v1/content-types/{modelId}](https://api-docs.sitecore.com/sai/content-types-api/content-types/updatecontentmodel.md): Updates a whole content type. Existing fields that aren't provided in the request will be removed.

### Delete a content type

 - [DELETE /api/v1/content-types/{modelId}](https://api-docs.sitecore.com/sai/content-types-api/content-types/deletecontentmodel.md): Deletes a content type.

### Get content type field source

 - [GET /api/v1/content-types/{modelId}/{fieldId}/source](https://api-docs.sitecore.com/sai/content-types-api/content-types/retrievefieldsource.md): Retrieves one page of source items for a specified field in a selected content type. Pass the response continuationToken in the x-sc-continuation
header to retrieve the next page. A field source can contain multiple Sitecore query segments, for example
query:$site/[@@name='Data']|query:$sharedSites/[@@name='Data']. Example hand-off header:
x-sc-continuation: eyJzb3VyY2VJbmRleCI6MSwibmV4dEl0ZW0iOjI1fQ==. Each returned item includes
sourceIndex, the zero-based segment from which it originated.

### List content types

 - [GET /api/v1/content-types](https://api-docs.sitecore.com/sai/content-types-api/content-types/retrievecontenttypes.md): Retrieves a paginated list of content types. Optionally filter results using a search query, or retrieve specific content types by supplying one or more id parameters.
The search and id parameters are mutually exclusive. When id is supplied, only the first 50 IDs are processed and pagination is disabled.

### Create a content type

 - [POST /api/v1/content-types](https://api-docs.sitecore.com/sai/content-types-api/content-types/createcontentmodel.md): Creates a content type.

### List validation rules

 - [GET /api/v1/content-types/validation-rules](https://api-docs.sitecore.com/sai/content-types-api/content-types/retrievevalidationrules.md): Fetches the list of available validation rules.

### Get content type field sources

 - [POST /api/v1/content-types/{modelId}/sources](https://api-docs.sitecore.com/sai/content-types-api/content-types/retrievefieldsources.md): Retrieves source items for multiple fields in a specified content type. Returns the source items page and a continuation token for the next field page.
Pass a field response's continuationToken to the single-field GET endpoint 'Get content type field source' to continue that field.
Pass the top-level continuationToken to this endpoint to continue the requested field collection via the x-sc-continuation header.

