LogoLogo
HomeApplicationBlog
  • WELCOME
    • Overview
    • Quickstart
    • Key Features
    • Demo
  • ONBOARDING YOUR DATA
    • Getting started
    • Prerequisites
    • Integrations
      • Prometheus
        • Handling organization_id
        • Privacy and Security
      • CloudWatch
      • Datadog
      • Coming soon
      • Request integration
    • Self-hosting
      • Configuration yaml
      • Running locally with Docker
      • Running with Kubernetes (k8s)
    • Data API
      • Example implementation
    • Filters
      • Open source log parsing library
      • Data hashing & transformation
    • Custom adapters
  • API (BETA)
    • Authentication
    • Pagination
    • API Reference
  • How to's
    • Tutorials
      • Build a SLI
      • Build a SLO
      • Create an Organization
      • Build a SLA
      • Configure a SLA Portal
    • Guides
    • Glossary
  • MISC
    • Changelog
    • Join the Closed Beta
  • Legal
    • Terms of Service
    • Contributor License Agreement
    • Privacy Notice
Powered by GitBook
On this page
  1. API (BETA)

Authentication

PreviousCustom adaptersNextPagination

Last updated 5 months ago

To enable users to programatically perform CRUD operations on organizations and SLIs, Os and As we have implemented m2m (machine to machine) authentication. You need to be authenticated in order to access it, i.e. by logging into slaOS on the frontend.

Create token flow

Once logged in, use the javascript provided below to create the token. You can copy and paste this javascript in the browser console and run it.

(fetch(`${window.location.protocol}//${window.location.host}/api/slaos/v1/users/m2m-token`, {method: 'GET'}).then(response => response.json()).then(json => json["jwt"]).then(console.log))();

This token can be used to access the slaOS APIs programmatically. On our end, the machine will be identified with the id of the user that obtained the token.

Note that the token has an expiry date of one year.

The token is then added in the API request headers with the value Authorization: Bearer <token>

Your token carries many privileges, so be sure to keep them secure! Do not share your token in publicly accessible areas such as GitHub, client-side code, and so forth.

#Authenticated Request
curl -v -X 'POST' \
'https://api.rated.co/v1/slos/' \
-H 'Content-Type: application/json' \
-H 'Authorization: Bearer <YOUR-TOKEN-HERE>'
-d '{
  "name": "Uptime percentage SLO",
  "description": "Uptime percentage must be greater than 99.9% for the calendar month",
  "service_level_indicator_id": "string",
  "time_window_type": "calendar",
  "time_window_value": "1",
  "time_window_unit": "month",
  "target_value": "99.9",
  "target_unit": "percentage",
  "interval": 86400,
  "on_missing_interval": "exclude",
  "benchmark_operator": "ge",
  "benchmark_value": "50000"
}'
import requests

# api endpoint
url = "https://api.rated.co/v1/slos/"

# headers with authorization
headers = {
    "Content-Type": "application/json",
    "Authorization": "Bearer <YOUR-TOKEN-HERE>",
}

# data payload
data = {
    "name": "Uptime percentage SLO",
    "description": "Uptime percentage must be greater than 99.9% for the calendar month",
    "service_level_indicator_id": "string",
    "time_window_type": "calendar",
    "time_window_value": "1",
    "time_window_unit": "month",
    "target_value": "99.9",
    "target_unit": "percentage",
    "interval": 86400,
    "on_missing_interval": "exclude",
    "benchmark_operator": "ge",
    "benchmark_value": "50000",
}

# send post request
response = requests.post(url, headers=headers, json=data)

# print response
print(response.status_code)
print(response.json())

All API requests must be made over . Calls made over plain HTTP will fail. API requests without authentication will also fail.

HTTPS
generating the token via browser console