Logging Events


Overview

You can log events from anywhere in your stack by simply making a HTTP request to the following endpoint

PUT https://api.blueradar.net/log

This endpoint requires the following:

  • site_id (required)
    • string
  • api_token (required)
    • string
  • channel (required)
    • string
    • The name of the channel you want to log the event in (i.e. "errors" or "user activity")
  • title (required)
    • string
    • the title of the event you want to log
  • description (optional)
    • string | null
    • the description of the event
  • icon (optional)
    • string | null
    • an icon to go with the event such as 💰

Response

When successful the api will return a http status of 200

Any other status will include either an error message as text. For example:

failed to find channel

Laravel Example

use Carbon\Carbon;
use Illuminate\Support\Facades\Http;

class BlueRadar
{
  static function log(
    string $title,
    string $description,
    string $icon,
    string $channel
  ) {
    $siteId = env("BLUERADAR_SITE_ID");
    $apiToken = env("BLUERADAR_SITE_API_TOKEN");

    if (!$siteId || !$apiToken) {
      return null;
    }

    $res = Http::put("https://api.blueradar.net/log", [
      "site_id" => $siteId,
      "api_token" => $apiToken,
      "title" => $title,
      "description" => $description,
      "icon" => $icon,
      "channel" => $channel,
    ]);

    if (!$res->successful()) {
      throw new \Exception(
        "Server responded with {$res->status()} for log '{$title}'"
      );
    }

    return true;
  }
}

Usage

use BlueRadar;

class PostController extends Controller
{
  public function store()
  {
    // ...

    BlueRadar::log(
      title: "New Post",
      description: "{$user} created a new post"
      icon: "✍️",
      channel: "Posts"
    );

    // ...
  }
}

CURL Example

curl -X GET https://api.blueradar.net/event \
-d site_id="YOUR_SITE_ID" \
-d api_token="YOUR_API_TOKEN" \
-d title="EVENT_TITLE" \
-d description="EVENT_DESCRIPTION" \
-d icon="EVENT_ICON" \
-d channel="CHANNEL_NAME"

JS Example

fetch("https://api.blueradar.net/log", {
  method: "PUT",
  body: new URLSearchParams({
    site_id: "YOUR_SITE_ID",
    api_token: "YOUR_API_TOKEN",
    title: "EVENT_TITLE",
    description: "EVENT_DESCRIPTION",
    icon: "EVENT_ICON",
    channel: "CHANNEL_NAME",
  }),
});

Python Example

import requests

data = {
  'site_id': 'YOUR_SITE_ID',
  'api_token': 'YOUR_API_TOKEN',
  'title': 'EVENT_TITLE',
  'description': 'EVENT_DESCRIPTION',
  'icon': 'EVENT_ICON',
  'channel': 'CHANNEL_NAME',
}

response = requests.put('https://api.blueradar.net/log', data=data)

PHP Example

<?php
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, "https://api.blueradar.net/log");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "PUT");
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&title=EVENT_TITLE&description=EVENT_DESCRIPTION&icon=EVENT_ICON&channel=CHANNEL_NAME"
);

$response = curl_exec($ch);

curl_close($ch);