Skip to main content

Methods

Create

func (s *ContactsSvcImpl) Create(params *CreateContactRequest) (CreateContactResponse, error)
Creates a new contact.

CreateWithContext

func (s *ContactsSvcImpl) CreateWithContext(ctx context.Context, params *CreateContactRequest) (CreateContactResponse, error)
Creates a new contact with context support.

Request Parameters

CreateContactRequest

email
string
required
The email address of the contact
audience_id
string
Deprecated: The audience ID to add the contact to. Omit this field to create a global contact. Use the Segments API for contact organization instead.
unsubscribed
bool
Whether the contact is unsubscribed from emails. Defaults to false.
first_name
string
The contact’s first name
last_name
string
The contact’s last name
properties
map[string]any
Custom key-value pairs for global contacts (when audience_id is omitted).Important: Currently, the Resend API only accepts string values for properties. Non-string values (numbers, booleans, etc.) will be rejected by the API with a validation error.Example: map[string]any{"tier": "premium", "age": "30", "active": "true"}

Response

CreateContactResponse

object
string
Object type (“contact”)
id
string
The unique identifier for the created contact

Examples

Create Global Contact

package main

import (
    "fmt"
    "github.com/resend/resend-go/v2"
)

func main() {
    client := resend.NewClient("re_123456789")

    params := &resend.CreateContactRequest{
        Email:     "[email protected]",
        FirstName: "John",
        LastName:  "Doe",
    }

    contact, err := client.Contacts.Create(params)
    if err != nil {
        panic(err)
    }

    fmt.Println("Contact created:", contact.Id)
}

Create Contact with Properties

params := &resend.CreateContactRequest{
    Email:     "[email protected]",
    FirstName: "Jane",
    LastName:  "Smith",
    Properties: map[string]any{
        "tier":     "premium",
        "industry": "technology",
        "company":  "Acme Inc",
    },
}

contact, err := client.Contacts.Create(params)

Create Audience Contact (Deprecated)

params := &resend.CreateContactRequest{
    Email:      "[email protected]",
    AudienceId: "aud_123456",
    FirstName:  "John",
    LastName:   "Doe",
}

contact, err := client.Contacts.Create(params)

With Context

ctx := context.Background()

params := &resend.CreateContactRequest{
    Email:        "[email protected]",
    FirstName:    "Alice",
    LastName:     "Johnson",
    Unsubscribed: false,
}

contact, err := client.Contacts.CreateWithContext(ctx, params)
if err != nil {
    panic(err)
}

Notes

  • Global contacts (without audience_id) support custom properties
  • Audience-specific contacts (with audience_id) do not support custom properties
  • The audience_id field is deprecated; use the Segments API for organizing contacts

Build docs developers (and LLMs) love