HTTP API

Upload and manage templates

Get your awesome documents with this simple HTTP API

Upload a template

/template

Endpoint to upload a template.

When a template is uploaded, a template ID is created, representing the unique identifier (sha256) of the file. If you upload the same template twice, you will have the same template ID.

The returned template ID can be used for:

Request header

{
  // Required Your API token (string)
  "authorization"       : "Bearer API_TOKEN",
  // Required Content-type 
  "content-type"        : "multipart/form-data", // or "application/json" (solution 2)
}

Request body

The body request can be either:

{
  "template" : ""  // File content
}

A JSON is returned as body response.
On success, the templateId is returned.

Status Code Body
200 { "success" : true, "data" : { "templateId" : "" } }
400 { "success" : false, "error" : "Cannot store template" }
400 { "success" : false, "error" : "Content-Type header should be multipart/form-data or application/json" }
401 { "success" : false, "error" : "Unauthorized, please provide a correct API key on the "Authorization" header"}
415 { "success" : false, "error" : "Template format not supported" }
422 { "success" : false, "error" : ""template" field is empty" }

Curl Example

Example 1 - Add a template with the absolute file path

curl --location --request POST 'https://api.carbone.io/template' \
--header 'carbone-version: 4' \
--header 'Expect:' \
--header 'Content-Type: multipart/form-data' \
--header 'Authorization: Bearer API_TOKEN' \
--form 'template=@"ABSOLUTE_FILE_PATH"'

Example 2 - Add a template with the file as a base64 String

curl --location --request POST 'https://api.carbone.io/template' \
--header 'carbone-version: 4' \
--header 'Expect:' \
--header 'Content-Type: application/json' \
--header 'Authorization: Bearer API_TOKEN' \
--data-raw '{ "template": "BASE64_STRING" }'

Download a template

/template/{templateId}

Endpoint to download a template from a template ID, a unique identifier for templates.

Request header

{
  // Required Your API token (string)
  "authorization" : "Bearer API_TOKEN"
}

Response body

On success, the file is returned.
On error, a JSON is returned with details of the problem.

Status Code Body
200 File stream
400 { "success" : false, "error" : "Invalid templateId"}
400 { "success" : false, "error" : "Cannot retrieve template"}
401 { "success" : false, "error" : "Unauthorized, please provide a correct API key on the "Authorization" header"}
404 { "success" : false, "error" : "Template not found"}

Curl example

curl --location --request GET 'https://api.carbone.io/template/TEMPLATE_ID' \
--header 'carbone-version: 4' \
--header 'Authorization: Bearer API_TOKEN' \
-o 'FILENAME.docx'

Delete a template

/template/{templateId}

Endpoint to delete a template from a template ID, a unique identifier for templates.

Request header

{
  // Required Your API token (string)
  "authorization" : "Bearer API_TOKEN"
}

Response

A JSON is returned as body response.
On success, a status code 200 is returned.

Status Code Body
200 { "success" : true }
400 { "success" : false, "error" : "Invalid templateId"}
400 { "success" : false, "error" : "Cannot delete template"}
401 { "success" : false, "error" : "Unauthorized, please provide a correct API key on the "Authorization" header"}
404 { "success" : false, "error" : "Template not found"}

Curl example

curl --location --request DELETE 'https://api.carbone.io/template/TEMPLATE_ID' \
--header 'carbone-version: 4' \
--header 'Authorization: Bearer API_TOKEN'