Quick Start: Das Keyboard Q REST API
Das Keyboard Q devices RGB LEDs are very simple to program.
BACKEND_URL="https://q2.daskeyboard.com"
HEADERS=(-H "X-API-KEY: $API_KEY" -H "Content-Type: application/json")
URL="$BACKEND_URL/api/1.0/signals"
curl "${HEADERS[@]}" -X POST -d '{
"zoneId": "KEY_Q",
"color": "#FF0000",
"effect": "SET_COLOR",
"pid": "DK5QPID",
"clientName": "Shell script",
"message": "Q App version 3 is available. Download it at https://www.daskeyboard.io/get-started/download/",
"name": "New Q app version available"}' $URL
var backendUrl = 'https://q2.daskeyboard.com';
var headers = {
"Content-Type": "application/json",
"X-API-KEY": "$API_KEY"
}
// Library to make simplified HTTP client requests
// if not installed run npm install request
var request = require('request');
// Construct the signal to send
var signal = {
'zoneId': 'KEY_Q',
'color': '#FF0000',
'effect': 'SET_COLOR',
'pid': 'DK5QPID',
'clientName': 'Node script',
'message': 'Q App version 3 is available. Download it at https://www.daskeyboard.io/get-started/download/',
'name': 'New Q app version available'
};
// HTTP POST request to the cloud
request.post({
url: backendUrl + '/api/1.0/signals',
headers: headers,
body: signal,
json: true
}, function (error, response) {
// OK
if (response && response.statusCode == 200) {
console.log('response', response.body);
}
// OK from API response
if(response && response.statusCode != 200){
console.error(response.body);
}
// OK
if (error) {
console.error(error);
}
});
backendUrl = 'https://q2.daskeyboard.com'
headers = { "Content-type": "application/json","X-API-KEY": "uS3qbfUi5sFNq2GU1j7EaAQkgdft0Zwg"}
import json
# sudo pip install request
import requests
# Construct the signal to send
signal = {
'zoneId': 'KEY_Q',
'color': '#FF0000',
'effect': 'SET_COLOR',
'pid': 'DK5QPID',
'clientName': 'Python script',
'message': 'Q App version 3 is available. Download it at https://www.daskeyboard.io/get-started/download/',
'name': 'New Q app version available'
}
signal_json = json.dumps(signal)
# sending the signal
res_signal = requests.post(backendUrl + '/api/1.0/signals', data=signal_json, headers=headers)
# checking the response
if res_signal.ok:
print "OK"
print res_signal.text
else:
print "Error: " + res_signal.text
BACKEND_URL="http://localhost:27301"
HEADERS=(-H "Content-Type: application/json")
URL="$BACKEND_URL/api/1.0/signals"
curl "${HEADERS[@]}" -X POST -d '{
"zoneId": "KEY_Q",
"color": "#FF0000",
"effect": "SET_COLOR",
"pid": "DK5QPID",
"clientName": "Shell script",
"message": "Q App version 3 is available. Download it at https://www.daskeyboard.io/get-started/download/",
"name": "New Q app version available"}' $URL
var backendUrl = 'http://localhost:27301';
var headers = {
"Content-Type": "application/json"
}
// Library to make simplified HTTP client requests
// if not installed run npm install request
var request = require('request');
// Construct the signal to send
var signal = {
'zoneId': 'KEY_Q',
'color': '#FF0000',
'effect': 'SET_COLOR',
'pid': 'DK5QPID',
'clientName': 'Node script',
'message': 'Q App version 3 is available. Download it at https://www.daskeyboard.io/get-started/download/',
'name': 'New Q app version available'
};
// HTTP POST request to the cloud
request.post({
url: backendUrl + '/api/1.0/signals',
headers: headers,
body: signal,
json: true
}, function (error, response) {
// OK
if (response && response.statusCode == 200) {
console.log('response', response.body);
}
// OK from API response
if(response && response.statusCode != 200){
console.error(response.body);
}
// OK
if (error) {
console.error(error);
}
});
backendUrl = 'http://localhost:27301'
headers = { "Content-type": "application/json"}
import json
# sudo pip install request
import requests
# Construct the signal to send
signal = {
'zoneId': 'KEY_Q',
'color': '#FF0000',
'effect': 'SET_COLOR',
'pid': 'DK5QPID',
'clientName': 'Python script',
'message': 'Q App version 3 is available. Download it at https://www.daskeyboard.io/get-started/download/',
'name': 'New Q app version available'
}
signal_json = json.dumps(signal)
# sending the signal
res_signal = requests.post(backendUrl + '/api/1.0/signals', data=signal_json, headers=headers)
# checking the response
if res_signal.ok:
print "OK"
print res_signal.text
else:
print "Error: " + res_signal.text
NOTE: Examples uses Linux-style shell
command line. It is also available on Windows:
-
shell
command line is available when installing Linux Subsystem for Windows 10: https://docs.microsoft.com/en-us/windows/wsl/install-win10. -
or when using
git bash
which is available here: https://gitforwindows.org/.
Key Q concepts: How it works
In order to control the RGB LEDs of a Q device, a user must send authenticated HTTP JSON requests to a Q REST API.
Q cloud services https://q2.daskeyboard.com/ provides a REST API that talks to Q devices. Alternatively, one can also write a script that directly interacts with a Q device via your workstation (i.e.: http://localhost:/#port…).
Therefore there are two ways to send a signal to a Q device:
- From the Q cloud:
Your script on any computer --> Q clould service --> Q desktop app on your computer --> Q enabled device
- Directly from your machine:
Your script on your computer --> Q desktop app on your computer --> Q enabled device
The example in this document uses the Q cloud service.
Getting a Q cloud API key
Since Q cloud service requires authenticated requests, you need to get an API key.
To get it, first signup for an account at https://q2.daskeyboard.com then find
your API key
here: https://q2.daskeyboard.com/signup/edit
Next steps
As seen in this simple example, once authenticated, it is very easy to send a signal to a Q device. Ready to program your dashboard keyboard? Head over to the full API documentation: Q cloud documentation