> For the complete documentation index, see [llms.txt](https://synap.ac/docs/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://synap.ac/docs/api/reference/certificates/publish-template.md). Agents can also search and read this documentation through its [MCP server](https://synap.ac/docs/~gitbook/mcp).

# Publish Template

Compiles the draft of a managed template, with the orientation staged in it, and, when it compiles, stores it as the published parts, makes that orientation the one being issued and clears the draft. The requester must be an admin of the main portal and not of a sub-portal. When it does not compile nothing is stored and one error is answered for each problem found. An archived template has to be unarchived first. Legacy templates cannot be published.

```json
{"openapi":"3.0.1","info":{"title":"Synap API","version":"3.0.0"},"tags":[{"name":"Certificates","description":"Endpoints related to Certificates."}],"servers":[{"url":"https://api.synap.ac/v3","description":"Production"},{"url":"https://api-stage.synap.ac/v3","description":"Staging"}],"security":[{"SessionAuth":[]},{"PATAuth":[]},{"AutomationAuth":[]},{"LegacySessionAuth":[]}],"components":{"securitySchemes":{"SessionAuth":{"type":"http","scheme":"bearer","description":"Authorize the request using a Session Token.","bearerFormat":"r:<token>"},"PATAuth":{"type":"http","scheme":"bearer","description":"Authorise the request using a personal access token.","bearerFormat":"p:"},"AutomationAuth":{"type":"http","scheme":"bearer","description":"Authorise the request with a short-lived token signed by the automations engine on behalf of a workflow owner.","bearerFormat":"a:<token>"},"LegacySessionAuth":{"type":"apiKey","description":"[Legacy] Authorize the request using a Session Token.","in":"header","name":"X-Syn-Session-Token"}},"schemas":{"ObjectId":{"type":"string","description":"The primary key for each resource."},"Template":{"type":"object","required":["id","type"],"properties":{"id":{"$ref":"#/components/schemas/ObjectId"},"type":{"type":"string","description":"Identifies the Resource.","enum":["Template"]},"attributes":{"type":"object","additionalProperties":false,"properties":{"name":{"type":"string","description":"Up to 120 characters. It can be changed on a managed template, and not on a legacy one."},"htmlTemplate":{"type":"string","readOnly":true,"description":"The complete document of a legacy template. A managed template does not send it."},"isDefault":{"type":"boolean","readOnly":true,"description":"Whether this is one of the built in templates."},"orientation":{"type":"string","enum":["landscape","portrait"],"readOnly":true,"description":"The orientation certificates are issued in. It is set when a managed template is created, and changed by putting orientation in the draft and publishing the template."},"preview":{"type":"object","readOnly":true,"properties":{"svg":{"type":"string"},"image":{"type":"string"}}},"usage":{"type":"string","enum":["exam","assignment"],"readOnly":true,"description":"What the template is issued for. A template stored without a usage is reported as an exam template. It cannot change once a managed template exists."},"kind":{"type":"string","enum":["legacy","managed"],"readOnly":true,"description":"Managed templates are edited here. Legacy templates are written by Synap and cannot be edited, published or deleted here."},"status":{"type":"string","enum":["draft","published"],"readOnly":true,"description":"Draft until the first publish. Legacy templates are always published."},"hasUnpublishedChanges":{"type":"boolean","readOnly":true,"description":"Whether the draft differs from the published parts or stages a different orientation from the one being issued, or nothing has been published yet."},"shellVersion":{"type":"integer","nullable":true,"readOnly":true,"description":"The version of the Synap-owned shell the published parts were compiled with."},"parts":{"type":"object","required":["body","css"],"additionalProperties":false,"description":"The published parts. Managed templates only.","properties":{"body":{"type":"string","maxLength":200000,"description":"An HTML fragment that may contain Go template actions."},"css":{"type":"string","maxLength":200000,"description":"CSS, scoped to the content box when compiled."},"contentInset":{"type":"integer","minimum":0,"maximum":30,"default":10,"description":"Safe area inside the A4 sheet, in millimetres. Defaults to 10."},"background":{"type":"object","nullable":true,"required":["url","fit"],"additionalProperties":false,"description":"The image that fills the whole page behind the content. It can only be set here, as the style of the template cannot reach it. Null or left out for no background. The url has to be the address of an image uploaded to this template, and publishing or previewing refuses any address of another place.","properties":{"url":{"type":"string","minLength":1,"maxLength":2048,"description":"The url of an image uploaded to this template."},"fit":{"type":"string","enum":["cover","contain","stretch"],"description":"How the image fills the page. Cover scales it until it covers the page and crops what does not fit, contain scales it until all of it fits in the page, and stretch fills the page whatever the proportions of the image."}}}},"nullable":true,"readOnly":true},"draft":{"type":"object","required":["body","css"],"additionalProperties":false,"description":"The parts being edited, with the orientation they will be published with, not yet published. Replaced as a whole when sent. Managed templates only.","properties":{"body":{"type":"string","maxLength":200000,"description":"An HTML fragment that may contain Go template actions."},"css":{"type":"string","maxLength":200000,"description":"CSS, scoped to the content box when compiled."},"contentInset":{"type":"integer","minimum":0,"maximum":30,"default":10,"description":"Safe area inside the A4 sheet, in millimetres. Defaults to 10."},"background":{"type":"object","nullable":true,"required":["url","fit"],"additionalProperties":false,"description":"The image that fills the whole page behind the content. It can only be set here, as the style of the template cannot reach it. Null or left out for no background. The url has to be the address of an image uploaded to this template, and publishing or previewing refuses any address of another place.","properties":{"url":{"type":"string","minLength":1,"maxLength":2048,"description":"The url of an image uploaded to this template."},"fit":{"type":"string","enum":["cover","contain","stretch"],"description":"How the image fills the page. Cover scales it until it covers the page and crops what does not fit, contain scales it until all of it fits in the page, and stretch fills the page whatever the proportions of the image."}}},"orientation":{"type":"string","enum":["landscape","portrait"],"description":"The orientation the template is issued in once this draft is published. When a request leaves it out, the orientation already staged in the draft is kept, or the orientation being issued when nothing is staged."}},"nullable":true},"isArchived":{"type":"boolean","readOnly":false,"description":"Whether the template has been archived. Archived templates are listed only when asked for, cannot be chosen for new settings and cannot be edited until they are unarchived. Send true to archive a published template and false to unarchive it, on its own, as an admin of the main portal. Sending the value it already has changes nothing. Legacy templates are never archived."},"availableToSubPortals":{"type":"boolean","nullable":true,"description":"Whether sub-portals may use this template. Only a template that is not limited to a sub-portal has it: true unless it was set to false, and false means only the main portal may choose it for its exams and assignments, and the people of a sub-portal neither see it listed nor find it. Null for a template limited to a sub-portal and for a legacy template. It can be changed whenever the template is not archived, and only affects what is chosen from then on."},"createdAt":{"type":"string","format":"date-time","readOnly":true},"updatedAt":{"type":"string","format":"date-time","readOnly":true}}},"relationships":{"type":"object","properties":{"subPortal":{"type":"object","description":"The sub-portal this template is limited to, which must belong to the portal of the requester. Empty for a template of the whole portal. It can only be set when the template is created. Only the people of that sub-portal and of the main portal see a template limited to a sub-portal.","readOnly":true,"properties":{"data":{"type":"object","required":["id","type"],"nullable":true,"properties":{"id":{"$ref":"#/components/schemas/ObjectId"},"type":{"type":"string","description":"Identifies the Resource.","enum":["SubPortal"]}}}}},"owner":{"type":"object","description":"This is a resource linkage for a to-one relationship. It is like a Parse Pointer.","readOnly":true,"properties":{"data":{"type":"object","required":["id","type"],"nullable":true,"properties":{"id":{"$ref":"#/components/schemas/ObjectId"},"type":{"type":"string","description":"Identifies the Resource.","enum":["User"]}}}}}}}}},"UnauthorizedApiError":{"type":"object","description":"Unauthorized request.","properties":{"id":{"type":"string","description":"Unique ID of this error occurrence."},"status":{"type":"string","description":"HTTP status code."},"code":{"type":"string","description":"Synap internal error code."},"title":{"type":"string"},"detail":{"type":"string"},"source":{"type":"object","properties":{"pointer":{"type":"string"},"parameter":{"type":"string"}}}}},"ForbiddenApiError":{"type":"object","description":"Forbidden request.","properties":{"id":{"type":"string","description":"Unique ID of this error occurrence."},"status":{"type":"string","description":"HTTP status code."},"code":{"type":"string","description":"Synap internal error code."},"title":{"type":"string"},"detail":{"type":"string"},"source":{"type":"object","properties":{"pointer":{"type":"string"},"parameter":{"type":"string"}}}}},"NotFoundApiError":{"type":"object","description":"The request resource could not be found.","properties":{"id":{"type":"string","description":"Unique ID of this error occurrence."},"status":{"type":"string","description":"HTTP status code."},"code":{"type":"string","description":"Synap internal error code."},"title":{"type":"string"},"detail":{"type":"string"},"source":{"type":"object","properties":{"pointer":{"type":"string"},"parameter":{"type":"string"}}}}},"ApiError":{"type":"object","description":"This is an error response structure. The id, status, code, title and detail will vary based on the error situation.","properties":{"id":{"type":"string","description":"Unique ID of this error occurrence."},"status":{"type":"string","description":"HTTP status code."},"code":{"type":"string","description":"Synap internal error code."},"title":{"type":"string"},"detail":{"type":"string"},"source":{"type":"object","properties":{"pointer":{"type":"string"},"parameter":{"type":"string"}}}}}}},"paths":{"/templates/{object_id}/publish":{"post":{"summary":"Publish Template","description":"Compiles the draft of a managed template, with the orientation staged in it, and, when it compiles, stores it as the published parts, makes that orientation the one being issued and clears the draft. The requester must be an admin of the main portal and not of a sub-portal. When it does not compile nothing is stored and one error is answered for each problem found. An archived template has to be unarchived first. Legacy templates cannot be published.","tags":["Certificates"],"parameters":[{"name":"object_id","in":"path","required":true,"schema":{"$ref":"#/components/schemas/ObjectId"}}],"responses":{"200":{"description":"Published","content":{"application/vnd.api+json":{"schema":{"type":"object","required":["data"],"properties":{"data":{"$ref":"#/components/schemas/Template"}}}}}},"400":{"description":"Bad Request. When the draft did not compile, nothing was stored and one error is answered for each problem found, with the rule it broke and where it is in the draft.","content":{"application/vnd.api+json":{"schema":{"type":"object","properties":{"errors":{"type":"array","description":"One error for each problem the compiler found, in the order it found them. The code of each is certificate-template-invalid-draft, and meta.rule says which rule of the compiler it broke.","items":{"type":"object","properties":{"id":{"type":"string","description":"Unique ID of this error occurrence."},"status":{"type":"string","description":"HTTP status code."},"code":{"type":"string","description":"Synap internal error code."},"title":{"type":"string"},"detail":{"type":"string"},"source":{"type":"object","properties":{"pointer":{"type":"string"},"parameter":{"type":"string"}}},"meta":{"type":"object","properties":{"rule":{"type":"string","description":"A stable, machine readable code of the compiler such as template.parse_error."},"pane":{"type":"string","description":"Where the problem is: html (the body), css, settings, or background (the page background)."},"line":{"type":"integer","description":"Starting at 1, within the source of that pane. 0 for settings. Left out for the background."},"column":{"type":"integer","description":"Starting at 1, within the source of that pane. 0 for settings. Left out for the background."}}}}}}}}}}},"401":{"description":"Unauthorized","content":{"application/vnd.api+json":{"schema":{"type":"object","properties":{"errors":{"type":"array","items":{"$ref":"#/components/schemas/UnauthorizedApiError"}}}}}}},"403":{"description":"Forbidden: the requester is not an admin of the main portal, the template is a legacy template, it is archived, or there is no draft to publish.","content":{"application/vnd.api+json":{"schema":{"type":"object","properties":{"errors":{"type":"array","items":{"$ref":"#/components/schemas/ForbiddenApiError"}}}}}}},"404":{"description":"Not Found","content":{"application/vnd.api+json":{"schema":{"type":"object","properties":{"errors":{"type":"array","items":{"$ref":"#/components/schemas/NotFoundApiError"}}}}}}},"409":{"description":"The template was changed while it was being published, so nothing was stored.","content":{"application/vnd.api+json":{"schema":{"type":"object","properties":{"errors":{"type":"array","items":{"$ref":"#/components/schemas/ApiError"}}}}}}}},"operationId":"templates.publishTemplate"}}}}
```


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation by asking a question.

Perform an HTTP GET request on the following URL with the `ask` and `goal` query parameters:

```
GET https://synap.ac/docs/api/reference/certificates/publish-template.md?ask=<question>&goal=<user_goal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is what the user is ultimately trying to achieve, the reason they need the answer. Sharing it helps GitBook give you a better, more relevant answer. A goal is most helpful when it describes the outcome the user wants rather than restating the question. For example, with `ask=how do I create an API token`, a goal like `automate deployments from our CI pipeline` lets GitBook tailor the answer to that use case.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
