Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions examples/templates.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@
# Get a template by ID
retrieved_template: resend.Template = resend.Templates.get(template["id"])
print(f"Retrieved template: {retrieved_template['name']}")
print(f"Has unpublished versions: {retrieved_template['has_unpublished_versions']}")

# Update a template (update just the name, keep HTML/variables the same)
update_params: resend.Templates.UpdateParams = {
Expand Down
6 changes: 6 additions & 0 deletions resend/templates/_template.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,8 @@ class Template(_FromParam):
created_at (str): The timestamp when the template was created.
updated_at (str): The timestamp when the template was last updated.
published_at (str): The timestamp when the template was published.
current_version_id (str): The ID of the current version of the template.
has_unpublished_versions (bool): Whether the template has unpublished versions.
"""

id: str
Expand Down Expand Up @@ -93,6 +95,10 @@ class Template(_FromParam):

published_at: NotRequired[str]
"""The timestamp when the template was published."""
current_version_id: NotRequired[str]
"""The ID of the current version of the template."""
has_unpublished_versions: NotRequired[bool]
"""Whether the template has unpublished versions."""


class TemplateListItem(TypedDict):
Expand Down
2 changes: 1 addition & 1 deletion resend/version.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
__version__ = "2.54.0"
__version__ = "2.54.1"


def get_version() -> str:
Expand Down
40 changes: 40 additions & 0 deletions tests/templates_async_test.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import pytest
from typing_extensions import assert_type

import resend
from resend.exceptions import NoContentError
Expand Down Expand Up @@ -217,3 +218,42 @@ async def test_should_list_templates_async_raise_exception_when_no_content(
self.set_mock_json(None)
with pytest.raises(NoContentError):
_ = await resend.Templates.list_async()

async def test_templates_get_async_returns_version_fields(self) -> None:
self.set_mock_json(
{
"object": "template",
"id": "34a080c9-b17d-4187-ad80-5af20266e535",
"current_version_id": "b2693018-7abb-4b4b-b4cb-aadf72dc06bd",
"alias": "reset-password",
"name": "reset-password",
"created_at": "2026-10-06 23:47:56.678+00",
"updated_at": "2026-10-06 23:47:56.678+00",
"status": "published",
"published_at": "2026-10-06 23:47:56.678+00",
"from": "John Doe <john.doe@example.com>",
"subject": "Hello, world!",
"reply_to": None,
"html": "<h1>Hello, world!</h1>",
"text": "Hello, world!",
"variables": [
{
"id": "e169aa45-1ecf-4183-9955-b1499d5701d3",
"key": "user_name",
"type": "string",
"fallback_value": "John Doe",
"created_at": "2026-10-06 23:47:56.678+00",
"updated_at": "2026-10-06 23:47:56.678+00",
}
],
"has_unpublished_versions": True,
}
)

template = await resend.Templates.get_async(
"34a080c9-b17d-4187-ad80-5af20266e535"
)
assert_type(template["current_version_id"], str)
assert_type(template["has_unpublished_versions"], bool)
assert template["current_version_id"] == "b2693018-7abb-4b4b-b4cb-aadf72dc06bd"
assert template["has_unpublished_versions"] is True
39 changes: 39 additions & 0 deletions tests/templates_test.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
from typing_extensions import assert_type

import resend
from tests.conftest import ResendBaseTest

Expand Down Expand Up @@ -305,3 +307,40 @@ def test_templates_variable_types(self) -> None:
template: resend.Templates.CreateResponse = resend.Templates.create(params)
assert template["id"] == "49a3999c-0ce1-4ea6-ab68-afcd6dc2e794"
assert template["object"] == "template"

def test_templates_get_returns_version_fields(self) -> None:
self.set_mock_json(
{
"object": "template",
"id": "34a080c9-b17d-4187-ad80-5af20266e535",
"current_version_id": "b2693018-7abb-4b4b-b4cb-aadf72dc06bd",
"alias": "reset-password",
"name": "reset-password",
"created_at": "2026-10-06 23:47:56.678+00",
"updated_at": "2026-10-06 23:47:56.678+00",
"status": "published",
"published_at": "2026-10-06 23:47:56.678+00",
"from": "John Doe <john.doe@example.com>",
"subject": "Hello, world!",
"reply_to": None,
"html": "<h1>Hello, world!</h1>",
"text": "Hello, world!",
"variables": [
{
"id": "e169aa45-1ecf-4183-9955-b1499d5701d3",
"key": "user_name",
"type": "string",
"fallback_value": "John Doe",
"created_at": "2026-10-06 23:47:56.678+00",
"updated_at": "2026-10-06 23:47:56.678+00",
}
],
"has_unpublished_versions": True,
}
)

template = resend.Templates.get("34a080c9-b17d-4187-ad80-5af20266e535")
assert_type(template["current_version_id"], str)
assert_type(template["has_unpublished_versions"], bool)
assert template["current_version_id"] == "b2693018-7abb-4b4b-b4cb-aadf72dc06bd"
assert template["has_unpublished_versions"] is True
Loading