Once content has been added to a template, it's not automatically available for use. Until save template action is called, you can create products from the template and they won't contain pages that are still being edited.
Save Template
Use the PUT Save template endpoint to save newly added content to a template.
Sample request
curl -X PUT "https://api.portal.swaggerhub.com/v1/templates/<TEMPLATE-ID>/saved" \
-H "Authorization: Bearer YOUR_SWAGGER_APIKEY" \
-H "Content-Type: application/json"In case of a processing error, the response with validation message is returned providing information of the error type and ID of each template table-of-contents (template TOC) entry that caused the issue.
Sample Response
{
"validationMessages": [
{
"level": "error",
"message": "The product failed to publish due to errors.",
"errorCode": "INVALID_API",
"tableOfContentsId": "f91f8be2-ccbc-483a-93a7-a692763f79a5"
}
]
}Possible validation error code are explained here.
Unsaved changes
To retrieve the changes made to a template since the last save, you can use the GET Get unsaved changes endpoint:
Sample Request
curl -X GET "https://api.portal.swaggerhub.com/v1/templates/<TEMPLATE-ID>/saved/changes" \
-H "Authorization: Bearer YOUR_SWAGGER_APIKEY" \
-H "Content-Type: application/json"Sample Response
{
"added": [
{
"path": "doc/new-feature",
"tableOfContentsId": "12345678-1234-1234-1234-123456789abc",
"title": "New Feature Documentation",
"type": "markdown"
}
],
"modified": [
{
"path": "doc/updated-feature",
"tableOfContentsId": "87654321-4321-4321-4321-cba987654321",
"title": "Updated Feature Documentation",
"type": "html"
}
],
"removed": [],
"missing": [],
"reordered": false
}🚧 Important: If any of you APIs appears as missing, it means it's inaccessible in Swagger Studio and must be unlinked to preview or publish the product. Possible causes:
- API renamed in Swagger Studio
- API deleted from Swagger Studio
- Provider doesn't have correct permissions to the API
- Anything that affects the API URL structure
Preview Template
It's possible to preview how a product created from template will look like. To do that first use the PUT Generate template preview endpoint, then you can check the included content with the GET Get template preview sections and GET Get template preview page endpoints.
Generate Template Preview Request
curl -X PUT "https://api.portal.swaggerhub.com/v1/templates/<TEMPLATE-ID>/preview" \
-H "Authorization: Bearer YOUR_SWAGGER_APIKEY" \
-H "Content-Type: application/json"📌 Note: There is also path parameter
savedof boolean type possible to add to this query, that defaults tofalse. If set totrue, the preview of saved template version is generated.
Generate Template Preview Sample Response
When preview was successfully generated, response contains empty list of validation messages
{
"validationMessages": []
}Get Template Preview Sections Sample Request
curl -X GET "https://api.portal.swaggerhub.com/v1/templates/<TEMPLATE-ID>/preview/sections" \
-H "Authorization: Bearer YOUR_SWAGGER_APIKEY"Sample Response for Get Template Preview Sections
{
"page": {
"number": 1,
"size": 10,
"totalElements": 1,
"totalPages": 1
},
"items": [
{
"title": "Getting Started",
"slug": "getting-started",
"tableOfContents": [
{
"tableOfContentsId": "3fa85f64-5717-4562-b3fc-2c963f66afa6",
"sourceTemplateTocId": "3fa85f64-5717-4562-b3fc-2c963f66afa6",
"type": "markdown",
"title": "Getting Started",
"path": "doc/getting-started",
"children": []
}
]
}
]
}Get Template Preview Page Sample Request
curl -X GET "https://api.portal.swaggerhub.com/v1/templates/<TEMPLATE-ID>/preview/page?path=doc/getting-started" \
-H "Authorization: Bearer YOUR_SWAGGER_APIKEY" \
-H "Content-Type: application/json"📝 Note:
pathparameter value is required. You can copy its value from GET Published section response or combine section's and table-of-contents' slugs
Sample Response for Get Template Preview Page
{
"content": "Getting Started Welcome to the API documentation. This guide will help you get started with our API.",
"last-modified": "2023-10-01T12:00:00Z",
"content-type": "text/html"
}