1. Make sure you have the latest version of Ruby 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. Add this line to your application’s Gemfile:
gem 'trycourier'
  1. Run $ gem install trycourier and add the following code to the top of your ruby file to install the Courier Ruby SDK:
require "trycourier"
  1. Add the following code and replace <auth_token> with your Courier API key:
client = Courier::Client.new "<auth_token>"
  1. Add the following code to send the message:
res = client.send({
    message => {
        to => {
          "email" => "email@example.com",
        },
        content: => {
          "title" => "Welcome!",
          "body" => "Thanks for signing up, {{name}}",
        },
        data: => { #any data you want to pass to the content or message template
          "name" => "Nuxt.js Enthusiasts",
        },
        routing: => { #any data you want to pass to the content or message template
          "method" => "single",
          "channels" => ["email"],
        },
    },
  })
  puts res.code # the HTTP response code
  puts res.message_id # if the code is 200, this will be the Courier message ID for this notification
rescue Courier::CourierAPIError => re #error sent from from the API
  puts re.message
end
  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

Questions?

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