Loading...
Skip to main content

Go Quick Start

  1. Make sure you have the latest version of Go installed.
  2. Sign up for Courier to get access to your API key.
  3. Add the channel(s) you wish to send your message to.
  4. Run npm install @trycourier/courier to install the Courier Go SDK.
  5. Add the following code to initialize your SDK:
import (
"context"
"log"

"github.com/trycourier/courier-go/v2"
)
  1. Add the following code and replace <auth_token> with your Courier API key:
func send() {

client := courier.CreateClient("<auth_token>", nil)

requestID, err := client.SendMessage(
context.Background(),
courier.SendMessageRequestBody{
Message: map[string]interface{}{
"to": map[string]string{
"email": "email@example.com",
},
"content": map[string]string{
"title": "Welcome!",
"body": "Thanks for signing up, {{name}}",
},
"data": map[string]string{
"name": "Peter Parker",
},
"routing": map[string]string{
"method": "single",
"channels": ["email"],
},
},
},
)

if err != nil {
log.Fatalln(err)
}
log.Println(requestID)
}
  1. Replace the JSON within the body to match the type and content of notification you want to send. There are 4 main properties within this example notification:

    • to: provide information used by Courier to identify the recipient of the notification. Here you can include details such as the recipient’s email address for email, phone number for SMS.
    • content: add your notification’s title and body.
    • data: include any data you want to pass to a message template. The data will populate the corresponding template variables.
    • routing: customize which channel(s) Courier will potentially deliver the message. If no routing key is specified, Courier will use the default routing configured in the Courier Studio UI.

    Explore how to customize your notification with more properties >

  2. Run your code. Upon running this API call, only a requestId will be returned.

    { "requestId": "87e7c05b-4f46-fda24e356e23" }
  3. Monitor the status of your notification (once sent) in the logs: https://app.courier.com/logs

FAQs

  1. How to add a channel?

    How to: Integrate a New Notification Channel - SMS, Email, Chat, or Push

  2. What's the difference between production and test API keys?

    Every Courier tenant has two notification development environments: “Live” and “Test”. The two environments are isolated from one another, and all the assets within them (templates, brands, tags, subscription topics, integrations, API keys, log data, etc.) belong only to that environment.

    Any changes made to a template and its associated assets are only applied within the current environment until you migrate the template and overwrite any changes to the corresponding Notification ID and assets in the other environment.

  3. How can I send to multiple users or contacts?

    You will need to create a list of users in Courier and

  4. How can I access user profiles from Courier?

    If you have your users saved in Courier's user database https://app.courier.com/users, you can replace the JSON "email" field in the "to" object with:

    • individual profiles with "user_id": "ADD_USER_ID"
    • list of multiple users: "list_id": "ADD_LIST_ID"

Questions?

Join our developer community on Discord and ask questions in the #ask-support channel.