API Example Get Account Balance
From InClickAdServer
Get Account Balance - Single Account
This API Service Request will obtain the balance of the provided inClick Ad Server user account. This Service Request can be used to obtain the balance of any account in the system, advertiser or publisher.
In the factory User Interface (UI), the corresponding information is the Account Balance located in the upper right corner of most screens inside the Account Summary block.
The Code Example
<?php require_once "../globals/globals.php"; require_once (INCLICK_CORE_DIR . "/external/classes/reporting/IMG_AccountBalanceReportManagerClient.php"); require_once (INCLICK_CORE_DIR . "/external/classes/reporting/IMG_AccountBalanceResult.php"); //THE BASE URL OF YOUR AD SERVER DEPLOYMENT $base_url = INCLICK_WEB_URL; //THE SERVICE KEY TO ACCESS THE API $service_key = "YOUR_API_SERVICE_KEY"; //INSTANTIATE THE API CLIENT $balance_manager = new IMG_AccountBalanceReportManagerClient ($base_url, $service_key); $service_result = $balance_manager->getAccountBalance($account_id); if ($service_result->Succeeded()) { $balance_result = $service_result->getReturnValue(); $balance = $balance_result->getBalance(); } else { }?>
Breaking Down the Code
require "../globals/globals.php";
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.
require_once (INCLICK_CORE_DIR . "/external/classes/reporting/IMG_AccountBalanceReportManagerClient.php"); require_once (INCLICK_CORE_DIR . "/external/classes/reporting/IMG_AccountBalanceResult.php");
This will include the files that contain the API Objects and Classes needed for this API Service Request.
$base_url = INCLICK_WEB_URL; $service_key = "YOUR_API_SERVICE_KEY";
The $base_url is the URL to your inClick Ad Server deployment, the ad server root URL. For local host API usage, the constant of INCLICK_WEB_URL is defined in the globals.php file referenced earlier. Remote deployments, deployments where the ad server and API Request Location are not on the same server, would change this to the fully qualified URL to the ad server root directory.
The $service_key is one of the the api_service_keys values you created for your ad server. (more information)
$balance_manager = new IMG_AccountBalanceReportManagerClient ($base_url, $service_key);
This is where we create an instance of the class needed to perform an Account Balance request.
$service_result = $balance_manager->getAccountBalance($account_id);
This line processes the API Service Request using the Account ID ($account_id) provided.
if ($service_result->Succeeded()) { $balance_result = $service_result->getReturnValue(); $balance = $balance_result->getBalance(); print_r($service_result->getReturnValue()); echo "<hr>Account Balance = $balance"; } else { echo ("Failed while requesting a report"); print_r($balance_result); }
This section of code is provided to give you a visual confirmation of what occurred, or to let you know what error occurred.
