API Example Create a Campaign

From InClickAdServer

Creating a New Campaign

This API Service Request will create a new campaign for the specified advertiser.

The Code Example

Breaking it Down

This require references the local inClick Ad Server deployment configuration files allowing your code to utilize the pre-packaged API Objects as well as the bundled PHPOlait services.


These requires (includes) contain the API Objects and Classes needed for this API Service Request.


The $user_id is the inClick Advertiser account number we will be working with for this API Service Request. For this example, we are working with the House Advertiser account, 1001.

The remaining two lines create an instance of the classes needed to create a new campaign.


These parameters are the various portions of the campaigns creative. Assign each $campaign->SetXXXXX with the corresponding values.


The $campaign->AddXXXX objects allow you to added multiple values as needed. In this example, the campaign we are creating will be targeted to viewers in two countries, United States of America (US) and Canada (CA). We then set each country as seen in this code snippet. Country codes are based on ISO-3166 standards.


The $campaign->setDailyBudget and $campaign->setMaximumCPC objects are just as they are described, the daily budget and the max cost-per-click values for this campaign.


The $campaign->setEndDate and $campaign->setStartDate objects are just as they are described, the starting and ending date for the campaign. If these values are not set, the ad server will assume the start date of today and and end date ten years from today.

WARNING: Values for $campaign->setEndDate and $campaign->setStartDate are integer timestamps. Do not enter date formatted values! For example, the timestamp value for May 24, 2023 is 1684900800.

The #campaign->setTypeCode defines the campaign type. Only cost-per-click is supported at this time.


This line is the API Service Reqeust that sends the campaign data to your inClick Ad Server deployment. If a failure occurs, the error code and corresponding error message are returned as objects:

$result->getErrorCode()
$result->getErrorMessage()

If this request is successful, the Campaign ID assigned is available in the following object:

$result->getReturnValue()

This section of code is provided to give you a visual confirmation of what occurred.

Updated 11/14/2016