📜 ⬆️ ⬇️

Opening API for working with services from Russian low-cost host (part 1)

After a long pause, we gathered our thoughts and decided to prepare a small cycle of articles that would be useful both for developers and our regular customers, who would need to order more than one service at a time.



Prerequisites for this publication appeared a long time ago. One of the clients with a large number of virtual servers inquired about whether it is possible to work with our billing API. At that time, to be honest, we were not ready for such a dialogue and could not offer a ready-made solution.
From the beginning of the summer, we received several more such questions and realized that we could not leave them unanswered. And today I will tell you how to work with our company's billing API to order virtual servers of any quantity.

')
As a billing system, we use the product of the Russian company ISPsystem - BILLmanager4. For all ISP products, there is an open API and it is described to a greater or lesser extent on their official documentation site ispdoc.com
You can work with the API either from the command line, directly accessing the mgrctl interpreter, or via the browser address bar (or any other application that will send a request to the web server: curl, wget, etc.)
Based on the documentation, you can make a request to any of the products, BUT, when working with billing, a certain amount of information is required, which is available only from the hosting provider.

The request itself for ordering a virtual server, for example, KVM Ferrum for one month with automatic monthly renewal, using the Centos-6.7-x86_64-minimal OS template without using the ISPmanager license, will look like this:

https://billing.ihor.ru/billmgr?authinfo=<USER>:<PASS>&addon_1101=20&addon_1103=1&addon_1104=1&addon_1110=1&addon_1791=4&enum_1112=21&enum_1106=25&agree=on&domain=test-for.habr&ostempl= Centos-6.7-x86_64-minimal&period=1210&price=1100&autoprolong=1210&payfrom=neworder&func=vds.order.7&sok=ok 


Now we will try to decipher all this jumble of variables and numbers.
The request itself can be divided conditionally into two parts: these are the billing URL and the request billing parameters passed.
The parameters themselves can be distributed as follows:

Description of parameters



The login and password of the user registered in the billing is specified as the authorization data.


Each tariff plan has its own identifier in the billing, taken from the table "Tariff Plans".


The parameters of the tariff plan include the parameters of the virtual server, its resources. Each parameter of the tariff plan has its own identifier and its default value, which corresponds to the size of the disk, the number of processor cores and RAM, as well as IPv6 and IPv4 addresses.


Additional services include DNS servers and the use of an ISPmananger license.


(default settings for KVM Ferrum)


The identifier of the order period and auto-renewal for each of the services are absolutely the same.


Domain name must be unique. Otherwise, an error will occur.
Error: The domain is already in use. Specify a different domain name.
When mass adding virtual servers, I recommend using the format + <sequence number>.


An incomplete list of templates is provided in this text just below. Please note that when ordering an OS template without ISPmanager, the setting of the value of the additional services should be disabled using the ISPmanager control panel (for all tariff plans this identifier is the same - 25)


In the example, I gave the value of the payment parameter - neworder, which corresponds to a separate order with payment for each server. payfrom = neworder .


Since the entire order of the virtual server consists of 7 steps, the API, which is not particularly obvious at first glance, should indicate not only the vds.order function itself, but also the number of the last step - 7. Thus, the full value of this item looks like this: func = vds.order.7


When ordering any of the services, we offer to familiarize with the user agreement and accept it (then the order goes for activation) or not accept it (then the order is canceled). In the API, this item is also required: agree = on .


Part of the parameters is fixed and I gave their values ​​in the description, and the values ​​of others can be taken from the table, which is entirely shown on the website page with reference information on working with hosting .

In order not to clutter the text with large tables with all tariff plans, I will give only the part that will help you figure out how the line was drawn up for ordering a virtual server with the KVM Ferrum tariff plan. As well as two other junior tariff plans SSD and OVZ

Tariff Plans


priceperiod / autoprolong
RateID1 month3 months6 months1 year
KVM Ferrum11001210121312141211
SSD Ferrum10331180118311841181
Ovz ferrum20611758176117621759


Tariff parameters


addon_enum_
Tariff / ValueDiskRamCPUIPv4IPv6NSISPmgr
KVM Ferrum1101
/ 20
1103
/ one
1104
/ one
1110
/ one
1791
/ four
1112
/ 21
1106
/ (1/25)
SSD Ferrum1034
/ 20
1037
/ one
1043
/ one
1036
/ one
1404
/ four
1045
/ 21
1039
/ (1/25)
Ovz ferrum2062
/ 20
2065
/ one
2071
/ one
2064
/ one
2074
/ four
2073
/ 21
2067
/ (1/25)

Template List



If the request is correct and the application for activation of the new service is accepted, you will receive in response something like this:

 <script language='JavaScript'>fr_master('startpage=vds', 'top.');</script> 


Below, as a bonus, I attach several scripts to order an arbitrary number of virtual servers for the Linux and Windows console.
If the comments show interest in the development of the topic of working with our billing API, we will try to describe it in more detail using various programming languages ​​and software products for integration.

BASH example
 #/bin/bash # #    USER=user PASS=password #  10   for i in {1..10} do /usr/bin/curl https://billing.ihor.ru/billmgr?authinfo=$USER:$PASS&addon_1101=20&addon_1103=1&addon_1104=1&addon_1110=1&addon_1791=4&enum_1112=21&enum_1106=25&agree=on&domain=$USER-$i.ru&ostempl= Centos-6.7-x86_64-minimal&period=1210&price=1100&autoprolong=1210&payfrom=neworder&func=vds.order.7&sok=ok" done 


Unfortunately, it was not possible to come up with any decent option, except for how to duplicate the previous cycle using curl, assembled to work in Windows. But if from among the readers there are experienced in scripting / programming under Windows, then please share more rational scripts in the comments.

An example on PowerShell, the curl.exe file must be located in the same directory where the script is running from

 USER=user PASS=password for ($i=1; $i -lt 10; $i++) { .\curl.exe https://billing.ihor.ru/billmgr?authinfo=$USER:$PASS&addon_1101=20&addon_1103=1&addon_1104=1&addon_1110=1&addon_1791=4&enum_1112=21&enum_1106=25&agree=on&domain=$USER-$i.ru&ostempl= Centos-6.7-x86_64-minimal&period=1210&price=1100&autoprolong=1210&payfrom=neworder&func=vds.order.7&sok=ok" } 

Source: https://habr.com/ru/post/305716/


All Articles