You can query your data from anywhere in your stack by simply making a HTTP request to the following endpoint
GET https://api.blueradar.net/event
This endpoint requires the following:
site_id
(required)
string
api_token
(required)
string
event
(required)
string
from
(required)
string | numeric | DateTime
"2022-07-25 06:23:47"
to
(required)
string | numeric | DateTime
"2022-09-25 06:23:47"
aggregate_type
(optional)
"count" | "sum" | "avg"
value
fields of the rows should be aggregated - default is count
When successful the api will return a http status of 200
with the following format
[
{
"timestamp": "string",
"count": number
},
...
]
Any other status will include either an error message as text
missing api_token field
or a json object with just null
if the query failed to execute
use Carbon\Carbon;
use Illuminate\Support\Facades\Http;
class BlueRadar
{
static function get(
string $event,
Carbon $from,
Carbon $to,
string $aggregate_type = "count"
) {
$siteId = env("BLUERADAR_SITE_ID");
$apiToken = env("BLUERADAR_SITE_API_TOKEN");
if (!$siteId || !$apiToken) {
return null;
}
if (!in_array($aggregate_type, ["count", "sum", "avg"])) {
return null;
}
$res = Http::get("https://api.blueradar.net/event", [
"site_id" => $siteId,
"api_token" => $apiToken,
"event" => $event,
"from" => $from,
"to" => $to,
]);
if (!$res->successful()) {
throw new \Exception(
"Server responded with {$res->status()} for query '{$event}'"
);
}
return $res->json();
}
}
use BlueRadar;
class AnalyticsController extends Controller
{
public function index()
{
$data = BlueRadar::get(
"invoices",
Carbon::today()->subMonth(),
Carbon::now(),
"sum" // get total revenue
);
return view("analytics", [
"data" => $data,
]);
}
}
curl -X GET https://api.blueradar.net/event \
-d site_id="YOUR_SITE_ID" \
-d api_token="YOUR_API_TOKEN" \
-d event="YOUR_EVENT_NAME" \
-d from=FROM_DATE \
-d to=TO_DATE \
-d aggregate_type="AGGREGATE_TYPE"
fetch("https://api.blueradar.net/event", {
body: new URLSearchParams({
site_id: "YOUR_SITE_ID",
api_token: "YOUR_API_TOKEN",
event: "YOUR_EVENT_NAME",
from: "FROM_DATE",
to: "TO_DATE",
aggregate_type: "AGGREGATE_TYPE", // "count" | "sum" | "avg"
}),
});
import requests
data = {
'site_id': 'YOUR_SITE_ID',
'api_token': 'YOUR_API_TOKEN',
'event': 'YOUR_EVENT_NAME',
'from': 'FROM_DATE',
'to': 'TO_DATE',
'aggregate_type': 'AGGREGATE_TYPE', // "count" | "sum" | "avg"
}
response = requests.get('https://api.blueradar.net/event', data=data)
<?php
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, "https://api.blueradar.net/event");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "GET");
curl_setopt($ch, CURLOPT_HTTPHEADER, [
"Content-Type" => "application/x-www-form-urlencoded",
]);
curl_setopt(
$ch,
CURLOPT_POSTFIELDS,
"site_id=YOUR_SITE_ID&api_token=YOUR_API_TOKEN&event=YOUR_EVENT_NAME&from=FROM_DATE&to=TO_DATE&aggregate_type=AGGREGATE_TYPE"
);
$response = curl_exec($ch);
curl_close($ch);