This is a simple Python Flask server which implements a small api to allow users to store key-value pairs. It was created to store persistent states because IFTTT does not really allow you to do that.
- Download wheel file from releases tab
- Create a new folder, enter it and execute
python -m venv .
- Activate virtual enviorment with
. bin/activate
- Install wheel file with pip:
pip install releasefile.whl
- Make sure a
var
folder exists in virtualenv, if not create it by runingmkdir var
- Initialize database by running
export FLASK_APP='iotpersistenceapi'
and thenflask init-db
and set a admin password
The server looks for the existence of an config.json
file in the flask instence folder and then loads it (the instance folder should be located in the var folder).
Example config.json:
{
"SECREY_KEY": "YOURSECREYKEY"
}
You should set a SECREY_KEY
in this config for security reasons, to do this just generate a random string with python -c 'import secrets; print(secrets.token_hex())'
and set it in the config file.
Project can now be run with flask run
. For production you should probably choose a cgi server like fastcgi (further infos).
The api uses standard HTTP-Authentification using a username and a password. The user and it's password have to be created by the admin using the admin interface.
/iotpersistenceapi/set?key=SOMEKEY&value=SOMEVALUE
Returns 200 status code on success and 400 on failure.
/iotpersistenceapi/get?key=SOMEKEY
The value will be returned directly in plain text (not json).
Returns 200 status code on success, 404 on unknown key and 400 on other failures.
/iotpersistenceapi/del?key=SOMEKEY
Returns 200 status code on success, 404 on unknown key and 400 on other failures.
/iotpersistenceapi/list
Returns key-value pairs in JSON format.
/iotpersistenceapi/admin
Can be done using the admin interface
HTTP Authentification in IFTTT Webhooks can be achieved with the following synthax: https://username:password@website.com