Logo

How can we help?

How to send data to NinjaCat

NinjaCat API Integration

In this article:

  1. Add the Custom Data Network to NinjaCat
  2. How to Send Data to NinjaCat
  3. PHP Code Sample
  4. Testing the Data

Add the Custom Data Network to NinjaCat

In order to use NinjaCat’s API integration you need to setup a custom integration and get the unique API Key.  Currently the API integration setup is shared with the Zapier integration so to setup the custom itnegration you first need to setup a Zaiper Network in Ninjacat.

In the NinjaCat UI - click on the “Setup”  and select the “Add Network” button from the “Data Sources” screen.

image9.png

Click on “Connect” under the Zapier icon:

image7.png

Enter a meaningful description for the type of data that you will be creating using this network. After clicking the “Add Network” button, take note of the API key that is generated. You will need this API key to send data to the API.

image4.png

If you want to send different types of data, create another data source and name it appropriately - it will be provided with its own unique API key.

How to Send Data to NinjaCat

In order to send data to NinjaCat you need 2 things:

  1. The Unique API Key (acquired above)
  2. The name of the account you are sending data to. It must match the name of the account in NinjaCat (it is not case sensitive).

The URL to post data to is: https://legacy.ninjacat.io/api/zapier_add_data.php?api_key=$api_key

Consider each post to be a single row of data. So if you want to send 100 rows you will require 100 posts. You should Post Data to that URL with the following parameters:

Parameter

Details

date

This is the date that the data will be associated with.  When working in the data in NinjaCat this date field will be used to determine what time frame this data appears in.

Sample: Y-m-d H:i:s

E.g.:2001-03-10 17:16:18

client

This is the name of the Ninjacat Account the data will be associated with.  It must match the name exactly - it is not case sensitive.

Sample: Coca Cola

data

This is the data to be reported on.  The format is JSON key value pairs.  

Format: {“key”:”value”,”key2”:”value2”}

Sample: {“Campaign”:”Brand Value”, “Clicks”:”100”, “Impressions”:”1500”}

You do not need to format any of the metrics.  Dimensions can be formatted exactly as you want them to be displayed.  You can use ASCII characters to send special displays like \u2193 will display ↓.

 

PHP Code Sample

This sample uses the php Guzzle library (http://docs.guzzlephp.org/en/stable/)

$array = [];
$array["impressions"] = 5;
$array["clicks"] = 10;

$api_key = "INSERT YOUR KEY";
$url = "https://legacy.ninjacat.io/api/zapier_add_data.php?api_key=$api_key";

$params = new \stdClass();
$params->date = Date("Y-m-dTh:m:s", strtotime("now"));
$params->client = "CLIENT NAME";
$data = new stdClass();
foreach($array as $key=>$value){
$data->$key = $value; }
$params->data = $data;

$options = ["headers" => ["Content-Type" => "application/json", "Accept" => "application/json"], "body" => json_encode($params)];

$client = new \GuzzleHttp\Client();
$response = $client->post($url, $options);

Testing the Data

In order to test that the data came through successfully you’ll need to set up a simple template.

Go back to your Network Data Source and edit it. At the top left you should click on the button “Edit Mappings”

 image8.png

 

Click on the Add Mapping Button in the center of the screen.

Give the Mapping a name that you will select in the Template Editor

Add Dimensions based on the data you are passing. You will see the Keys from your data in the “Header Mapping” field. Select the appropriate field in the Header Mapping dropdown. Give the field a friendly name and a Display As Format. Do the same thing for Metrics. Set up as many as you want to have for testing purposes.

Save the mapping and exit the data source.

Click on the “Reporting” menu item and then Templates. Click on the Button on the top right: “Create Template” and then select the “Start from scratch” option.

image1.png

On the Right - Select a Table Widget from under the Data Section

image5.png


Click Add Datasources and select the Custom Data Datasource.

image3.png

Click on the Pencil Icon and select the Mapping you created from the Mapping dropdown list.

image6.png

Select your Dimensions and Metrics from the Add Dimensions and Add Metrics buttons. Make sure that the Date Range (which defaults to last month) includes the timeframe that you sent data against.

Please note that we never show today’s data so if you sent data with today’s date it will not be visible until tomorrow.

 

Was this article helpful?
0 out of 0 found this helpful
Have more questions? Submit a request

0 Comments

Please sign in to leave a comment.