In a recent blog post, we announced the Perl interface for Monitis API, a simple way to access our API through Perl, which is a high-level, general-purpose, interpreted, dynamic programming language.
In this post, we’ll discuss how to take care of some administrative IT tasks via the Perl library — which includes two sample scripts that allow you to create, list and delete subaccounts right from the following command line: create_subaccount.pl and delete_subaccount.pl.
Lets take a quick look at the first script:
perl eg/create_subaccount.pl --api-key=*** --secret-key=*** \
--first-name=John --last-name=Doe --email=johndoe@example.com \
--password=johndoeS3CRET --group=users
Account ‘johndoe@example.com’ was successfully created
Account ID: 12915
If you follow the above instructions, you should be able to add a subaccount. On Monitis, you can view details in your personal page under ‘Account -> Access Management -> Manage Accounts’. If you look down into the script, you can find that it was done very easily just by checking all parameters and calling: sub_accounts->add.
Here’s a practical exercise: Newly created account ‘johndoe@example.com’ is a fake one. So let’s try to delete it, since you obviously don’t need it. To delete a subaccount, you need to know its ID — or just a name (email).
You can list all existing accounts by calling the delete_subaccount.pl script without any parameters (except keys):
perl eg/delete_subaccount.pl --api-key=*** --secret-key=***
Existing accounts:
[12915] johndoe@example.com
[12697] foo@bar.com
Now we have both IDs and names of all existing subaccounts, and we could easily delete it. Here’s how:
perl eg/delete_subaccount.pl --api-key=*** --secret-key=*** johndoe@example.com
Found account ‘johndoe@example.com’: id 12915
Try to delete it…
Account 12915 successfully deleted
To delete script is a bit more complicated:
If a user passes through account’s numeric ID, script just calls sub_accounts->delete on it.
If an ID is a string, than script receives a list of all existing accounts, and tries to find id by email.
And finally if user did not pass id or email at all, script just prints list of all existing accounts and their ids.
We hope these sample scripts will make your understanding of Perl interface more clear and your life a whole lot easier.