User API
Overview
HostBill User API plugin enables HTTP REST API for your customers to manage their accounts from their apps/systems.  Additionally API is self-documenting so your users will have nice, comprehensive documentation of all methods that your API offers.
Â
Activating the module
- If the plugin is included in your HostBill edition you can download it from your client portal.
- If the plugin is not included in your HostBill edition you can purchase it from our marketplace and then download it from the client area.
- Once you download the plugin extract it in the main HostBill directory.
- Go to Settings → Modules, find and activate User API plugin.
Module configuration
- Proceed to Extras → User API where you can:
- Enable/disable logging. Enable only for debug/testing purposes
- Set Rate limit - Number of requests users can make in a period of time, when exceeded new requests will be discarded.
- Select available Authentication methods:
- Basic HTTP Auth -Â This option enables client to use basic authentication. It requires client login credentials in every api request.
- JSON Web Token Auth -Â Allows clients to authenticate requests with generated token. Client will need to pass their credentials to /login route to generate required token.
Path to JSON Web Token key - used with JSON Web token auth.
Path to RSAÂ private key file, relative to hostbill installation directory or an absolute path.Generating private key in linuxssh-keygen -t rsa -b 4096 -m PEM -f private.key -q -N ""
- It is important to set URL rewrites for API to function, depending on your web-server software
- Apache users
in /api folder rename file template.htaccess to .htaccess Nginx (including HostBill enterprise) users .
If you are using SEO URL rewrites described here, modify block "@seohburl" in /etc/nginx/locations/hostbill.conf to look like:location @seohburl { rewrite ^/api/(.+)$ /api/index.php?/$1 last; rewrite ^/(.+)$ /index.php?/$1 last; }
If you are not using SEO urls, edit your location file (in server section, for HostBill enterprise it is /etc/nginx/locations/hostbill.conf, addÂlocation @userapi { rewrite ^/api/(.+)$ /api/index.php?/$1 last; }
Next, to main location add try files line:
try_files $uri $uri/ @userapi;
- Apache users
Now, restart your webserver.
Configuring routes
You can configure routes (API functions) in Adminarea → Extras → User API
Using this section, you can:
- Add route alias - this creates copy of the route, so you can rename it. For example if you wish to change route from /service to /cloud - create alias for first one.
- Edit - by editing route you can:
- Enable/Disable it - you can limit to which functions your customers will have access to (ie if you use IPAM plugin only for admin purposes, you can disable IPAM api functions for clients)
Change route name - change how route appears in documentation
Change route category - change category where route appears in documentation
Change route description - enter your custom description of route to be shown in documentation
User API Log
User API module allows you to log queries. Logging is optional and can be activated from the module configuration.
After activation, a new User API Log section will be available on the module page. In this section, you can see the date, method, route, in/out data, the IP address and the user who sent the query.
FAQ
Question: Can we customize client area templates, edit introduction text or add company logo?
Answer: Yes, but you will need to edit template files used by this module, located in: ./includes/modules/Other/userapi/user/
Question:Â I'm missing route/function XYZ, do you plan to add it?
Answer: Yes! Just let us know what is missing for you and we're happy to improve this plugin for you.
Question: I'm using Apache + PHP-FPM - I'm always getting wronglogin error, even with right credentials.
Answer:Â Your apache is not passing Authorization header to php-fpm. To do that, add to your .htaccess or vhost config file:
SetEnvIf Authorization "(.*)" HTTP_AUTHORIZATION=$1