> ## Documentation Index
> Fetch the complete documentation index at: https://docs.emailbison.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Creating Campaigns

This page will walk you through creating a campaign from the API.

### Creating a Campaign

Send a `POST` request to `/api/campaigns`.

You must pass 1 body parameter, `name`, which corresponds to the name of the campaign you wish to create.

If successful, you will receive a a `200 OK` with the campaign ID as part of the response.

### Campaign Settings

<Tip>
  You can get the ID for a campaign using the UI by navigating to the campaign, clicking on the `Actions` dropdown, and then clicking `Copy ID for API`.

  Alternatively, campaign IDs can be acquired with a `GET` request to `/api/campaigns`.
</Tip>

Each campaign has individual settings that can be changed.

You can view the settings with a `GET` request to `/api/campaigns/{id}` where `{id}` is the campaign ID.

If you need to change the settings, send a `PATCH` request to `/api/campaigns/{id}/update` where `{id}` is the campaign ID.

<Accordion title="This request takes a JSON body with the following fields">
  <ParamField path="max_emails_per_day" type="integer|null" default="1000">
    The maxiumum number of emails that can be sent per day
  </ParamField>

  <ParamField path="max_new_leads_per_day" type="integer|null" default="1000">
    The maximum number of new leads that can be added per day.
  </ParamField>

  <ParamField path="plain_text" type="boolean|null" default="false">
    Whether the email content should be plain text. If nothing sent, false is assumed
  </ParamField>

  <ParamField path="open_tracking" type="boolean|null" default="false">
    Whether open tracking should be enabled for the campaign. If nothing sent, false is assumed.
  </ParamField>

  <ParamField path="reputation_building" type="boolean|null" default="false">
    Spam protection. If nothing sent, false is assumed.
  </ParamField>

  <ParamField path="can_unsubscribe" type="boolean|null" default="false">
    Whether recipients can unsubscribe from the campaign using a one-click link. If nothing sent, false is assumed.
  </ParamField>

  <ParamField path="unsubscribe_text" type="string|null">
    The text that will be shown in the unsubscribe link.
  </ParamField>
</Accordion>

<Accordion title="Show example of a request to update campaign settings">
  <CodeGroup>
    ```bash curl theme={null}
    curl 'https://dedi.emailbison.com/api/campaigns/{id}/update' \
      --request PATCH \
      --header 'Content-Type: application/json' \
      --header 'Authorization: Bearer YOUR_SECRET_TOKEN' \
      --data '{
      "max_emails_per_day": 500,
      "max_new_leads_per_day": 100,
      "plain_text": true,
      "open_tracking": true,
      "reputation_building": true,
      "can_unsubscribe": true,
      "unsubscribe_text": "Click here to unsubscribe"
    }'
    ```

    ```JavaScript JavaScript theme={null}
    fetch('https://dedi.emailbison.com/api/campaigns/{id}/update', {
      method: 'PATCH',
      headers: {
        'Content-Type': 'application/json',
        Authorization: 'Bearer YOUR_SECRET_TOKEN'
      },
      body: JSON.stringify({
        max_emails_per_day: 500,
        max_new_leads_per_day: 100,
        plain_text: true,
        open_tracking: true,
        reputation_building: true,
        can_unsubscribe: true,
        unsubscribe_text: 'Click here to unsubscribe'
      })
    })
    ```

    ```Python Python theme={null}
    url = "https://dedi.emailbison.com/api/campaigns/{id}/update"

    payload = {
    		"max_emails_per_day": 500,
    		"max_new_leads_per_day": 100,
    		"plain_text": True,
    		"open_tracking": True,
    		"reputation_building": True,
    		"can_unsubscribe": True,
    		"unsubscribe_text": "Click here to unsubscribe"
    }
    headers = {
    		"Content-Type": "application/json",
    		"Authorization": "Bearer YOUR_SECRET_TOKEN"
    }

    response = requests.patch(url, json=payload, headers=headers)
    ```
  </CodeGroup>
</Accordion>

### Campaign Schedule

If you have created a schedule for a campaign in the past, you can re-use it provided you've saved it as a template.

**If you have a schedule template you wish to use**:

Get the schedule ID by sending a `GET` request to `/api/campaigns/schedule/templates`.

Once you've acquired the ID, send a `POST` to `/api/campaigns/{campaign_id}/create-schedule-from-template`.

The request requires 1 body field, `schedule_id`, which is the ID of the schedule you want to use.

**If you don't have a schedule template you wish to use**:

If you don't have any templates, or wish to create a new one, send a `POST` request to `/api/campaigns/{campaign_id}/schedule`.

<Accordion title="Show JSON body fields for request">
  <ParamField path="monday" type="boolean" required>
    Whether the schedule includes Monday.
  </ParamField>

  <ParamField path="tuesday" type="boolean" required>
    Whether the schedule includes Tuesday.
  </ParamField>

  <ParamField path="wednesday" type="boolean" required>
    Whether the schedule includes Wednesday.
  </ParamField>

  <ParamField path="thursday" type="boolean" required>
    Whether the schedule includes Thursday.
  </ParamField>

  <ParamField path="friday" type="boolean" required>
    Whether the schedule includes Friday.
  </ParamField>

  <ParamField path="saturday" type="boolean" required>
    Whether the schedule includes Saturday.
  </ParamField>

  <ParamField path="sunday" type="boolean" required>
    Whether the schedule includes Sunday.
  </ParamField>

  <ParamField path="start_time" type="string" required>
    The start time in HH:MM format.

    Example: `09:00`
  </ParamField>

  <ParamField path="end_time" type="string" required>
    The end time in HH:MM format.

    Example: `17:00`
  </ParamField>

  <ParamField path="timezone" type="string" required>
    The timezone of the schedule.

    <Accordion title="Show full list of timezone strings">
      You need to use the formatted string after the `=>` symbol.

      e.g. "America/Los\_Angeles"

      <Tabs>
        <Tab title="GMT -12:00 to -06:00">
          (GMT-12:00) International Date Line West => **Pacific/Kwajalein**

          (GMT-11:00) Midway Island => **Pacific/Midway**

          (GMT-11:00) Samoa => **Pacific/Apia**

          (GMT-10:00) Hawaii => **Pacific/Honolulu**

          (GMT-09:00) Alaska => **America/Anchorage**

          (GMT-08:00) Pacific Time (US & Canada) => **America/Los\_Angeles**

          (GMT-08:00) Tijuana => **America/Tijuana**

          (GMT-07:00) Arizona => **America/Phoenix**

          (GMT-07:00) Mountain Time (US & Canada) => **America/Denver**

          (GMT-07:00) Chihuahua => **America/Chihuahua**

          (GMT-07:00) La Paz => **America/Chihuahua**

          (GMT-07:00) Mazatlan => **America/Mazatlan**

          (GMT-06:00) Central Time (US & Canada) => **America/Chicago**

          (GMT-06:00) Central America => **America/Managua**

          (GMT-06:00) Guadalajara => **America/Mexico\_City**

          (GMT-06:00) Mexico City => **America/Mexico\_City**

          (GMT-06:00) Monterrey => **America/Monterrey**

          (GMT-06:00) Saskatchewan => **America/Regina**
        </Tab>

        <Tab title="GMT -05:00 to 00:00">
          (GMT-05:00) Eastern Time (US & Canada) => **America/New\_York**

          (GMT-05:00) Indiana (East) => **America/Indiana/Indianapolis**

          (GMT-05:00) Bogota => **America/Bogota**

          (GMT-05:00) Lima => **America/Lima**

          (GMT-05:00) Quito => **America/Bogota**

          (GMT-04:00) Atlantic Time (Canada) => **America/Halifax**

          (GMT-04:00) Caracas => **America/Caracas**

          (GMT-04:00) La Paz => **America/La\_Paz**

          (GMT-04:00) Santiago => **America/Santiago**

          (GMT-03:30) Newfoundland => **America/St\_Johns**

          (GMT-03:00) Brasilia => **America/Sao\_Paulo**

          (GMT-03:00) Buenos Aires => **America/Argentina/Buenos\_Aires**

          (GMT-03:00) Georgetown => **America/Argentina/Buenos\_Aires**

          (GMT-03:00) Greenland => **America/Godthab**

          (GMT-02:00) Mid-Atlantic => **America/Noronha**

          (GMT-01:00) Azores => **Atlantic/Azores**

          (GMT-01:00) Cape Verde Is. => **Atlantic/Cape\_Verde**

          (GMT) Casablanca => **Africa/Casablanca**

          (GMT) Dublin => **Europe/London**

          (GMT) Edinburgh => **Europe/London**

          (GMT) Lisbon => **Europe/Lisbon**

          (GMT) London => **Europe/London**

          (GMT) Monrovia => **Africa/Monrovia**
        </Tab>

        <Tab title="GMT +01:00 to +02:00">
          (GMT+01:00) Amsterdam => **Europe/Amsterdam**

          (GMT+01:00) Belgrade => **Europe/Belgrade**

          (GMT+01:00) Berlin => **Europe/Berlin**

          (GMT+01:00) Bern => **Europe/Berlin**

          (GMT+01:00) Bratislava => **Europe/Bratislava**

          (GMT+01:00) Brussels => **Europe/Brussels**

          (GMT+01:00) Budapest => **Europe/Budapest**

          (GMT+01:00) Copenhagen => **Europe/Copenhagen**

          (GMT+01:00) Ljubljana => **Europe/Ljubljana**

          (GMT+01:00) Madrid => **Europe/Madrid**

          (GMT+01:00) Paris => **Europe/Paris**

          (GMT+01:00) Prague => **Europe/Prague**

          (GMT+01:00) Rome => **Europe/Rome**

          (GMT+01:00) Sarajevo => **Europe/Sarajevo**

          (GMT+01:00) Skopje => **Europe/Skopje**

          (GMT+01:00) Stockholm => **Europe/Stockholm**

          (GMT+01:00) Vienna => **Europe/Vienna**

          (GMT+01:00) Warsaw => **Europe/Warsaw**

          (GMT+01:00) West Central Africa => **Africa/Lagos**

          (GMT+01:00) Zagreb => **Europe/Zagreb**

          (GMT+02:00) Athens => **Europe/Athens**

          (GMT+02:00) Bucharest => **Europe/Bucharest**

          (GMT+02:00) Cairo => **Africa/Cairo**

          (GMT+02:00) Harare => **Africa/Harare**

          (GMT+02:00) Helsinki => **Europe/Helsinki**

          (GMT+02:00) Istanbul => **Europe/Istanbul**

          (GMT+02:00) Jerusalem => **Asia/Jerusalem**

          (GMT+02:00) Kyev => **Europe/Kiev**

          (GMT+02:00) Minsk => **Europe/Minsk**

          (GMT+02:00) Pretoria => **Africa/Johannesburg**

          (GMT+02:00) Riga => **Europe/Riga**

          (GMT+02:00) Sofia => **Europe/Sofia**

          (GMT+02:00) Tallinn => **Europe/Tallinn**

          (GMT+02:00) Vilnius => **Europe/Vilnius**
        </Tab>

        <Tab title="GMT +03:00 to +07:00">
          (GMT+03:00) Baghdad => **Asia/Baghdad**

          (GMT+03:00) Kuwait => **Asia/Kuwait**

          (GMT+03:00) Moscow => **Europe/Moscow**

          (GMT+03:00) Nairobi => **Africa/Nairobi**

          (GMT+03:00) Riyadh => **Asia/Riyadh**

          (GMT+03:00) St. Petersburg => **Europe/Moscow**

          (GMT+03:00) Volgograd => **Europe/Volgograd**

          (GMT+03:30) Tehran => **Asia/Tehran**

          (GMT+04:00) Abu Dhabi => **Asia/Muscat**

          (GMT+04:00) Baku => **Asia/Baku**

          (GMT+04:00) Muscat => **Asia/Muscat**

          (GMT+04:00) Tbilisi => **Asia/Tbilisi**

          (GMT+04:00) Yerevan => **Asia/Yerevan**

          (GMT+04:30) Kabul => **Asia/Kabul**

          (GMT+05:00) Ekaterinburg => **Asia/Yekaterinburg**

          (GMT+05:00) Islamabad => **Asia/Karachi**

          (GMT+05:00) Karachi => **Asia/Karachi**

          (GMT+05:00) Tashkent => **Asia/Tashkent**

          (GMT+05:30) Chennai => **Asia/Kolkata**

          (GMT+05:30) Kolkata => **Asia/Kolkata**

          (GMT+05:30) Mumbai => **Asia/Kolkata**

          (GMT+05:30) New Delhi => **Asia/Kolkata**

          (GMT+05:45) Kathmandu => **Asia/Kathmandu**

          (GMT+06:00) Almaty => **Asia/Almaty**

          (GMT+06:00) Astana => **Asia/Dhaka**

          (GMT+06:00) Dhaka => **Asia/Dhaka**

          (GMT+06:00) Novosibirsk => **Asia/Novosibirsk**

          (GMT+06:00) Sri Jayawardenepura => **Asia/Colombo**

          (GMT+06:30) Rangoon => **Asia/Rangoon**

          (GMT+07:00) Bangkok => **Asia/Bangkok**

          (GMT+07:00) Hanoi => **Asia/Bangkok**

          (GMT+07:00) Jakarta => **Asia/Jakarta**

          (GMT+07:00) Krasnoyarsk => **Asia/Krasnoyarsk**
        </Tab>

        <Tab title="GMT +8:00 to +13:00">
          (GMT+08:00) Beijing => **Asia/Hong\_Kong**

          (GMT+08:00) Chongqing => **Asia/Chongqing**

          (GMT+08:00) Hong Kong => **Asia/Hong\_Kong**

          (GMT+08:00) Irkutsk => **Asia/Irkutsk**

          (GMT+08:00) Kuala Lumpur => **Asia/Kuala\_Lumpur**

          (GMT+08:00) Perth => **Australia/Perth**

          (GMT+08:00) Singapore => **Asia/Singapore**

          (GMT+08:00) Taipei => **Asia/Taipei**

          (GMT+08:00) Ulaan Bataar => **Asia/Irkutsk**

          (GMT+08:00) Urumqi => **Asia/Urumqi**

          (GMT+09:00) Osaka => **Asia/Tokyo**

          (GMT+09:00) Sapporo => **Asia/Tokyo**

          (GMT+09:00) Seoul => **Asia/Seoul**

          (GMT+09:00) Tokyo => **Asia/Tokyo**

          (GMT+09:00) Yakutsk => **Asia/Yakutsk**

          (GMT+09:30) Adelaide => **Australia/Adelaide**

          (GMT+09:30) Darwin => **Australia/Darwin**

          (GMT+10:00) Brisbane => **Australia/Brisbane**

          (GMT+10:00) Canberra => **Australia/Sydney**

          (GMT+10:00) Guam => **Pacific/Guam**

          (GMT+10:00) Hobart => **Australia/Hobart**

          (GMT+10:00) Melbourne => **Australia/Melbourne**

          (GMT+10:00) Port Moresby => **Pacific/Port\_Moresby**

          (GMT+10:00) Sydney => **Australia/Sydney**

          (GMT+10:00) Vladivostok => **Asia/Vladivostok**

          (GMT+11:00) Magadan => **Asia/Magadan**

          (GMT+11:00) New Caledonia => **Asia/Magadan**

          (GMT+11:00) Solomon Is. => **Asia/Magadan**

          (GMT+12:00) Auckland => **Pacific/Auckland**

          (GMT+12:00) Fiji => **Pacific/Fiji**

          (GMT+12:00) Kamchatka => **Asia/Kamchatka**

          (GMT+12:00) Marshall Is. => **Pacific/Fiji**

          (GMT+12:00) Wellington => **Pacific/Auckland**

          (GMT+13:00) Nuku\alofa => **Pacific/Tongatapu**
        </Tab>
      </Tabs>
    </Accordion>
  </ParamField>

  <ParamField path="save_as_template" type="boolean" required>
    Whether the created schedule should be saved as template.
  </ParamField>
</Accordion>

<Accordion title="Show example request to create schedule">
  <CodeGroup>
    ```bash curl theme={null}
    curl 'https://dedi.emailbison.com/api/campaigns/{campaign_id}/schedule' \
      --request POST \
      --header 'Content-Type: application/json' \
      --header 'Authorization: Bearer YOUR_SECRET_TOKEN' \
      --data '{
      "monday": true,
      "tuesday": true,
      "wednesday": true,
      "thursday": true,
      "friday": true,
      "saturday": false,
      "sunday": false,
      "start_time": "09:00",
      "end_time": "17:00",
      "timezone": "America/New_York",
      "save_as_template": false
    }'
    ```

    ```JavaScript JavaScript theme={null}
    fetch('https://dedi.emailbison.com/api/campaigns/{campaign_id}/schedule', {
      method: 'POST',
      headers: {
        'Content-Type': 'application/json',
        Authorization: 'Bearer YOUR_SECRET_TOKEN'
      },
      body: JSON.stringify({
        monday: true,
        tuesday: true,
        wednesday: true,
        thursday: true,
        friday: true,
        saturday: false,
        sunday: false,
        start_time: '09:00',
        end_time: '17:00',
        timezone: 'America/New_York',
        save_as_template: false
      })
    })
    ```

    ```Python Python theme={null}
    import requests

    url = "https://dedi.emailbison.com/api/campaigns/%7Bcampaign_id%7D/schedule"

    payload = {
        "monday": True,
        "tuesday": True,
        "wednesday": True,
        "thursday": True,
        "friday": True,
        "saturday": False,
        "sunday": False,
        "start_time": "09:00",
        "end_time": "17:00",
        "timezone": "America/New_York",
        "save_as_template": False
    }
    headers = {
        "Content-Type": "application/json",
        "Authorization": "Bearer YOUR_SECRET_TOKEN"
    }

    response = requests.post(url, json=payload, headers=headers)
    ```
  </CodeGroup>
</Accordion>

### Campaign Sequence

The sequence of the campaign is the emails that will be sent out.

To create your sequence, send a `POST` request to `/api/campaigns/{campaign_id}/sequence-steps`.

The request can take only 2 fields in the body JSON. `title` and `sequence_steps`.

`title` is a string, and `sequence_steps` is an array that contains the following fields:

<Accordion title="Show sequence_steps fields">
  <ParamField path="title" type="string" required>
    The title of the sequence
  </ParamField>

  <ParamField path="email_subject" type="string" required>
    The subject of the email. To include variables, type in them in uppercase and wrap them with curly braces.

    Note that these variables must exist as custom variables in your workspace.

    Example: `"This is an email subject with a {VARIABLE}."`
  </ParamField>

  <ParamField path="email_body" type="string" required>
    The body of the email. To include variables, type in them in uppercase and wrap them with curly braces.

    Note that these variables must exist as custom variables in your workspace.

    Example: `"This is an email body with a {VARIABLE}."`
  </ParamField>

  <ParamField path="wait_in_days" type="integer" required>
    How many days before the sequence moves to the next step.
  </ParamField>

  <ParamField path="variant" type="boolean|null">
    Whether the step is a variant
  </ParamField>

  <ParamField path="variant_from_step" type="integer|null">
    Required if `variant` is true.

    The ID of the step this step is a variant of. You can get the step IDs with a `GET` request to \`/api/campaigns/{campaign_id}/sequence-steps.
  </ParamField>

  <ParamField path="thread_reply" type="boolean" required>
    Whether the step should be a reply from the previous step.
  </ParamField>
</Accordion>

The request will look like the following example:

<Accordion title="Show example sequence creation request">
  <CodeGroup>
    ```bash curl theme={null}
    curl 'https://dedi.emailbison.com/api/campaigns/{campaign_id}/sequence-steps' \
      --request POST \
      --header 'Content-Type: application/json' \
      --header 'Authorization: Bearer YOUR_SECRET_TOKEN' \
      --data '{
        "title": "test sequence",
        "sequence_steps": [
            {
                "email_subject": "Hey {FIRST_NAME}",
                "order": 1,
                "email_body": "You should check this {PRODUCT] out!",
                "wait_in_days": 1,
                "variant": true,
                "variant_from_step": 223
            },
            {
                "email_subject": "EmailBison is awesome!",
                "order": 2,
                "email_body": "Try it now!",
                "wait_in_days": 1,
                "variant": true,
                "variant_from_step": 1,
                "thread_reply": true
            }
        ]
    }'
    ```

    ```JavaScript JavaScript theme={null}
    fetch('https://dedi.emailbison.com/api/campaigns/{campaign_id}/sequence-steps', {
      method: 'POST',
      headers: {
        'Content-Type': 'application/json',
        'Authorization': 'Bearer YOUR_SECRET_TOKEN'
      },
      body: JSON.stringify({
        'title': 'test sequence',
        'sequence_steps': [
          {
            'email_subject': 'Hey {FIRST_NAME}',
            'order': 1,
            'email_body': 'You should check this {PRODUCT] out!',
            'wait_in_days': 1,
            'variant': true,
            'variant_from_step': 223
          },
          {
            'email_subject': 'EmailBison is awesome!',
            'order': 2,
            'email_body': 'Try it now!',
            'wait_in_days': 1,
            'variant': true,
            'variant_from_step': 1,
            'thread_reply': true
          }
        ]
      })
    });
    ```

    ```Python Python theme={null}
    import requests

    headers = {
        'Content-Type': 'application/json',
        'Authorization': 'Bearer YOUR_SECRET_TOKEN',
    }

    json_data = {
        'title': 'test sequence',
        'sequence_steps': [
            {
                'email_subject': 'Hey {FIRST_NAME}',
                'order': 1,
                'email_body': 'You should check this {PRODUCT] out!',
                'wait_in_days': 1,
                'variant': True,
                'variant_from_step': 223,
            },
            {
                'email_subject': 'EmailBison is awesome!',
                'order': 2,
                'email_body': 'Try it now!',
                'wait_in_days': 1,
                'variant': True,
                'variant_from_step': 1,
                'thread_reply': True,
            },
        ],
    }

    response = requests.post(
        'https://dedi.emailbison.com/api/campaigns/{campaign_id}/sequence-steps',
        headers=headers,
        json=json_data,
    )
    ```
  </CodeGroup>
</Accordion>

### Launching Campaign

After creating a campaign, updating its settings, creating or choosing a schedule, and creating a sequence, you have completed all the necessary steps in creating a campaign.

You can send these requests to check the details of a campaign:

* `GET /api/campaigns/{campaign_id}`: retrieves the campaign you created and its settings.

* `GET /api/campaigns/{campaign_id}/schedule`: retreives the campaign schedule.

* `GET /api/campaigns/{campaign_id}/sequence-steps`: retrieves the campaign sequences steps.

**Once you're ready to launch your campaign, send a `PATCH` request to `/api/campaigns/{campaign_id}/resume`.**

You can pause the campaign by sending a `PATCH` request to `/api/campaigns/{campaign_id}/pause`.
