create_template()
Create a new template on the Listmonk instance.
Usage
create_template(
name=None,
body=None,
type=None,
is_default=None,
subject=None,
timeout_config=None
)The body must contain the placeholder {{ template “content” . }} exactly where the rendered content should be injected; a template is rejected without it.
Parameters
name: Optional[str] = None-
The template name. Required; a ValueError is raised if empty.
body: Optional[str] = None-
The template body markup. Required, and must contain the {{ template “content” . }} placeholder.
type: Optional[str] = None-
The template type, e.g. ‘campaign’ or ‘tx’ (transactional).
is_default: Optional[bool] = None-
Whether the new template should become the default for its type.
subject: Optional[str] = None-
The default subject line for the template, if any.
timeout_config: Optional[httpx.Timeout] = None- Optional per-request timeout; defaults to 10 seconds.
Returns
Optional[models.Template]- A models.Template representing the newly created template.
Raises
ValueError-
If name is empty, if body is empty, or if body does not contain the {{ template “content” . }} placeholder.
OperationNotAllowedError-
If the base URL has not been set or you have not logged in.
httpx.HTTPStatusError-
If the server responds with a 4xx or 5xx status.
ValidationError- If the response is empty or is not valid JSON.
Examples
>>> import listmonk
>>> body = 'Header {{ template "content" . }} Footer'
>>> tmpl = listmonk.create_template(name='Welcome', body=body, type='tx')
>>> tmpl.id
7