Quickstart
We designed our API to be as straightforward as possible.
To use the api you need an API token, you can find your API secret token on your
dashboard, once you are logged in to the app.mindthedoc.com.
The token is necessary to authenticate yourself through each HTTP request.
Your API secret token should be passed as an HTTP header named Authorization and be prefixed with Token.
Authorization: Token YOUR_API_SECRET_TOKEN
Test the API
The base URL for the API is: https://api.mindthedoc.com/v0.
GET https://api.mindthedoc.com/v0/users/me
Authorization: Token YOUR_API_SECRET_TOKEN
Using the curl command the request would look like this:
curl "https://api.mindthedoc.com/v0/users/me" \
-H "Authorization: Token YOUR_API_SECRET_KEY"
You should obtain a response similar to this one:
{
"id": "0185b4d4-42f4-5b17-6b52-3b3da5c6b1b2",
"first_name": "Max",
"last_name": "Mustermann",
"email": "max.mustermann@email.com"
}
A simple example
To generate documents we first need a template, so let's create one.
Templates are HTML files, they can be one HTML file or a ZIP file that contains an HTML file.
Here goes a script in Python creating a template from an HTML file and using it to generate a new document.
We are using requests for the HTTP
requests and requests_toolbelt to create
a multipart encoder to easily POST data along with a file in the same payload.
import io
import requests
from requests_toolbelt.multipart.encoder import MultipartEncoder
# The API token from the website
api_token = "123456"
base_url = "https://api.mindthedoc.com/v0"
# Our HTML template
html_template = """
<!DOCTYPE html>
<html>
<head>
<title>Example</title>
</head>
<body>
<h1>{{message}}</h1>
</body>
</html>
"""
file_content = io.StringIO(html_template)
session = requests.Session()
session.headers["Authorization"] = f"Token {API_TOKEN}"
templates_url = f"{base_url}/templates"
payload = MultipartEncoder(
fields={
'name': "hello_world",
'type': 'HTML',
'file': ('hello_world.html', file_content, 'text/html')
}
)
response = session.post(
templates_url,
data=payload,
headers={'Content-Type': payload.content_type},
)
response_data = response.json()
template_id = response_data["id"]
As you can see the endpoint requires 3 parameters for the template: the name,
the type (which can be ZIP or HTML), and the file.
An HTTP status code 201 is returned if the request is successful.
In the response, the template_id contains the identifier for the template.
This template_id will be useful to create a document, as shown in the next step.
documents_url = f"{base_url}/documents"
response = session.post(
documents_url,
json={
"template": template_id,
"data": {
'message': 'Hello World!',
},
},
headers={'Content-Type': "application/json"},
)
result_data = response.json()
file_url = result_data["file_url"]
Note that a POST to the /documents endpoint needs 2 fields: template which indicates
which template you want to render, and data which contains all the parameters values
to interpolate the template correctly.
A successful result will return a 201 status code. The response contains the file_url
which is an URL that can be used to download the generated document.
You could use the URL to write the file locally...
pdf_document = Path("document.pdf")
response = requests.get(file_url)
pdf_document.write_bytes(response.content)