Skip to content

trycourier/courier-go

master
Switch branches/tags

Name already in use

A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
Code

Latest commit

 

Git stats

Files

Permalink
Failed to load latest commit information.
Type
Name
Latest commit message
Commit time
 
 
v2
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Courier Go SDK

This Go package helps you send notifications through Courier, the smartest way to design & deliver notifications. Design your notifications once using our drag & drop editor, then deliver to any channel through one API. Email, mobile push, SMS, Slack — you name it!

"Golang Gopher"

APIs supported:

  • Audiences API
  • Audit Events API
  • Automations API
  • Brand API
  • Messages API
  • Profiles API
  • Send API
  • List API

Official Courier API docs

For a full description of request and response payloads and properties, please see the official Courier API docs.

Installation

Download the package using go get:

go get -u github.com/trycourier/courier-go/v2

Usage

package main

import (
	"context"
	"fmt"

	"github.com/trycourier/courier-go/v2"
)

func main() {
	client := courier.CourierClient("<YOUR_AUTH_TOKEN>", nil)
	message := courier.SendMessageRequestBody{
		"template": "<COURIER_TEMPLATE>",
			"to": map[string]string{
				"email": "test@email.com"
		}
	}

	reqID, err := client.SendMessage(context.Background(), message)
	if err != nil {
		panic(err)
	}

	fmt.Println(reqID)
}

If you would like to send an idempotent message then be sure to use the SendMessageWithOptions method as shown below:

package main

import (
	"fmt"
	"time"
	"context"

	"github.com/trycourier/courier-go/v2"
)

func main() {
	client := courier.CourierClient("<YOUR_AUTH_TOKEN>", nil)
	message := map[string]interface{}{
		"template": "<COURIER_TEMPLATE>",
			"to": map[string]string{
				"email": "test@email.com"
			}
	}

	reqID, err := client.SendMessageWithOptions(
		context.Background(),
		message,
		courier.WithIdempotencyKey("fake-key"),
		courier.WithIdempotencyKeyExpiration(time.Now().Add(time.Hour * 30))
	)
	if err != nil {
		panic(err)
	}

	fmt.Println(reqID)
}

If you need to use a base url other than the default https://api.courier.com, you can pass it in as the second paramter to the CourierClient:

client := courier.CourierClient("<AUTH_TOKEN>", "<BASE_URL>")

APIs

For a full description of request and response payloads and properties, please see the official Courier API docs.

Send API

  • SendMessage(ctx context.Context, body SendMessageRequestBody) (string, error) [?]
  • Send(ctx context.Context, eventID, recipientID string, body interface{}) (string, error): object [?]
  • SendMessageWithOptions(ctx context.Context, body map[string]interface{}, method string, opts ...Option) (string, error) [?]

Messages API

  • GetMessage(ctx context.Context, messageID string) (*MessageResponse, error) [?]

Audiences API

  • PutAudience(ctx context.Context, audienceId string, audience Audience) (*AudienceResponse, error) [?]
  • GetAudience(ctx context.Context, audienceId string) (*AudienceResponseBody, error) [?]
  • GetAudienceMembers(ctx context.Context, audienceId string, cursor string) (*GetAudienceMembersResponse, error) [?]
  • GetAudiences(ctx context.Context, cursor string) (*GetAudiencesResponse, error) [?]
  • DeleteAudience(ctx context.Context, audienceId string) error [?]

Brand API

  • GetBrands(ctx context.Context, cursor string) (*BrandsResponse, error) [?]
  • GetBrand(ctx context.Context, brandID string) (*BrandResponse, error) [?]
  • PostBrand(ctx context.Context, body PostBrandBody) (*BrandResponse, error) [?]
  • PutBrand(ctx context.Context, brandID string, body PutBrandBody) (*BrandResponse, error) [?]
  • DeleteBrand(ctx context.Context, brandID string) error [?]

Profiles API

  • GetProfile(ctx context.Context, id string) (map[string]json.RawMessage, error): object [?]
  • MergeProfileBytes(ctx context.Context, id string, profile []byte) error [?]
  • UpdateProfileBytes(ctx context.Context, id string, profile []byte) error [?]

Lists API

  • GetLists(ctx context.Context, cursor string, pattern string) (*ListsResponse, error) [?]
  • GetList(ctx context.Context, listID string) (*ListResponse, error) [?]
  • PutList(ctx context.Context, listID string, body interface{}) error [?]
  • DeleteList(ctx context.Context, listID string) error [?]
  • RestoreList(ctx context.Context, listID string) error [?]
  • GetListSubscriptions(ctx context.Context, listID string, cursor string) (*ListSubscriptionsResponse, error) [?]
  • PutListSubscriptions(ctx context.Context, listID string, body interface{}) error [?]
  • PostListSubscriptions(ctx context.Context, listID string, body interface{}) error [?]
  • ListSubscribe(ctx context.Context, listID string, recipientID string, body interface{}) error [?]
  • ListUnsubscribe(ctx context.Context, listID string, recipientID string) error [?]

Automations API

  • InvokeAutomation(ctx context.Context, body interface{}) (string, error)[?]
  • InvokeAutomationTemplate(ctx context.Context, templateId string, body interface{}) (string, error) [?]

Audit Events API

  • GetAuditEvent(ctx context.Context, auditEventID string) (*AuditEvent, error) [?]
  • ListAuditEvents(ctx context.Context, cursor string) (*ListAuditEventsResponse, error) [?]

Staying Updated

To update this SDK to the latest version, use go get -u github.com/trycourier/courier-go.

License

The package is available as open source under the terms of the MIT License. MIT License

About

A Go package for communicating with the Courier REST API.

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages