# Manage Template Content

The API allows you to manage the table of contents for a template, including adding new entries and updating existing ones.

Similar as for Portal products, API reference material and documentation are grouped under **sections** named *docs*. When a template is created, a *docs* section is also created and accessible via a [GET Retrieve a specific section](https://developer.smartbear.com/portal/default/swaggerhub-portal-api#/Content%20%3A%3A%20Sections/getSection) request.

## Retrieve Section – Sample Request

```text
curl --location 'https://api.portal.swaggerhub.com/v1/templates/<TEMPLATE-ID>/sections' \
--header 'Authorization: Bearer <YOUR-SWAGGER-APIKEY>'
```

### Sample Response Payload

```text
{
  "items": [
    {
      "id": "02fdcafc-9328-4eb2-8315-a2ce34d9644b",
      "templateId": "afda3749-2314-4153-a53f-ed54ab2387b2",
      "title": "docs",
      "slug": "docs"
    }
  ]
}
```

> 📝 **Note:** Keep note of the returned `id` for the section, as it will be needed in subsequent API calls.

## Adding a new Template Table of Contents Entry (ToC)

To add a new entry to the template's table of contents, use the [POST Add template table of contents entry](https://developer.smartbear.com/portal/default/swaggerhub-portal-api#/Templates%20%3A%3A%20Table%20of%20Contents/createTemplateTableOfContentsEntry) endpoint. Same as it is for Products, Template ToCs with `source` property set to `internal` are editable in UI and via API requests, but if if the value is `external` the UI editor will be disabled The default value is `internal`.

### Sample Request:

```text
curl -X POST "https://api.portal.swaggerhub.com/v1/templates/sections/<SECTION-ID>/table-of-contents" -H "Content-Type: application/json" -H "Authorization: Bearer <YOUR-SWAGGER-APIKEY>" -d '{
	"type": "new",
    "title": "Getting Started",
    "slug": "getting-started",
    "order": 1,
    "content": {
        "type": "markdown",
        "source": "internal"
    }
}'
```

> 📌 **Note:** The `content` type `markdown/html` distinguishes documentation from API references. To reference an API use the `apiUrl` content type and provide its URL as `url` parameter of `content` object.

### Sample Response

```text
{
  "id": "0afe1039-e1a4-4bb3-9d13-a0e7c2a6942c",
  "documentId": "5af87df5-ff80-4423-a0a1-a1db5fb99cb7"
}
```

## Edit title or order of ToC Entry, or API reference 

To update an existing template ToC entry, use the [PATCH Update template table of contents entry](https://developer.smartbear.com/portal/default/swaggerhub-portal-api#/Content%20%3A%3A%20Table%20of%20Contents/patchTableOfContents) endpoint:

### Sample Request

```text
curl -X PATCH "https://api.portal.swaggerhub.com/v1/templates/table-of-contents/<DOCUMENT-ID>" -H "Content-Type: application/json" -H "Authorization: Bearer <YOUR-SWAGGER-APIKEY>" -d '{
    "title": "Updated Getting Started",
    "order": 2,
    "content": {
    	"type": "apiUrl",
    	"url": "https://api.swaggerhub.com/apis/Pets-and-Adoptions-API/1.0.0/swagger.json",
    	"apiSpec": "openapi-2.0"
    }
}'
```

## Add or update ToC Content with Documents Endpoint

To edit the content of a table of contents entry, use the [PATCH Update document](https://developer.smartbear.com/portal/default/swaggerhub-portal-api#/Documents/patchDocument) endpoint. This allows you to update the content of a document associated with a TOC entry.

### Sample Request

```text
curl -X PATCH "https://api.portal.swaggerhub.com/v1/documents/<DOCUMENT-ID>" -H "Content-Type: application/json" -H "Authorization: Bearer <YOUR-SWAGGER-APIKEY>" -d '{
    "content": "# Updated Content\nThis is the new content for the document."
}'
```

In this example, replace `<DOCUMENT-ID>` with the actual document ID you want to update, and provide the new content in the `content` field.

## Restore Deleted Items

Use the [PATCH Patch template table of contents](https://developer.smartbear.com/portal/default/swaggerhub-portal-api#/Templates%20%3A%3A%20Table%20of%20Contents/patchTemplateTableOfContents) endpoint to restore deleted ToC entries and set `status` value to `restored`. To revert content to published state set it to `reverted`.

### Sample Request

```text
curl -X PATCH "https://api.portal.swaggerhub.com/v1/templates/table-of-contents/<TOC-ID>" -H "Content-Type: application/json" -H "Authorization: Bearer <YOUR-SWAGGER-APIKEY>" -d '{
    "status": "restored"
}'
```

> ❗ **Note:** Restoring a template table of contents item does *not* restore its nested child pages.

## Revert content to saved state

Use the [PATCH Patch template table of contents](https://developer.smartbear.com/portal/default/swaggerhub-portal-api#/Templates%20%3A%3A%20Table%20of%20Contents/patchTemplateTableOfContents) endpoint to revert content to last saved state. 

### Sample Request

```text
curl -X PATCH "https://api.portal.swaggerhub.com/v1/templates/table-of-contents/<TOC-ID>" -H "Content-Type: application/json" -H "Authorization: Bearer <YOUR-SWAGGER-APIKEY>" -d '{
    "status": "reverted"
}'
```

> ❗ **Note:** No other property can be updated when the `status` field is set.
