Token Authâ
Courier assigns you an âAuth Tokenâ when you Register your account. You can retrieve this token from any of your Notification detail pages.
This token should be passed as a Bearer Token
in an Authorization
header with each request. Remember, it is best not to store an authorization token in your source control but instead reference values stored in environment variables or some other configuration. However you handle your tokens, be sure to keep them private and secure.
curl --request POST \
--url https://api.courier.com/send \
--header 'Authorization: Bearer <token>'
curl --request POST \
--url https://api.courier.com/send \
--header 'Authorization: Bearer <token>'
require 'uri'
require 'net/http'
require 'openssl'
url = URI("https://api.courier.com/send")
http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true
http.verify_mode = OpenSSL::SSL::VERIFY_NONE
request = Net::HTTP::Post.new(url)
request["Authorization"] = 'Bearer <token>'
import requests
url = "https://api.courier.com/send"
headers = {
'Authorization': "Bearer <token>"
}
const xhr = new XMLHttpRequest();
xhr.addEventListener("readystatechange", function () {
if (this.readyState === this.DONE) {
console.log(this.responseText);
}
});
xhr.open("POST", "https://api.courier.com/send");
xhr.setRequestHeader("Authorization", "Bearer <token>");
xhr.send(data);
Basic Auth
Basic Auth works by passing a username and password in an Authorization
header. These credentials should be Base64 encoded, which can typically be accomplished using a function or method available in your language of choice. For example, JavaScript provides the btoa()
and atob()
functions to Base64 encode and decode respectively.
A username of normanosborn@oscorp.com
and password of goblin616
are concatenated to normanosborn@oscorp.com:goblin616
. This concatenated string becomes âbm9ybWFub3Nib3JuQG9zY29ycC5jb206Z29ibGluNjE2â once it is Base64 encoded.
curl --request POST \
--url https://api.courier.com/send \
--header 'Authorization: Basic <Base64 encoded string>'
curl --request POST \
--url https://api.courier.com/send \
--header 'Authorization: Basic <Base64 encoded string>'
require 'uri'
require 'net/http'
require 'openssl'
url = URI("https://api.courier.com/send")
http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true
http.verify_mode = OpenSSL::SSL::VERIFY_NONE
request = Net::HTTP::Post.new(url)
request["Authorization"] = 'Basic <Base64 encoded string>'
import requests
url = "https://api.courier.com/send"
headers = {
'Authorization': "Basic <Base64 encoded string>"
}
const xhr = new XMLHttpRequest();
xhr.addEventListener("readystatechange", function () {
if (this.readyState === this.DONE) {
console.log(this.responseText);
}
});
xhr.open("POST", "https://api.courier.com/send");
xhr.setRequestHeader("Authorization", "Basic <Base64 encoded string>");
xhr.send(data);
To authenticate with the Courier REST API, use the email associated with your account as the username and the Auth Token as your password.