Create api token via the bash terminal


I’m trying to automate the build of our librenms server. I’m trying to set up the api token, which appears to be done via we web gui console:

I was wondering if there is a way to automate this too? E.g. maybe by running a mysql command or running a php script in my bash terminal.

You need to know the user id for the token but insert into the api_tokens table in mysql

Thanks Iaf,

I think I got it working by running the following commands, in my case the username is ‘admin’

mysql -u root -s -N --database='librenms' -e 'select user_id from users where username="admin"'

this gave the user_id, then I added my api_token, here’s an example:

mysql -u root --database='librenms' -e 'insert into api_tokens (id,user_id,token_hash,description,disabled) VALUES (1,1,"e9bab3639db475105f6eb41b969e7cc4","This token is used by the Ansible Tower",0);'

1 Like