JSON report

Bunker DB Analytics offers you the possibility to download the information from your reports in JSON format.

Lucía Achigar avatar
Written by Lucía Achigar
Updated over a week ago

JSON (JavaScript Object Notation) is a simple text format for data exchange. Through Bunker DB's JSON report, you can extract larger amounts of information quickly.


Create a JSON Report

This functionality includes both brand and campaign reports. To download this information, it will be necessary to have:

👉🏽Bunker DB analytics user access credentials (username and password) with permission to view the report.

👉🏽Brand ID or campaign ID to download.

👉🏽A RESTful API compatible client (Postman, Insomnia, etc.).


Get your brand ID

  1. Select one of your brands.

  2. Hover over the "Edit Brand" button.

You will see a URL at the bottom of the browser where the brand ID will be the number at the end.

Endpoint and parameters

API endpoint

If you usually access Bunker DB at example.bunkerdb.com, your API endpoint is:

Sending method

POST

Parameters

  • email: Bunker DB analytics user's email address with sufficient permissions to view the report.

  • password: access password linked to the user's email.

  • type: type of report requested, "brand" or "campaign."

  • object_id: brand ID or campaign ID.

  • period_id: period ID. Possible values:

"cmp" (campaign).

"wkl" (weekly).

"mnt" (monthly).

"qrt" (trimester).

"bia" (biannual).

"ann" (annual).

“l15d” (last 15 days).

"l3d" (last three days).

"l7d" (last seven days).

  • selected_date: period start date, formatted as YYYY-MM-DD.

  • selected_end_date: period end date, formatted as YYYY-MM-DD (for campaigns only).

  • email_report: email where you want the report to be delivered as an attached zip.

  • zip: If you want to obtain the report in plain text or compressed in a zip.
    Possible values:

1 (yes).

2 (no).

Response flow

The JSON response can be synchronous or asynchronous.

  • Synchronous: If an email_report is not specified, then the report will be returned in the same API call, either in plain (JSON) or compressed (via zip) format.
    We suggest configuring a high time out so the connection won't terminate before the report is returned.

  • Asynchronous: if an email is specified in "email_report," then the report will be processed in the background, and status will be printed. The report will be sent to the specified inbox in "email_report" once the data has been processed.

Response format (asynchronous):

{

"id": “Report ID (hash)”

"timestamp": "Report creation date (YYYY-MM-DD H:m:s)",

"email_report": "Report recipient email",

"status": "status (processing, failed)"

}

Example:

{

"id": "c027d8b0bb4726611546f42c04f6b005",

"timestamp": "2020-08-24 15:16:24",

"email_report": "[email protected]",

"status": "processing"

}


Response codes (HTTP status)

200 — OK

The call has been successful, and the report's result is in the body of the response (called synchronous).

202 — Accepted

The report generation request (sent by email) has been received and processed (called asynchronous).

401 — Unauthorized

The credentials provided by email and password are not valid. A control of attempts will be made, and after the maximum of 5, the IP from where the calls are made will be blocked for a period of 60 minutes.

403 — Forbidden

The maximum number of failed attempts has been reached from the calling IP; you will need to try again later.

429 — Too many requests

The maximum number of simultaneous report generation requests allowed has been reached. The response to this error will contain a list of the report identifiers (hash) and the client's creation dates for possible control.

500 — Internal server error

A server-side error has occurred, the support team will check the problem.


Response base structure

Below you can see the base structure of the JSON:

The networks' content will be found within the "available_media" tree:


Query examples

cURL

curl -X POST \
https://{instancia}.bunkerdb.com/report/json \
-H 'cache-control: no-cache' \
-H 'content-type: application/x-www-form-urlencoded' \
-d 'email=it%40bunkerdb.com&password=XXX&type=brand&object_id=1&period_id=mnt&selected_date=2019-06-01&selected_end_date=2019-06-30&email_report=it%40bunkerdb.com'

Python 3

import http.client
conn = http.client.HTTPSConnection("")

payload = "email=it%40bunkerdb.com&password=XXX&type=brand&object_id=1&period_id=mnt&selected_date=2019-06-01&selected_end_date=2019-06-30&email_report=it%40bunkerdb.com"

headers = {
'content-type': "application/x-www-form-urlencoded",
'cache-control': "no-cache"
}

conn.request("POST", "{instancia}.bunkerdb.com/report/json", payload, headers)

res = conn.getresponse()
data = res.read()

print(data.decode("utf-8"))


PHP

<?php

$curl = curl_init();

curl_setopt_array($curl, array(
CURLOPT_URL =>
"https://{instancia}.bunkerdb.com/report/json",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "POST",
CURLOPT_POSTFIELDS => "email=it%40bunkerdb.com&password=XXX&type=brand&object_id=1&period_id=mnt&selected_date=2019-06-01&email_report=it%40bunkerdb.com",
CURLOPT_HTTPHEADER => array(
"cache-control: no-cache",
"content-type: application/x-www-form-urlencoded"
),

));

$response = curl_exec($curl);
$err = curl_error($curl);

curl_close($curl);

if ($err) {
echo "cURL Error #:" . $err;
} else {
echo $response;

}


RESTful API client call example

To request the report, you can use a client for RESTful APIs. Here are the steps to request the report in JSON format.

Interaction with the API is done in "x-www-form-urlencoded" format, so the header ContentType: Application / x-www-form-urlencoded must always be present.

When using the POST method type, you must enter the parameters within the body as follows:

After the API call has been generated, the response will be displayed below the entered parameters:

Did this answer your question?