Opening a hosting account through the API: catalog, purchase from credit and following the new service

API & DocumentationWhat You Can Automate·· 14 views· 5 min read

The short answer: your system picks the plan from the catalog, buys it with POST /v1/services/purchase, pays from credit and gets the service number back. The account opens just as with a purchase in Meu Interweb. If you are in the Reseller Program, the catalog and the purchase already carry your Agence price. Test it all first with a Sandbox key, which charges nothing. There is a summary on the hosting for resellers page.

The key you need

Permission What for
catalog:read Seeing the plans, cycles, options and prices.
billing:read Checking your credit before you buy.
billing:purchase Buying from credit. It is a sensitive permission and comes switched off: turn it on by hand.
hosting:write Write access for the area. Buying hosting or reseller hosting needs it as well as the purchase permission.
hosting:read Following the new service after the purchase.

Keys are created on the API page in Meu Interweb. Give this key a spending limit that matches what you buy: it is the most it can spend in 30 days. The step-by-step guide is in creating an API key.

Step by step

1 Pick the plan. GET /v1/catalog/products lists what is on sale, with the price of each cycle. kind says what the product is and purchasable whether it can be bought through the API. With a discount, price is your price, list_price the public one and discount the percentage.
2 Look at the options. GET /v1/catalog/products/{id} shows the cycles with a price and the options to choose, such as the panel (cPanel or Plesk), with the price of each choice. Options you do not send take the first choice, as in Meu Interweb.
3 Have the domain in your account. For the hosting to open with your client's domain, the domain has to be in your account. You can register it first, through the API too: see domains through the API. Without a domain, the account starts on a temporary address that you can change later.
4 Check your credit with GET /v1/billing/credit. The purchase is paid from credit only.
5 Buy with POST /v1/services/purchase: product_id, billing_cycle and, if you like, domain and config_options. The Idempotency-Key header is required: build it from your client's order number, and a dropped connection will not buy the plan twice.
6 Follow the service. The answer includes service_id, invoice_id, amount and manage_url. Follow the service with GET /v1/services/{id}. Until it is ready, domain and username may come back as null.
7 Hand over access. The API never returns passwords. The access details are in Meu Interweb, at the manage_url address.

The purchase, with the client's domain (38 is just an example: the right product_id comes from your account's catalog):

curl https://api.interweb.co.mz/v1/services/purchase -X POST \
-H "Authorization: Bearer $INTERWEB_API_KEY" \
-H "Content-Type: application/json" \
-H "Idempotency-Key: order-1042-hosting" \
-d '{"product_id": 38, "billing_cycle": "annually", "domain": "asuaempresa.co.mz"}'

For Plesk, add config_options as {"option id": choice id}, using the numbers that GET /v1/catalog/products/{id} shows for the panel option.

No need to keep asking. If you save an address with PUT /v1/webhooks (permission webhooks:write), the service.created event tells you when the service has been created on the server, with service_id, name and domain.

The price is your account's price

The API charges the same as the cart and the invoice. If the invoice does not match that price, the purchase is undone and nothing is charged. amount includes tax; subtotal and tax show the two parts. With a sandbox_ key nothing is created and nothing is charged.

The answers you will come across

Answer When What to do
402 insufficient_credit Your credit is not enough. Nothing was charged. Top up and repeat with the same Idempotency-Key.
403 spending_limit_exceeded The purchase goes over the key's spending limit. Nothing was charged. Use a key with a higher limit, or wait for the period to reset.
403 insufficient_scope The key is missing a permission. Check the table above.
409 profile_incomplete The account profile is not complete. Complete it in Meu Interweb.
409 domain_not_owned The domain is not in this account. Register or transfer it into the account, or buy without a domain.
422 incompatible_options Plesk with WordPress, or Windows with a cPanel licence. Choose cPanel for WordPress.
429 You went over a limit. Purchases allow 5 per minute. Wait the seconds in Retry-After.
After the purchase, the management. The management operations (databases, SSL, PHP, FTP, cron and the rest) only run on an active hosting account, on a supported server: today, cPanel. On a Plesk account they answer 409 with server_not_supported. See hosting through the API.

Want to open hosting accounts from your own system? Start with a Sandbox key and your Agence discount.

See hosting for resellers

SEE ALSO

Hosting through the API: subdomains, databases, cron jobs, SSL, PHP options and FTP

Creating an API key: name, mode, permissions, validity, IP list and spending limit

Idempotency-Key in our API: repeating a purchase, payment or ticket without doing it twice

API Sandbox or Production: what each key really does, and moving your program to production

Domains through the API: checking a name, registering, renewing and transferring with credit

Resellers and agencies: a new client's domain, DNS and mailboxes through the API, step by step

Hosting in the Reseller Program

RECOMMENDED PRODUCT

Web hosting with cPanel

Domain and SSL included, daily backups and the panel you already know. from $5.36/mo (3-year plan, with coupon)

See plans
Was this answer helpful? Your answer helps us improve this article.