Skip to content

Latest commit

 

History

History
61 lines (48 loc) · 1.64 KB

File metadata and controls

61 lines (48 loc) · 1.64 KB

Courier Go SDK

The Courier Go SDK provides typed access to the Courier REST API from applications written in Go. It uses strongly typed request structs, automatic retries, and returns parsed response types.

Installation

import (
	"github.com/trycourier/courier-go/v4" // imported as courier
)

Requires Go 1.22+.

Quick Start

package main

import (
	"context"
	"fmt"

	"github.com/trycourier/courier-go/v4"
	"github.com/trycourier/courier-go/v4/option"
	"github.com/trycourier/courier-go/v4/shared"
)

func main() {
	client := courier.NewClient(
		option.WithAPIKey("My API Key"), // defaults to os.LookupEnv("COURIER_API_KEY")
	)
	response, err := client.Send.Message(context.TODO(), courier.SendMessageParams{
		Message: courier.SendMessageParamsMessage{
			To: courier.SendMessageParamsMessageToUnion{
				OfUserRecipient: &shared.UserRecipientParam{
					UserID: courier.String("your_user_id"),
				},
			},
			Template: courier.String("your_template_id"),
			Data: map[string]any{"foo": "bar"},
		},
	})
	if err != nil {
		panic(err.Error())
	}
	fmt.Printf("%+v\n", response.RequestID)
}

The client reads COURIER_API_KEY from your environment automatically.

Documentation

Full documentation: courier.com/docs/sdk-libraries/go