Skip to main content
Retrieves a paginated list of all segments.

Methods

List

List() (ListSegmentsResponse, error)
Lists all segments using the default background context.

ListWithContext

ListWithContext(ctx context.Context) (ListSegmentsResponse, error)
Lists all segments with a custom context for cancellation and timeout control.

ListWithOptions

ListWithOptions(ctx context.Context, options *ListOptions) (ListSegmentsResponse, error)
Lists segments with pagination options.

Query Parameters

When using ListWithOptions, you can pass a ListOptions struct with the following fields:
limit
number
The maximum number of segments to return per page.
offset
number
The number of segments to skip before starting to return results.

Response

object
string
The object type, always list.
data
Segment[]
An array of segment objects.
has_more
boolean
Indicates whether there are more segments available beyond the current page.

Example

package main

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

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

    segments, err := client.Segments.List()
    if err != nil {
        panic(err)
    }

    fmt.Println("Total segments:", len(segments.Data))
    for _, segment := range segments.Data {
        fmt.Printf("%s: %s\n", segment.Id, segment.Name)
    }
}

Example with pagination

package main

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

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

    options := &resend.ListOptions{
        Limit:  10,
        Offset: 0,
    }

    segments, err := client.Segments.ListWithOptions(context.Background(), options)
    if err != nil {
        panic(err)
    }

    fmt.Println("Has more:", segments.HasMore)
}

Build docs developers (and LLMs) love