API Link - Setup guide

Started by SasaKaranovic, Mar 10, 2024, 08:45 PM

Previous topic - Next topic

SasaKaranovic

You can install API Link using the download link or run it from source.

Once running you can open http://localhost:5341 to access API Link dashboard.

Here you can add, edit or remove API Links as well as activate/deactivate links and more.

We are aware that right now adding links is not the most user friendly experience because you have to enter raw text to define your link.
Alternatively you can copy-paste the link file into your API Link
We will work on adding a more user-friendly way of creating API Links.

SasaKaranovic

#1
How does API Link file work?

API Link file is stored/created as a TOML file.

Each API Link file must have the following sections:
  • info
    • name -> Name of your link file
    • description -> Brief description for this link
  • api
    • url -> API URL to call when fetching data
    • item -> JSON item from the API response
    • update_period -> How often to make the API call (in seconds)
  • dial
    • uid -> UID of the VU dial on which you want to display API information
    • host -> VU Server host (if not sure, use localhost)
    • port -> VU Server port (if not sure, use 5340
    • api_key -> API key *igned to this API link (if not sure, use cTpAWYuRpA2zx75Yh961Cg

SasaKaranovic

#2
Example API Link file

Comments are optional, they are added to explain how that particular line is interpreted by the API Link

[info]
name = "Bitcoin price change tracker"
file = "requests_bitcoin_hourly_price_change.toml"
image = "bitcoin_5.png" # Image to use as dial background/face-plate
description = "Retrive Bitcoin price change in the last 1hr (in percent)"
driver = "requests" # Right now we only have 'requests' driver
enabled = true # Automatically created by API Link

[api]
url = "https://api.coinlore.net/api/ticker/?id=90"
item = "response[0]['percent_change_1h']"
update_period = 600 # How often, in seconds to fetch API data
headers = [] # Optionally we can send headers like API Key
value_modifiers = [ # These are functions through which API value will run before it's sent to the VU dial
    { function = "scale_number", min=-10, max=10 }, # Scale API value so that value of -10 is 0% and value of 10 is 100% on the dial.
]

[dial]
uid = "490075000650564139323920"
host = "localhost"
port = 5340
api_key = "cTpAWYuRpA2zx75Yh961Cg"

[backlight_map] # We can create mapping for dial backlight color
0 = [0, 0, 0]  # When dial value is 0, set RGB to 0,0,0 which equals OFF
46 = [20, 0, 0] # When dial value is 1-46, set RGB to 20,0,0 which is Red at 20% brightness
47 = [2, 0, 0]  # When dial value is 46, set RGB to 2,0,0 which is Red at 2% brightness
48 = [10, 10, 10] # When dial value is 48-51 set RGB to 10,10,10 which is White at 10% brightness
52 = [0, 10, 0] # When dial value is 52-54 set RGB to 0,10,0 which is Green at 10% brightness
55 = [0, 20, 0] # When dial value is 55-100 set RGB to 0,20,0 which is Green at 20% brightness