11 Oct 2026

Python Example: Order Hosting and Domains Through a Reseller API

← All posts

Python Example: Order Hosting and Domains Through a Reseller API

Python is a great fit for automation scripts and back-office tools. This example uses the requests library with the SyllHost Reseller API.

Setup

pip install requests
export SYLL_KEY=sh_live_xxx

A reusable session

import os, requests
BASE = "https://syllhost.com/api/v1"
s = requests.Session()
s.headers["Authorization"] = "Bearer " + os.environ["SYLL_KEY"]
def call(method, path, idem=None, **kw):
    headers = {"Idempotency-Key": idem} if idem else {}
    r = s.request(method, BASE + path, headers=headers, timeout=60, **kw)
    data = r.json()
    if r.status_code >= 400:
        err = data.get("error", {})
        raise RuntimeError(f"{r.status_code} {err.get('code')}: {err.get('message')}")
    return data["data"]

Check balance, then a domain

acct = call("GET", "/account")
print("Can spend:", acct["available_to_spend"])
d = call("GET", "/domains/check", params={"domain": "acme-traders.com"})
if d["available"]:
    print("Register price:", d["register_price"])

Order hosting with a safe retry

import time
def place_order(payload, key, tries=3):
    for i in range(tries):
        try:
            return call("POST", "/orders/hosting", idem=key, json=payload)
        except requests.exceptions.RequestException:
            time.sleep(2 ** i)   # network trouble: retry with the SAME key
    raise RuntimeError("Giving up")
order = place_order({"product_id": 3, "cycle": "monthly",
                     "domain": "acme-traders.com", "reference": "CUST-77"}, "order-1001")
print(order["order_number"], order["service"]["status"])

Why the same key matters

If a timeout hides the real result, retrying with the same Idempotency-Key returns the original order instead of creating a second one. Read idempotency keys explained.

Next steps

  • Poll /services/{id} until the status is active.
  • Store order numbers against your own customer records.
  • Add rate-limit handling. See rate limiting explained.

Adding polling for pending services

def wait_active(service_id, timeout=300):
    end = time.time() + timeout
    while time.time() 

Reading your invoices

Use GET /invoices?status=unpaid to find renewals waiting and POST /invoices/{id}/pay to settle them from your balance. Paying twice is safe. A nightly script that lists unpaid invoices and compares them to your balance is a simple but effective safeguard.

Testing safely

There is no test mode, so use real but cheap items first: check a domain (free), list products (free), and place a single low-cost order while watching your balance. Add unit tests for your own code by mocking the HTTP layer.

FAQ

Which Python version do I need?

Any currently supported Python 3 version works.

Where do I find product ids?

Call GET /products. Each plan lists its id, type, resources and prices.


Build with our API: read the Reseller API reference and the step-by-step guide. API access is enabled per account, so contact us to request it.

Related posts

How to Find Out Who Owns a Domain Name (WHOIS Lookup Guide)

How to Start Using SyllHost: Step-by-Step Beginner Guide (2026)

How to Check a Domain's Expiry Date (3 Easy Ways)

Contact us