How to Automate Hosting with the Hetzner Agency Reseller API

Getting Started with the Hetzner Agency Reseller API

If you run a hosting business or manage multiple client projects, automation is the key to scaling profitably. Hetzner’s Agency Reseller API lets you provision servers, manage contracts, and handle billing programmatically – saving you hours of manual work.

Why Use the Hetzner Agency Reseller API?

  • Full automation: Spin up, modify, or terminate servers with a single API call.
  • Accurate billing: Retrieve usage data and generate invoices directly from Het Hetzner’s system.
  • Centralised control: Manage all client contracts from one dashboard or script.
  • Scalable pricing: Benefit from reseller discounts while keeping your margins intact.

Key Concepts You Need to Know

1. API Authentication

Hetzner uses Bearer tokens. Generate a token in the Agency Dashboard → API Settings. Store it securely – it grants full access to all reseller functions.

2. Resources Overview

The API revolves around a few core resources:

  • Projects: Logical containers for client servers.
  • Servers: The actual virtual machines or bare‑metal nodes.
  • Contracts: Billing agreements linked to a project.
  • Images & Plans: OS templates and hardware specifications.

Step‑by‑Step: Provision a New Server

  1. Create a project for the client
    POST https://api.hetzner.com/v1/projects {   "name": "Acme Corp",   "currency": "EUR" } 

    Response includes a project_id you’ll reuse.

  2. Select a server plan

    Call GET /v1/plans and pick the plan that matches the client’s budget.

  3. Choose an image

    Use GET /v1/images to list OS templates (Ubuntu, Debian, etc.).

  4. Provision the server
    POST https://api.hetzner.com/v1/servers {   "project_id": "12345",   "plan": "cx31",   "image": "ubuntu-22.04",   "location": "nbg1",   "ssh_keys": ["ssh-rsa AAA…"] } 

    The call returns a server_id and the IP address.

  5. Activate the contract

    Once the server is up, create a contract to start billing:

    POST https://api.hetzner.com/v1/contracts {   "project_id": "12345",   "server_id": "67890",   "billing_cycle": "monthly" } 

Managing Existing Resources

Updating a Server

To resize or change the OS, send a PATCH request to /v1/servers/{id}. Most changes require a reboot, which you can trigger via /v1/servers/{id}/actions/reboot.

Retrieving Billing Data

Use GET /v1/billing?project_id=12345&month=2024-04 to fetch itemised costs. Combine this with your own invoicing system or export to CSV.

Best Practices for a Reliable Integration

  • Rate limiting: Hetzner caps requests at 60 per minute. Implement exponential back‑off.
  • Idempotent design: Store request IDs and check for duplicate responses to avoid provisioning the same server twice.
  • Secure secrets: Use environment variables or a secret manager; never hard‑code the token.
  • Webhooks (optional): Subscribe to server‑status events to receive real‑time notifications instead of polling.

Frequently Asked Questions

Do I need a Hetzner Cloud account to use the Reseller API?
Yes. The reseller API is an extension of a regular Cloud account with Agency status enabled.
Can I automate DNS records for the provisioned servers?
While the Reseller API itself doesn’t manage DNS, you can call Hetzner DNS API after the server is created to add A records.
What happens if a server is terminated?
The associated contract is automatically closed and billing stops at the next cycle.
Is there a sandbox for testing?
Hetzner provides a dedicated “Test” project where you can issue API calls without affecting production resources.
How do I handle VAT for European clients?
Set the correct tax_rate on the contract creation request or let Hetzner calculate it based on the client’s country code.

Conclusion

The Hetzner Agency Reseller API empowers hosting providers to automate the entire lifecycle of a client’s infrastructure – from provisioning to billing. By following the steps above and adhering to best‑practice guidelines, you can deliver a seamless, scalable service while keeping operational overhead low.

Ready to Automate?

Start by generating your API token, set up a simple script using the examples, and watch your provisioning time shrink from hours to seconds. Need help implementing a full‑stack solution? Contact our team for a free consultation.

Comments are closed, but trackbacks and pingbacks are open.