# Getting Started on 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. Create your account on [Cakemail website](https://www.cakemail.com).

## 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**](/api/reference/token#create-or-refresh-a-token) endpoint along with your Cakemail **_username_** and **_password_**.

```python
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
<?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();
```

```shell
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**](/api/reference/sender#add-a-sender) endpoint along with a name and an email address.

```python
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
<?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();
```

```shell
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.
