Difference between revisions of "API setting"

From Service Manual Kadam.net
Jump to: navigation, search
(Новая страница: «== API authorization == To access the API, you will need a user ID (app_id) and a signature (signature). Calling different methods is carried out using queries o…»)
 
Line 101: Line 101:
 
</pre>
 
</pre>
 
</code>
 
</code>
 +
 +
== Campaign Statistics ==
 +
To get campaign statistics, use the method <b>ads.analytic.campaign.get</b><br/>
 +
<table>
 +
  <tr bgcolor = #DCDCDC>
 +
      <th width = 130 align = left>Parameters</th>
 +
      <th width = 300 align = left>Values</th>
 +
      <th width = 350 align = left>Optional attributes</th>
 +
  </tr>
 +
  <tr bgcolor = #F5F5F5>
 +
      <td>campaign_id</td>
 +
      <td>campaign's id</td>
 +
      <td>int (numeric value), required parameter</td>
 +
  </tr>
 +
  <tr bgcolor = #F5F5F5>
 +
      <td>region_id</td>
 +
      <td>region's id: data.geo.regions.get</td>
 +
      <td>int (numeric value), required parameter</td>
 +
  </tr>
 +
  <tr bgcolor = #F5F5F5>
 +
      <td>period</td>
 +
      <td>The way data is grouped by date:
 +
          <p>day — daily statistics;</p>
 +
          <p>month - monthly statistics</p>
 +
          <p>Temporary restrictions are set by parameters date_from and date_to</p>
 +
      </td>
 +
      <td>required parameter, string</td>
 +
  </tr>
 +
  <tr bgcolor = #F5F5F5>
 +
      <td>date_from</td>
 +
      <td>The starting date of the statistics to display. Different date format is used for different parameter ''period'' values:
 +
          <p>day: YYYY-MM-DD, example: 2011-09-27;</p>
 +
          <p>month: YYYY-MM, example: 2011-09</p>
 +
      </td>
 +
      <td>required parameter, string</td>
 +
  </tr>
 +
  <tr bgcolor = #F5F5F5>
 +
      <td>date_to</td>
 +
      <td>The final date of the displayed statistics. Different date format is used for different parameter ''period'' values:
 +
          <p>day: YYYY-MM-DD, example: 2011-09-27;</p>
 +
          <p>month: YYYY-MM, example: 2011-09</p>
 +
      </td>
 +
      <td>required parameter, string</td>
 +
  </tr>
 +
</table>
 +
<b>Result:</b><br/>
 +
Returns an object with data
 +
<code>
 +
<pre>
 +
{
 +
response: {
 +
count: %total items%
 +
items: {
 +
shows
 +
clicks
 +
ctr
 +
cpm
 +
money
 +
                      }
 +
                  }
 +
}
 +
</pre>
 +
</code>

Revision as of 13:16, 21 January 2019

API authorization

To access the API, you will need a user ID (app_id) and a signature (signature). Calling different methods is carried out using queries on this template:

        api.kadam.net?%action%.%method%?%params%
        % action% - what are we turning to
        % method% - type of treatment
get - get
put - write
post - update
delete - delete
        % params% - request parameters

        required parameters% params%

        app_id - user id
        signature - signature

Example:

       [GET] http://api.kadam.net/campaigns.get?app_id=%app_id%&signature=%signature%

or

       [GET] http://api.kadam.net/campaigns?app_id=%app_id%&signature=%signature%
       [GET] - http access method

Signature (signature) is created using a temporary token (access_token), which can be obtained using the app_id and secret key parameters.
Parameters app_id (user ID) and the key "secret key" are available on request to support.
Getting a token:

       [GET] http://api.kadam.net/auth.token?app_id=%app_id%&secret_key=%key%
       -> {“access_token”: “...”}

Generating signature for the [GET] method:

       md5 ( %sort_params% . %access_token% )
       %sort_params% - all parameters passed (except signature) are sorted by name

Example:

       app_id=1&campaign_id=3…
       [PUT] http://api.kadam.net/campaigns?signature=%signature%
       +post fields -> %params%

Example for php. Getting a list of campaigns:

       <?
        $your_secret_key = "jqhwekq8734quo37o498q3p498qp34";
       $your_app_id = 1;
       $auth_url = "http://api.kadam.net/auth.token?app_id={$your_app_id}&secret_key={$your_secret_key}";
       $auth = file_get_contents($auth_url);
       $auth = json_decode($auth, true);

       if ( !is_array( $auth ) || !isset( $auth['access_token'] ) ) {
           die( 'something wrong! ' . print_r( $res, true ) );
       }

       $token    = $auth['access_token'];
       $params = array(
	    'client_id' => $your_app_id,
        'app_id' => $your_app_id,
       );

       ksort( $params );

       $result = array ();
       foreach( $params as $key => $value ) {
           $result[] = $key . '=' . urlencode( $value );
       }
       $params = implode( '&', $result );
       $signature = md5( $params . $token );

       $campaign_url = 'http://api.kadam.net/ads.campaigns.get?' . $params . '&signature=' . $signature;

       $campaigns = file_get_contents($campaign_url);
       $campaigns = json_decode($campaigns, true);

       if ( !is_array( $campaigns ) || !isset( $campaigns['response'] ) ) {
           die( 'something wrong! ' . print_r( $campaigns, true ) );
       }
       
       print_r($campaigns);
       

Campaign Statistics

To get campaign statistics, use the method ads.analytic.campaign.get

Parameters Values Optional attributes
campaign_id campaign's id int (numeric value), required parameter
region_id region's id: data.geo.regions.get int (numeric value), required parameter
period The way data is grouped by date:

day — daily statistics;

month - monthly statistics

Temporary restrictions are set by parameters date_from and date_to

required parameter, string
date_from The starting date of the statistics to display. Different date format is used for different parameter period values:

day: YYYY-MM-DD, example: 2011-09-27;

month: YYYY-MM, example: 2011-09

required parameter, string
date_to The final date of the displayed statistics. Different date format is used for different parameter period values:

day: YYYY-MM-DD, example: 2011-09-27;

month: YYYY-MM, example: 2011-09

required parameter, string

Result:
Returns an object with data

{
	response: {
		count: %total items%
		items: {
			shows
			clicks
			ctr
			cpm
			money
                       }
                  }
}