Registering a domain through the API and paying from your credit

API & DocumentationWhat You Can Automate·· 2 views· 4 min read

In short: your system checks the name, registers it with POST /v1/domains/register and follows the action until it finishes. The registration is paid on the spot from your account credit, at your Agence discount, and leaves no unpaid invoices. If credit runs short, the price changes or your profile is incomplete, nothing is charged. The domain reseller page shows the whole flow.

The right key for buying

Create the key on the API page in My MozOut with domains:read, domains:write and billing:purchase. Add billing:read if you want your program to see the credit before it buys. billing:purchase is a sensitive permission, off by default, and every purchase counts towards the key's spending limit. The step-by-step guide is in creating an API key.

Start with a sandbox_ key. Name checks are real and registration is simulated: the response looks just like Production, with credit_sufficient and within_spending_limit telling you whether the purchase would go through, but nothing is registered or charged. When you are ready, just swap the key.

From a name to a live domain

1 Check the name. GET /v1/domains/availability?domain=... says whether it is free and gives the price for 1 to 10 years, in prices. If the status is unknown, it could not be confirmed right now and registration through the API will not go ahead.
2 Check your credit with GET /v1/billing/credit. If it is not enough, the purchase answers 402 and nothing is charged.
3 Register. POST /v1/domains/register takes the domain, the years (1 to 10; without it, 1 year) and, if you like, nameservers (2 to 5). Without nameservers, the domain gets ours. The transfer lock is switched on unless you send "locked": false.
4 Always send the Idempotency-Key header, built from your client's order number. If the connection drops, repeat with the same value and the domain is not bought twice.
5 Follow the action. The answer is 202 with an action_id. GET /v1/actions/{id} shows queued, running and finally done or failed. For a .co.mz it reaches done in seconds.

A .co.mz for 2 years, with your client's nameservers:

curl https://api.mozout.com/v1/domains/register -X POST \
-H "Authorization: Bearer $MOZOUT_API_KEY" \
-H "Content-Type: application/json" \
-H "Idempotency-Key: order-2051-domain" \
-d '{"domain": "yourcompany.com", "years": 2, "nameservers": ["ns1.yourcompany.com", "ns2.yourcompany.com"]}'

The response includes amount and currency: what came out of your credit, with your discount applied. Keep it with the client's order.

The answers you may get

Answer When What to do
402 insufficient_credit Not enough credit. Nothing was charged. Top up and ask again.
403 spending_limit_exceeded The purchase goes over the key's spending limit. Nothing was charged. Use a key with a higher limit.
422 with portal_url The case is handled in My MozOut: .ac.mz, .gov.mz, .mil.mz, .mz and .ao names up to 3 characters, extensions that need extra registrant details. Follow the link and register in My MozOut.
422 period_not_available The extension has no price for that number of years. Nothing was charged. Ask for a different number of years.
409 account_email_domain You sent nameservers for the domain of your account e-mail, or of one of its users. Register without nameservers and change them in My MozOut.

You can add a promo_code to the request. If it gives no discount on that purchase, the answer is 422 promo_not_applicable and nothing is charged. The other codes are in our API's error codes.

Know straight away when it ends. Instead of asking about the action over and over, save a webhook with the domain.registered and domain.registration_failed events. When it fails, refund.automatic says whether the amount goes back to your credit. See long-running API operations for the rest.

Ready to plug in your system? Start with a Sandbox key, and see on the domain reseller page what registers on the spot.

See the domain reseller page

SEE ALSO

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

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

Long-running API operations: the 202 answer, the action_id and following the result

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

Sensitive API permissions and the spending limit: paying, buying, reinstalling, cPanel access

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

RECOMMENDED PRODUCT

Register your .com domain

Secure your company name before someone else registers it. from $17.00/yr

Search a domain
Was this answer helpful? Your answer helps us improve this article.