CityGrid Advertising APIs
Campaign API
Introduction
The CityGrid Campaign API is part of the Advertising API suite and enables developers to write applications to manage campaigns. A campaign holds one or more ad groups together with a budget and serving date range. The API provides two endpoints: campaign/get and campaign/mutate.
Contents
Campaign Get Endpoint
The campaign/get endpoint retrieves information about one or more selected campaigns. The operation is invoked via HTTPS GET to:
Request Parameters
Parameter | Description | Required | Type | Default | Example |
|---|---|---|---|---|---|
| Comma-separated list of campaign IDs. If specified, other filter parameters will be ignored. | No | Long | — | 1,2,3,4,5 |
| Comma-separated list of external IDs of the campaign. If specified without | No | Long | — | 6,7,8,9,10 |
| Case-sensitive list of statuses for filtering | No | {ACTIVE, CANCELLED, PENDING, SUSPENDED} | — | ACTIVE |
| Restricts campaigns to those starting on or after this date. This date refers to the date the creator of the campaign indicated that the campaign should start, not necessarily the date the campaign actually started. | No | String | — | 20100131 |
| Restricts campaigns to those ending on or before this date. If the field is omitted, campaigns for all end dates are returned. | No | String | — | 20100131 |
| Field(s) to sort by | No | {name, date} | — | name |
| Used with | No | {true, false} | — | false |
| Page number of results to return (zero-based) | No | Integer | 0 | 5 |
| Number of results per page | No | Integer | 10 | 25 |
If campaignId appears, then all other parameters will be ignored.
If externalId appears and campaignId does not appear, then all other parameters will be ignored.
Request Headers
Header | Description | Required | Valid Values | |
|---|---|---|---|---|
| Requested format for the response | Yes |
| |
| Authentication Token from the Authentication API | Yes | Valid token | |
| The token received during registration | Yes | Valid token |
|
Request Examples
Example 1: Get campaigns 1, 54, 766, and 5678
curl -X GET \
-H 'Accept:application/json' \
-H 'authToken:mytoken' \
-H 'developerToken:myDevToken' \
'https://api.citygrid.com/advertising/campaign/v2/get?campaignId=1,54,766,5678'
Example 2: Get all campaigns in a date range for the current user's account, 8 campaigns per page, ordered ascending by name
curl -X GET \
-H 'Accept:application/json' \
-H 'authToken:mytoken' \
-H 'developerToken:myDevToken' \
'https://api.citygrid.com/advertising/campaign/v2/get?startDate=20100324&endDate=20110720&ordering=name&sortAsc=true&numberResults=8'
Example 3: Get campaigns with external ids 1 and 2
curl -X GET \
-H 'Accept:application/json' \
-H 'authToken:mytoken' \
-H 'developerToken:myDevToken' \
'https://api.citygrid.com/advertising/campaign/v2/get?externalId=1,2'
Example 4: Get all active campaigns for the current user's account
curl -X GET \
-H 'Accept:application/json' \
-H 'authToken:mytoken' \
-H 'developerToken:myDevToken' \
'https://api.citygrid.com/advertising/campaign/v2/get?campaignStatus=ACTIVE'
Response Properties
Property | Type | Description |
|---|---|---|
| Response Metadata | |
| Integer | Total number of campaigns in the response |
| Double | Total monthly budget for the campaigns listed |
| Double | Total daily budget for the campaigns listed |
| Campaign List | The campaigns returned from the search |
| String | The campaign ID |
| String | Arbitrary campaign name, not shown in the ads |
| {ACTIVE, CANCELLED, PENDING, | Status of the campaign in the system |
| Datestring | Date that the creator of the campaign indicated the campaign should begin, YYYYMMDD format |
| Datestring | Date that the campaign ends if any, YYYYMMDD format |
| Datestring | Date when campaign should no longer be in distribution. cancelDate is set to following day in YYYYMMDD format when REMOVE operation is called. It is empty when it is not on cancelled or pending cancellation state |
| Double | Current budget for campaign, in U.S. Dollars |
| {DAILY, MONTHLY} | Period over which to spend the budget |
| Long | External ID of the campaign |
affiliateId | Integer | Affiliate ID of the campaign |
Response Examples
Example 1: A XML success response
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<results>
<totalNumEntries>4</totalNumEntries>
<totalBudget>30</totalBudget>
<totalDailyBudget>94</totalDailyBudget>
<campaigns>
<campaign>
<affiliateId></affiliateId>
<budgetAmount>90</budgetAmount>
<endDate>20170520</endDate>
<cancelDate></cancelDate>
<externalId/>
<id>3167472</id>
<name>myFallCampaign</name>
<period>DAILY</period>
<response>
<code>SUCCESS</code>
<field/>
<message>Success</message>
</response>
<servingStatus>PENDING</servingStatus>
<startDate>20120920</startDate>
</campaign>
<campaign>
<affiliateId>8</affiliateId>
<budgetAmount>20</budgetAmount>
<endDate>20170520</endDate>
<cancelDate></cancelDate>
<externalId/>
<id>3167502</id>
<name>myFallCampaign</name>
<period>MONTHLY</period>
<response>
<code>SUCCESS</code>
<field/>
<message>Success</message>
</response>
<servingStatus>PENDING</servingStatus>
<startDate>20120920</startDate>
</campaign>
<campaign>
<affiliateId></affiliateId>
<budgetAmount>10</budgetAmount>
<endDate>20170520</endDate>
<cancelDate></cancelDate>
<externalId/>
<id>3167492</id>
<name>myFallCampaign</name>
<period>MONTHLY</period>
<response>
<code>SUCCESS</code>
<field/>
<message>Success</message>
</response>
<servingStatus>PENDING</servingStatus>
<startDate>20120920</startDate>
</campaign>
<campaign>
<affiliateId></affiliateId>
<budgetAmount>4</budgetAmount>
<endDate>20170520</endDate>
<cancelDate></cancelDate>
<externalId/>
<id>3167482</id>
<name>myFallCampaign</name>
<period>DAILY</period>
<response>
<code>SUCCESS</code>
<field/>
<message>Success</message>
</response>
<servingStatus>PENDING</servingStatus>
<startDate>20120920</startDate>
</campaign>
</campaigns>
</results>
Example 2: A JSON success response
{
"totalNumEntries": 4,
"totalBudget": 30,
"totalDailyBudget": 94,
"campaigns": [
{
"response": {
"code": "SUCCESS",
"message": "Success",
"field": ""
},
"id": "3167472",
"externalId": "",
"startDate": "20120920",
"endDate": "20170520",
"cancelDate": "",
"name": "myFallCampaign",
"servingStatus": "PENDING",
"period": "DAILY",
"budgetAmount": "90"
"affiliateId": ""
},
{
"response": {
"code": "SUCCESS",
"message": "Success",
"field": ""
},
"id": "3167502",
"externalId": "",
"startDate": "20120920",
"endDate": "20170520",
"cancelDate": "",
"name": "myFallCampaign",
"servingStatus": "PENDING",
"period": "MONTHLY",
"budgetAmount": "20"
"affiliateId": "8"
},
{
"response": {
"code": "SUCCESS",
"message": "Success",
"field": ""
},
"id": "3167492",
"externalId": "",
"startDate": "20120920",
"endDate": "20170520",
"cancelDate": "",
"name": "myFallCampaign",
"servingStatus": "PENDING",
"period": "MONTHLY",
"budgetAmount": "10"
"affiliateId": ""
},
{
"response": {
"code": "SUCCESS",
"message": "Success",
"field": ""
},
"id": "3167482",
"externalId": "",
"startDate": "20120920",
"endDate": "20170520",
"cancelDate": "20130119",
"name": "myFallCampaign",
"servingStatus": "PENDING",
"period": "DAILY",
"budgetAmount": "4"
"affiliateId": ""
}
]
}
Campaign Mutate Endpoint
The campaign/mutate endpoint uses five operators to provide the following operations on campaigns:
The ADD operator creates a campaign.
The SET operator updates campaign properties.
The PAUSE operator pauses a campaign
The UNPAUSE operator re-activates a campaign
The REMOVE operator cancels a campaign.
These operations are invoked via HTTPS POST to:
Input data such as request parameters are subject to field size limits.
Request Parameters
Every campaign mutate request requires the following two parameters:
Property | Type | Description | Required |
|---|---|---|---|
| {ADD, REMOVE, SET, PAUSE, UNPAUSE} | Type of operation to perform (case sensitive). See the section below | Yes |
| Campaign | The campaign to operate on | Yes |
The properties of a Campaign request operand are:
Property | Type | Description | Required | Limits |
|---|---|---|---|---|
| String | Name of the campaign | If operator is ADD | 100 chars |
| Long | ID of the campaign | If operator is SET, REMOVE, PAUSE or UNPAUSE (unless | 10 digits |
| Long | External ID of the campaign | If operator is SET, REMOVE, PAUSE or UNPAUSE (unless | 10 digits |
| String | Status of the campaign | No | 9 chars |
| Budget | Budget object for this request | No- See details below | 11 digits total, 4 decimals |
| String | Type of the product of the campaign, default is PERFORMANCE | No |
|
affiliateId | Integer | The ID of the affiliate of the campaign. For SET if affiliateId is an empty string the current value will be removed. | No | 4 digits |
startDate | Datestring | Indicates when the campaign should start, In YYYYMMDD format. This date refers to the date that the creator of the campaign indicated that the campaign should start, not necessarily the date the campaign actually started. For the ADD and SET operations, this date cannot be before the current date. For the SET operation, this date cannot be before the creation date of the campaign. | No (default is current date) |
|
| Datestring | Indicates when the campaign should end, in YYYYMMDD format | No (default is to run indefinitely) | 1000 chars |
| String | The reason for the cancellation | If operator is REMOVE |
|
| Integer | The ID of the status reason associated with campaign deactivation | No |
|
Budget
The Campaign operand may or may not include a budget object. If you wish to set budget at the AdGroup level do not include the budget object in your Campaign API requests. You may create a campaign budget at the time the campaign is created (ADD operation) or you may add it later using the campaign SET operation. Once the budget is added at the Campaign level, it cannot be configured at the AdGroup level and vice versa. properties of a budget object in a request are as follows:
Property | Type | Description | Required | Notes |
|---|---|---|---|---|
| Double | Amount of budget in U.S. Dollars | Yes |
|
| {Daily, Monthly} | Period over which to spend the budget | No | If this property is not supplied, the budget period defaults to monthly |
Notes
A campaign will not become active until budget is added either at the Campaign level or the AdGroup level (the AdGroup API is used to configure budget at the AdGroup level).
Once an external ID is used to create campaign, that external ID cannot be reassigned to another campaign.
The campaignId and externalId properties cannot be submitted together for a mutate operation.
The period can not switched from monthly to daily or from daily to monthly once it is set.
Request Headers
Header | Description | Required | Valid Values | |
|---|---|---|---|---|
| Media type of the request body | Yes |
| |
| Requested format for the response | Yes |
| |
| Authentication Token from Authentication API | Yes | Valid token | |
| The token received during registration | Yes | Valid token |
|
Request Examples
Example 1: Create a campaign with a $3000 budget ending on 2017-05-20
{
"mutateOperationListResource":[
{
"operator":"ADD",
"operand":{
"mopId":"202602",
"name":"myFallCampaign",
"endDate":"20170520",
"product":"PERFORMANCE",
"affiliateId":"11",
"budget":{
"amount":"100.0",
"period":"Monthly"
}
}
}
]
}
Example 2: Update campaigns 3168332 and remove campaign 3981
{
"mutateOperationListResource":[
{
"operator":"SET",
"operand":{
"id":"3168332",
"budget":{
"period":"MONTHLY",
"amount":"50.0"
}
}
},
{
"operator":"REMOVE",
"operand":{
"id":"3981",
"reason":"The campaign period expired"
}
}
]
}
Example 3: Update campaign 3168332, remove campaign 3981 (XML)
<mutateOperationListResource>
<mutateOperation>
<operator>SET</operator>
<operand>
<id>3168332</id>
<budget>
<period>MONTHLY</period>
<amount>50.0</amount>
</budget>
</operand>
</mutateOperation>
<mutateOperation>
<operator>REMOVE</operator>
<operand>
<id>3981</id>
<reason>The campaign period expired</reason>
</operand>
</mutateOperation>
</mutateOperationListResource>
Response Properties
Property | Type | Description |
|---|---|---|
| Response Metadata | |
| Campaign list | List of campaigns |
| Long | The Campaign ID |
| Long |