Skip to content

Add templates_api for the paginated /api/templates endpoints - #86

Draft
izikaj wants to merge 2 commits into
mainfrom
templates-api
Draft

izikaj wants to merge 2 commits into
mainfrom
templates-api

Conversation

@izikaj

@izikaj izikaj commented Oct 5, 2026

Copy link
Copy Markdown

Motivation

Mailtrap now serves a conventions-compliant templates API at /api/templates (and /api/accounts/{account_id}/templates): every response is wrapped in a data envelope, the list is paginated with token / per_page, and write bodies are flat. The existing /api/email_templates surface keeps its published shape and stays live, but it is scheduled for removal once the new one leaves experimental status.

This adds the new surface as a sibling resource rather than widening the existing one, because widening would change every return type for current callers. The old methods are deprecated and point at the replacement.

Changes

  • Add client.templates_api.templates (AccountTemplatesApi) for /api/accounts/{id}/templates: get_list(TemplateListParams(per_page, token)) returns TemplateListResponse (data + pagination), get/create/update return Template, delete returns DeletedObject; bodies are flat
    • Pagination is reused from mailtrap.models.common
  • client.email_templates_api.templates now emits a DeprecationWarning pointing at templates_api; behaviour unchanged
  • Add examples/account_templates/templates.py and README rows

How to test

You'll need an account API token and the account id.

  • List — client.templates_api.templates.get_list(mt.TemplateListParams(per_page=1)) returns one item in .data and .pagination.next_token when more exist; get_list(mt.TemplateListParams(token=2)) returns the next page
  • Create / get / update / delete — create(mt.CreateTemplateParams(name=, subject=, category=, body_html=)) returns a Template with an id; get_by_id, update(id, mt.UpdateTemplateParams(subject=...)) and delete follow; get_by_id after delete raises APIError
  • Empty update — mt.UpdateTemplateParams() raises ValueError
  • Old surface — client.email_templates_api.templates warns once and still returns a bare list

- New `client.templates_api.templates` targets /api/accounts/{id}/templates; list returns the `{data, pagination}` object, single-template calls return the unwrapped `Template`.
- Internal names use `account_templates` because `TemplatesApi` and `EmailTemplatesApi` already belong to the /api/email_templates resource.
- Request bodies are flat (no `email_template` wrap key) and update uses PATCH with the same "at least one field" check as before.
- `client.email_templates_api.templates` now emits a DeprecationWarning pointing at `templates_api`; its behavior is unchanged.
@izikaj izikaj self-assigned this Oct 5, 2026
@coderabbitai

coderabbitai Bot commented Oct 5, 2026

Copy link
Copy Markdown

Important

Draft PR not reviewed

Draft PRs are not automatically reviewed by default.

  • Trigger a manual review

To automatically review draft PRs, update your CodeRabbit configuration:

reviews:
  auto_review:
    drafts: true
  • Autopilot · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant