Create Campaigns

The campaigns POST function allows you to create a new campaign with the supplied fields.

Overview

While id, createdDate, and modifiedDate are given when retrieving a campaign object, they should be left off the POST function body because they are set by the service. The campaignTypeId, name, and archived fields are required. The description field is optional.

On success, a 201 code is returned with the created campaign.

This request requires an access token with “campaigns-read” scope.

URI

POST: https://rest.bronto.com/campaigns/

Request Body

The data used to create the campaign.

{
  "campaignTypeId": number,
  "name": string,
  "description": string,
  "archived": boolean
}

Response

A response containing the newly created campaign.

{
  "id": number,
  "siteId": number,
  "createdDate": ISO-8601 datetime,
  "modifiedDate": ISO-8601 datetime,
  "campaignTypeId": number,
  "name": string,
  "description": string,
  "archived": boolean
}

Python Code Example

from __future__ import print_function
 
# Requests documentation:  http://docs.python-requests.org/
import requests
 
 
# API authorization
bronto_access_token = "access token"
session = requests.Session()
session.headers["Authorization"] = "Bearer " + bronto_access_token
 
url = "https://rest.bronto.com/campaigns/"
 
json = { "campaignTypeId": 1, "name": "campaign name", "archived": False }
 
response = session.post(url, json=json)
 
if response.ok:
    campaigns = response.json()
    print("campaign:", campaigns)
else:
    print("Could not post campaign (status code={}, content='{}', headers={})".format(
        response.status_code, response.text, response.headers
    ))