Getting started with the Cakemail API
This page will help you get started with Cakemail. You'll be up and running in a jiffy!
In this guide, we will show you how to interact with the Cakemail API.
Requirements
To use the Cakemail API, you need an account. Register your account on our website.
Obtain your access token
The first step is to obtain a token. Tokens are required to make subsequent API calls. To obtain your token, you simply have to call the Create a token endpoint along with your Cakemail username and password.
# you may have to install `requests`: python -m pip install requests
import requests
url = "https://api.cakemail.dev/token"
username = "email@address.com"
password = "yourpassword"
payload = {
"grant_type": "password",
"username": username,
"password": password
}
headers = {
"accept": "application/json",
"content-type": "application/x-www-form-urlencoded"
}
response = requests.post(url, data=payload, headers=headers)
print(response.text)
<?php
// you may have to install `guzzle`: composer require guzzlehttp/guzzle
require_once('vendor/autoload.php');
$client = new \GuzzleHttp\Client();
$response = $client->request('POST', 'https://api.cakemail.dev/token', [
'form_params' => [
'grant_type' => 'password',
'username' => 'email@address.com',.
'password' => 'yourpassword'
],
'headers' => [
'accept' => 'application/json',
'content-type' => 'application/x-www-form-urlencoded',
],
]);
echo $response->getBody();
curl --request POST \
--url https://api.cakemail.dev/token \
--data-urlencode grant_type=password \
--data-urlencode username=[Cakemail username] \
--data-urlencode password=[Cakemail password]
This call, if successful, will return you a valid token containing:
- Access Token
- Token Type
- Expires In
- Refresh Token
The Access Token is what you will need to make the next API call. Before you can send your first email, you will need to create and confirm your first Sender. This step is required so we can make sure you have access to the mailbox of that sender.
Add your first sender
To create your first sender, you will call the Add a sender endpoint along with a name and an email address.
import requests
url = "https://api.cakemail.dev/brands/default/senders"
payload = {
"name": "Sender Name", # change me
"email": "email@address.com", # change me
"language": "en_US"
}
token = "your access token previously obtained" # change me
headers = {
"accept": "application/json",
"content-type": "application/json",
"authorization": f"Bearer {token}"
}
response = requests.post(url, json=payload, headers=headers)
print(response.text)
<?php
require_once('vendor/autoload.php');
$client = new \GuzzleHttp\Client();
$token = "your access token previously obtained"; // change me
$response = $client->request('POST', 'https://api.cakemail.dev/brands/default/senders', [
'body' => '{"language":"en_US", "name":"Sender Name", "email":"email@address.com"}', // change me
'headers' => [
'accept' => 'application/json',
'content-type' => 'application/json',
'authorization' => "Bearer {$token}"
],
]);
echo $response->getBody();
curl --request POST \
--url https://api.cakemail.dev/brands/default/senders \
--header 'accept: application/json' \
--header 'authorization: Bearer [access token]' \
--header 'content-type: application/json' \
--data '{"name":"[name]","email":"[email address]"}'
This will return you a sender object that has an ID. It will also send an email to the email address you specified in the previous step.
Confirm your first sender
To use a sender, it must be confirmed. If the sender email address is the same as your login email address, the sender will automatically be confirmed.
Otherwise, a confirmation email is sent to the sender email address; simply click the activation link to confirm your sender.
Updated 21 days ago