# Building a reseller panel on the NoctHost API

> Sell servers to your own customers through the NoctHost API: a key per customer, tags, safe retries, webhooks and a console link.

Source: https://nocthost.com/docs/reseller-api

## What you get as a partner

A partner account gets 5% off NoctHost Cloud plans (at least $1 per server per month), a credit line of $300 by default so a late top-up does not stop your customers' servers, and no server limit. Ask for it on [the partners page](https://nocthost.com/partners). GET /billing shows your terms under partner, and GET /servers/nocthost/plans shows the prices your account pays.

Everything below works on any account. It is written for a panel or billing system (WHMCS or your own app) that creates servers for many end customers.

## Tag every server with its customer

Send tags when you create a server, for example customer:42 and plan:pro. Tags are lowercase letters, digits, dot, dash, underscore and colon, up to 10 per server. metadata holds up to 32 string values of your own, such as your order id. Both come back on every server object.

GET /servers?tag=customer:42 lists one customer's servers. Add limit to page through a big account: the response carries nextCursor until the last page. PATCH /servers/:id changes label, tags or metadata later.

Create a server for customer 42:

```
curl -X POST https://api.nocthost.com/servers \
  -H "Authorization: Bearer $NOCTHOST_KEY" \
  -H "Idempotency-Key: order-A-1001" \
  -H "content-type: application/json" \
  -d '{"label":"c42-web","planId":"vc2-1c-1gb","regionId":"ams","password":"<root password>","tags":["customer:42"],"metadata":{"order":"A-1001"}}'
```

## Retry without buying twice

Networks drop requests. Send an Idempotency-Key header (your order id works well) on POST /servers, POST /servers/bulk, POST /backups/:id/restore and POST /load-balancers. A repeat with the same key and body within 24 hours returns the first answer with Idempotent-Replayed: true and creates nothing. The same key with a different body returns 422.

## A key for one customer

When a customer, or a panel you run for them, needs API access, create a key in Profile, API keys with "Only servers tagged" set to their tag. That key sees and manages only servers with the tag, every server it creates gets the tag, and balance, billing, support, backups, load balancers and webhooks are closed to it. If it leaks, your other customers stay safe.

Keys are created in the dashboard only: an API key cannot create or revoke other keys.

## Hear about changes without polling

Register an https endpoint with POST /webhooks and we POST signed events to it: server.active, server.error, server.suspended, server.resumed, server.destroyed, server.ip_changed, server.traffic_cap_reached, billing.low_balance, billing.deposit_credited, billing.traffic_warning, billing.traffic_overage and abuse.case_opened. Check the X-NoctHost-Signature header with the secret you got when you registered. Events carry the server id; map it to your customer with the tags you stored.

billing.low_balance arrives 72, 24 and 6 hours before the balance runs out, in time to top up or warn your customer.

## Traffic: what is covered and how to stay in control

NoctHost Cloud traffic is one pool per account. Each server adds its included traffic for the share of the month it lives, and never less than what it used itself within its plan. So a server that uses its plan's traffic and is deleted the same day causes no overage: you pay extra only for traffic beyond the plans your servers had.

For a hard ceiling per customer, set trafficCapGb on POST /servers or PATCH /servers/:id. With trafficCapAction "throttle" (the default on NoctHost Cloud) the port drops to 10 Mbit/s until next month and the server stays reachable; "stop" powers it off. Use it when a customer must not go past a number you sold them, and raise it with one PATCH when they need more.

Take payment from your customers before you create their server, at least for the first month: hourly billing is yours, not theirs.

Bill extra traffic on to the customer who caused it: GET /billing/usage puts this month's pool overage on the servers that used the traffic.

Listen to the webhooks server.traffic_cap_reached, billing.traffic_warning and billing.traffic_overage, so you hear about it within minutes.

## Console access for your customer

POST /servers/:id/console-link returns a link to a console page that needs no NoctHost login. Send it to your customer: it works for 15 minutes and opens a fresh session each time. Anyone with the link can use the console until it expires, so send it only to the person who needs it.

## Traffic and spend

GET /billing/usage?groupBy=tag returns spend per customer tag for a period, as JSON or CSV. Extra traffic on the shared NoctHost Cloud pool is split across your servers by their share of the month's traffic, so each customer's row already includes their part. GET /billing/traffic shows this month's traffic per server and the pool, and the webhooks billing.traffic_warning (80% of the pool) and billing.traffic_overage tell you before and when extra traffic starts. Every endpoint, with scopes and examples, is in [the API reference](https://nocthost.com/docs/api).
