Skip to main content

Update

Update a template by ID or alias using the default context.
func (s *TemplatesSvcImpl) Update(identifier string, params *UpdateTemplateRequest) (*UpdateTemplateResponse, error)

Parameters

identifier
string
required
The template ID or alias.
params
*UpdateTemplateRequest
required
The template update parameters.

Returns

Returns an *UpdateTemplateResponse containing the updated template ID.

Example

update := &resend.UpdateTemplateRequest{
  Name:    "Updated Welcome Email",
  Subject: "Welcome {{{name}}}!",
  Html:    "<h1>Hello {{{name}}}</h1><p>Updated content</p>",
  Variables: []*resend.TemplateVariable{
    {
      Key:           "name",
      Type:          resend.VariableTypeString,
      FallbackValue: "there",
    },
  },
}

response, err := client.Templates.Update("template_id_or_alias", update)
if err != nil {
  panic(err)
}

fmt.Println("Updated template:", response.Id)

UpdateWithContext

Update a template by ID or alias with a custom context.
func (s *TemplatesSvcImpl) UpdateWithContext(ctx context.Context, identifier string, params *UpdateTemplateRequest) (*UpdateTemplateResponse, error)

Parameters

ctx
context.Context
required
Context for the request, useful for timeouts and cancellation.
identifier
string
required
The template ID or alias.
params
*UpdateTemplateRequest
required
The template update parameters.

Returns

Returns an *UpdateTemplateResponse containing the updated template ID.

Example

ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second)
defer cancel()

update := &resend.UpdateTemplateRequest{
  Name: "Updated Template Name",
  Html: "<h1>New content</h1>",
}

response, err := client.Templates.UpdateWithContext(ctx, "welcome-email", update)
if err != nil {
  panic(err)
}

Types

UpdateTemplateRequest

Request payload for updating a template.
type UpdateTemplateRequest struct {
  Name      string              `json:"name"`
  Alias     string              `json:"alias,omitempty"`
  From      string              `json:"from,omitempty"`
  Subject   string              `json:"subject,omitempty"`
  ReplyTo   any                 `json:"reply_to,omitempty"` // string or []string
  Html      string              `json:"html"`
  Text      string              `json:"text,omitempty"`
  Variables []*TemplateVariable `json:"variables,omitempty"`
}
Name
string
required
The name of the template.
Alias
string
A unique alias for the template. Can be used instead of the ID to reference the template.
From
string
The sender email address. Can be a plain email or formatted as “Name <[email protected]>”.
Subject
string
The email subject line. Can include template variables like {{{variable_name}}}.
ReplyTo
any
Reply-to email address. Can be a string or array of strings.
Html
string
required
The HTML content of the email template. Use {{{variable_name}}} syntax for variables.Important: All variables referenced in Html must be declared in the Variables array, or the API will return a validation error.
Text
string
Plain text version of the email template.
Variables
[]*TemplateVariable
Array of variable declarations used in the template. All variables referenced in Html or Subject must be declared here.

UpdateTemplateResponse

Response from updating a template.
type UpdateTemplateResponse struct {
  Id     string `json:"id"`
  Object string `json:"object"`
}
Id
string
The unique identifier of the updated template.
Object
string
The object type, always “template”.

Build docs developers (and LLMs) love