The NinjaCat Outbound API is designed to allow you to pull your data from your templates for any account in NinjaCat. This article leads you through the steps and lists the details for setup and use of the NinjaCat Outbound (Restful) API.
NinjaNote: Use of this feature requires a user account with access to the setup settings, and access to an area of the setup settings that can only be granted by a NinjaCat team member. Contact a NinjaCat team member and request access to the "API" tab in the setup settings.
Section Links
Generate API Key
1. Go to the Setup Settings
2. Click on "Agency Settings" in the sub-navigation
3. Click on the "API" tab under Agency Settings
4. Click on the "Generate" button under the field labeled "Key"
Find Template ID
1. Go to the NinjaCat Template Builder
2. Select the desired, previously created template from the list
3. The Template ID is the string of digits at the end of the URL in the address bar of your web browser
Find Advertiser/Account ID
1. Click on "Accounts" in the top navigation bar
2. Select the desired account from the list
3. The Account ID is the string of digits after "accounts#/" in the URL in the address bar of your web browser
Get Agency ID
1. Contact NinjaCat Support to obtain your Agency ID
Requesting a Report
This rest method will queue up a report to be processed based on the account, template, and date range provided.
URL - |
https://app.ninjacat.io/open_api/report/{agencyId}/{templateId}/{advertiserId} All of these parameters are defined in the Setup above.
|
Method - |
POST
|
Security - |
JWT encoded with your API Key (defined in Setup above) Please see https://jwt.io/ for more info
|
URL Params - |
None
|
Data Params - |
[ "start_date" => "07/01/2017", "end_date" => "08/01/2017" ]
Both start_date and end_date expected format is MM/DD/YYYY.
|
Success Response - |
Status code: 200 [ "request_id" => {ID} ]
The ID is your unique identifier which you will use to query / receive the data.
|
Error Response - |
Status code: 400 [ "error_message" => "message of error" ]
|
Sample Call - |
PHP (requires Guzzle and firebase/php-jwt) $client = new Client(); $url = "https://app.ninjacat.io/open_api"; $agencyId = -1; // replace with correct agency id $advertiserId = -1; //replace with correct account id $key = "secret";
$payLoad = [ "agency_id" => $agencyId, "template_id" => $templateId, "advertiser_id" => $advertiserId ];
$token = JWT::encode($payLoad, $key);
$options = [ "form_params" => [ "start_date" => $startDate, "end_date" => $endDate ], "headers" => [ 'Accept' => 'application/json', 'Authorization' => "Bearer $token" ] ]; $response = $client->post("$url/$agencyId/$templateId/$advertiserId", $options); $result = json_decode($response->getBody());
|
Get Report
This rest method will return the actual report data if the report has been processed or it will return the status of the report if it has not.
URL - |
https://app.ninjacat.io/open_api/report/{agencyId}/{requestId} All of these parameters are defined in the Setup above.
|
Method - |
GET
|
Security - |
JWT encoded with your API Key (defined in Setup above) Please see https://jwt.io/ for more info
|
URL Params - |
None
|
Data Params - |
None
|
Success Response - |
Status code: 200
Response Statuses: 0 = Pending (waiting to be run) 1 = Running 2 = Complete
Sample Response with a report pending: [ "status" => 0, "id" => 12 ]
Sample Response with a report running: [ "status" => 1, "id" => 12 ]
Sample Response on a completed report: [ "success" => true, "status" => 2, "id" => 2, "data" => [ [ "id" => 18, "title" => "Default Title", "dataRows" => [ "rows" => [ [ "dimensions" => [ "aggregate:DIM_MONTH_OF_YEAR" => 8, "aggregate:DIM_YEAR" => 2017 ], "google_adwords??id=0:MET_Clicks" => 5330 ] ] ] ] ],
|
Comments
0 comments
Article is closed for comments.