Skip to content

API & WHMCS ​

If you bill your customers in WHMCS, the IPTV OS module for WHMCS lets WHMCS do the work in the panel: when a customer orders, WHMCS creates the line; when an invoice stays unpaid, it suspends the line; when an invoice is paid, it renews the line; when a service is cancelled, it deletes the line. Your customers find their login, playlist links and a QR code in the WHMCS client area.

Behind this is the Reseller API v1, a fixed interface of the panel under /api/v1. The module uses it, and your own programs can use it too.

The running example: you are the reseller kanalwerk-ost and bill your customers in WHMCS at billing.example.com. Your WHMCS server has the address 203.0.113.10. You want to sell a product "IPTV Premium" with monthly and yearly billing in WHMCS. At the end, your storefront sends buyers to the WHMCS cart instead of the panel's checkout.


1. The terms in one sentence ​

TermWhat it is
Reseller API v1The fixed interface for billing systems under /api/v1. It does not change; anything incompatible comes as a new version.
API keyThe key WHMCS signs in with (ipk_…). It acts as your account, with your lines and your credits.
ScopeWhat a key may do, e.g. lines:write = create, change, renew and delete lines.
WHMCS / provisioningThe preset for a billing system: lines, packages and credit balance, nothing else.
Allowed IP addressesThe addresses a key may be used from. Calls from anywhere else are refused.
WHMCS moduleThe provisioning module iptvos for WHMCS 8. It turns WHMCS actions into API calls.
Idempotency-KeyA name for each write call. If WHMCS repeats a call, the panel answers the first result again and charges nothing a second time.
external_refThe WHMCS service id, stored on the line. It lets WHMCS find its line again.
External shopA storefront mode in which the plans link to your WHMCS cart instead of the checkout.

The short version:

Create a key with the preset WHMCS / provisioning and limit it to your WHMCS server's IP. Enter the panel and the key as a server in WHMCS, choose a package per product, done. Keep enough credits; WHMCS orders fail when they run out.


2. Before you start ​

  • WHMCS 8.x on PHP 8.1 or newer with cURL.
  • The module as a zip, iptvos-whmcs-<version>.zip. Your panel offers the matching version on My Account › API keys under WHMCS module (step 2). If the panel's API is newer than the module, the service tab in WHMCS shows a note (section 7).
  • The API must be allowed for your account. For the team it always is. For resellers, two switches decide (section 9): the operator's setting "Resellers may use the API" and the switch API allowed on the account and on every account above it. If one is off, API keys shows: "The API is switched off for your account, so your keys do not work. Ask the account above you or the panel team."
  • Packages you may sell. WHMCS shows the panel's packages in a list; a reseller sees the enabled ones only.
  • Credits for a reseller account without an unlimited plan: every line WHMCS creates or renews costs the package's credits, as in the panel (section 5).

3. The example: connect WHMCS in five steps ​

Step 1 – Create the API key ​

  1. Open My Account and go to the card API keys. "For your shop, billing system (e.g. WHMCS) or scripts. A key never has more rights than your account."
  2. Click New API key.
  3. Name: WHMCS. "Where the key is used, so you can recognise it later."
  4. Under What the key may do choose WHMCS / provisioning: "For a billing system: create, change, renew and delete lines, read packages and the credit balance. No sub-accounts, credit transfers or webhooks."
  5. Under Allowed IP addresses enter your WHMCS server: 203.0.113.10. "One IP or CIDR range per line, e.g. your WHMCS server. Empty = any address. Calls from other addresses are refused and logged in the audit log."
  6. Create and copy the key: "Copy the key now – it is shown only once. Treat it like a password."

In the list, the key now has the badges WHMCS / provisioning and IP limited (1). You can change the scopes and the addresses later with the pencil (Edit key). The key itself stays the same. More about the presets in Team & account.

Tip: The IP allow-list is the cheapest protection there is. If the key ever leaks, it is useless from any other address. If your WHMCS server gets a new address, change the list first, otherwise every order fails with "This API key may not be used from {ip}."

Step 2 – Install the module ​

On the API keys card, the section WHMCS module says: "Already bill in WHMCS? Unpack this zip into the WHMCS folder and add the panel as a server, with a key of the “WHMCS / provisioning” preset. WHMCS then creates, suspends, renews and deletes your lines by itself. This version is made for this panel." Click Download. Next to the button are the file name, the version, the size and the SHA-256 checksum (click it to copy). Without a module the section says: "This panel build has no WHMCS module. It comes with every release."

Unpack iptvos-whmcs-<version>.zip into your WHMCS folder. The zip only holds the folder modules/servers/iptvos/, so nothing else in WHMCS is touched. To update, download the module again after a panel update and unpack it over the old one.

Step 3 – Add the panel as a server in WHMCS ​

In WHMCS: System Settings › Servers › Add New Server.

Field in WHMCSWhat you enter
ModuleIPTV OS
HostnameThe panel's address, e.g. panel.example.com. With a scheme, port or path, such as https://panel.example.com:8443, it works too.
Access HashThe API key from step 1. Alternatively in Password.
UsernameOptional: the panel's access code, the part after the domain in the panel's address (https://panel.example.com/x7k2/ → x7k2). Only used for the Open in panel button.
SecureOn (https).

Test Connection asks the panel who the key is and checks that it may read and write lines and read packages. If a scope is missing, WHMCS says: "The API key lacks the scopes … Create a key with the "WHMCS / provisioning" preset in the panel (Account › API keys)." If the panel is older than the module, Test Connection fails with "The panel speaks API v…, this module needs v… Update the panel, or use the module the panel offers (Account › API keys › WHMCS module)." The module is in English.

Put the server into a server group, as usual in WHMCS.

Step 4 – Create the product ​

  1. In WHMCS create a product of type Other, e.g. "IPTV Premium".
  2. On the Module Settings tab choose the module IPTV OS and your server group.
  3. WHMCS now loads the panel's packages and shows each one as e.g. "Premium – 30 days, 2 connections, 10 credits".
SettingWhat it does
PackageThe package of a new line and of every renewal. Required.
Package (monthly), (quarterly), (semi-annually), (annually)Optional: one product sells every duration. A service billed yearly gets the package under Package (annually). Empty ("— as "Package" —") = Package.
Line typeLine (M3U / Xtream) or MAG box.
UsernameThe service's WHMCS username, Random or The client's e-mail prefix. If that prefix is taken, the line gets prefix.<service id>.
Trial product"A trial package: the line is not renewed."

In the example, Package is your 30-day package, Package (annually) your 365-day package. Then set the prices for monthly and annual billing in WHMCS as usual.

For a MAG box, add a configurable option or a custom field named exactly MAC address to the product. The module reads the box's MAC from it. Without a MAC, creating fails: "A MAG line needs the box's MAC address (configurable option or custom field "MAC address")."

The panel accepts usernames of letters, digits and _ . @ - (up to 64 characters), and passwords of 4 to 72 characters without / ? # & or spaces. If the password WHMCS generated contains one of those, the module makes a new one and saves it in WHMCS before it calls the panel.

Step 5 – A test order ​

Order the product in WHMCS for a test client and accept the order (or run Create in the service). In the panel, Lines now shows the new line. In the audit log it appears under your name with "(API: WHMCS)", and in your Credit history the package's credits are booked.

The service in WHMCS holds the panel's line id in the field Line ID; the username and the password are filled in.


4. What WHMCS does in the panel ​

In WHMCSIn the panelGood to know
CreateCreates the line with the product's package.The WHMCS service id is stored on the line as external_ref.
SuspendSuspends the line (it stops playing).Free; the expiry stays.
UnsuspendSwitches the line back on.Free; the expiry stays. A banned line stays banned (line_banned).
TerminateDeletes the line.Credits come back only inside the refund window (section 5). A line already deleted in the panel counts as done.
RenewAdds the package's days to the expiry.The package of the service's billing cycle. One renewal per paid invoice (section 6). Refused for a trial product.
Change Package (upgrade/downgrade)Moves the line to the new product's package.The expiry stays; an upgrade costs the pro-rated difference (section 5).
Change PasswordSets the new password in the panel.
Sync from panel (admin button)Reads the line and takes its username into WHMCS.Also finds a line whose id was lost.
Reset password (client button)A new password in the panel and in WHMCS.

If the saved line id is missing, the module first looks the line up by its external_ref. If the panel does not know the line either, Suspend, Unsuspend, Renew, Change Package, Change Password and Reset password fail with "The panel has no line for this service (create it first, or "Sync from panel")." Terminate counts it as done. Sync from panel then clears the saved id and says: "The panel has no line for this service (external_ref …)."

When the panel refuses something, WHMCS shows the panel's message and its fixed code, e.g. Not enough credits. [insufficient_credits]. The codes are listed in section 10.

Note: A line the panel's team has banned cannot be switched back on through the API, not even with an operator key. Unsuspend answers line_banned; the ban is lifted in the panel only.


5. What costs credits ​

WHMCS uses your credits just as you do in the panel. The team (operator keys) and resellers on an unlimited plan pay no credits.

ActionCredits
CreateThe package's credits. Too few: nothing is created, WHMCS marks the action as failed with insufficient_credits.
RenewThe package's credits again. Too few: nothing is extended.
Suspend / UnsuspendFree. The expiry is not touched; WHMCS decides when to renew.
TerminateFree. Credits come back only if the line is deleted within the Credit refund window after it was created, renewed or moved to another package (default 30 minutes, see Resellers & credits).
Change Package – upgradeThe difference, pro-rated by the time the line has left, rounded up to a whole credit. The expiry stays.
Change Package – downgradeFree, and nothing is refunded.

The upgrade in numbers. For two packages of the same length: (new credits − old credits) × remaining days / package days.

Example: a line on "Basic" (30 days, 10 credits) has 15 days left. The customer moves to "Premium" (30 days, 16 credits). Cost: (16 − 10) × 15 / 30 = 3 credits. The line keeps its expiry date.

If the packages have different lengths, the panel compares the credits per day: (new credits / new days − old credits / old days) × remaining days, rounded up. If the new package costs less per day, it counts as a downgrade and is free. An expired line also pays nothing for a change. In the credit history the booking appears as Package change of line {line}.

Changing the package works only through the API. Trial lines and trial packages cannot change package; a trial line becomes a paid one when it is renewed with a paid package.

Low credit alert ​

So that WHMCS orders do not suddenly fail, set an alert. Resellers find it on My Account › API keys under Low credit alert: "When a line you create, renew or move to another package – in the panel or through the API – takes your balance below this number, you get an e-mail and the credits.low webhook, so orders of your billing system do not suddenly fail. 0 = off."

In the example you set Alert below to 50 credits and Save. Shop orders of your storefronts do not trigger the alert.


6. No double charges ​

Networks fail: WHMCS sends a renewal, the answer gets lost, WHMCS tries again. So that this does not cost you twice, the module sends a name with every write call, the Idempotency-Key (whmcs:<service id>:<action>:<invoice or time>). The panel remembers it for 48 hours. A second call with the same name gets the first successful answer again and is neither run nor charged a second time. A call that failed is not remembered: nothing changed, so the same call runs again, for example after you topped up your credits.

  • Renew is tied to the service's newest paid invoice. A second renewal of the same invoice, whether a retry or a second click, neither charges nor extends. WHMCS shows: "Already renewed for invoice #N: the panel did not charge or extend again."
  • Within one call, the module repeats timeouts and temporary errors (429, 502–504) with the same name.
  • If WHMCS runs a Create again whose answer was lost, the panel answers external_ref_taken. The module then takes over the line it made the first time instead of creating a second one.

7. Client area and admin area ​

Client area. The customer sees the status, package, expiry and connections, and depending on the line type:

  • a line: the Xtream login (server, username, password), the M3U Plus, M3U and Enigma2 links and the Enigma2 script,
  • a MAG box: the portal address and the MAC address.

Every login field and link has a copy button (the MAC address has none), plus a QR code (M3U Plus or the MAG portal). The QR code is made inside WHMCS; no outside service sees the login. The links are the same as in the line's access data in the panel. Reset password gives the line a new password.

The page comes from the template modules/servers/iptvos/templates/overview.tpl, which you can restyle freely.

Admin area. The service's tab in WHMCS shows the panel line (id, username, type), its live status, expiry, package and connections, and the panel's API version. If the panel is newer than the module knows, a note says so; v1 keeps working, but update the module. Open in panel only appears if the server's Username holds the access code (step 3).

Module log. Every call goes to WHMCS' System Logs › Module Log (when it is switched on). The API key, line passwords and MAG portal addresses are masked there.

Not in this version: adult content and extra connections as configurable options, and importing existing lines into WHMCS.


8. Storefront: buy in WHMCS ​

Your storefront can send buyers to your WHMCS cart instead of the panel's checkout. WHMCS then takes the payment and creates the line through the API as above.

In the example: in the storefront editor, tab Legal & support, card Sell through another shop, switch on External shop (e.g. WHMCS) and enter as Order address for every plan the cart link of your product, e.g. https://billing.example.com/cart.php?a=add&pid=12&billingcycle=monthly. As Renew address, enter your WHMCS client area, e.g. https://billing.example.com/clientarea.php?action=services.

All the settings are in the chapter Shop, payments & newsletter.


9. Switching the API on and off ​

WhereSwitchEffect
Settings › General (team)Resellers may use the API"Resellers and sub-resellers can create API keys, for example to connect WHMCS. Off: their keys stop working; team keys keep working. Each account can also be switched off on its own." On by default.
Edit dialog of a reseller or sub-resellerAPI allowed"On: the account's API keys work (if the panel allows resellers the API). Off: its keys and the keys of every account below it stop working."
Shop › Storefronts, Slots (team)Resellers may sell through another shopReseller storefronts may link to their own shop. Off: their plans use the checkout again.

The team and the accounts above set API allowed; nobody switches their own account. Team keys always work.

A switched-off API does not delete any keys. Switched back on, they work again.


10. The API for your own programs ​

The full reference is in the panel: API documentation on the API keys card opens the page /api-docs. At the top it lists the Reseller API v1, read from its OpenAPI file, with each endpoint's scope, body, error codes and a curl example. The file itself can be downloaded there and is served at /api/v1/openapi.json. The endpoint descriptions are in English. Below it, the Panel API is described: "The panel's own API under /api/admin. It changes with the panel; billing systems are better served by the Reseller API v1."

The essentials:

  • Authentication: Authorization: Bearer ipk_…. At most 300 requests per minute and key.
  • "v1 does not change: unknown fields in a request are ignored, errors carry a stable code, and anything incompatible comes as a new version."
  • Send an Idempotency-Key header with every write (section 6). The same key with a different body is refused (idempotency_key_reused).
  • GET /api/v1/ping tells you the account, role, credits, the key's scopes, the panel version and api_version.

Endpoints: ping, packages, credits, lines (create, find by external_ref or username), lines/{id} (read, delete) and lines/{id}/suspend, /unsuspend, /renew, /change-package, /password, /access.

Error codes:

GroupCodes
Key and accessunauthorized, forbidden, scope_missing, ip_not_allowed, api_disabled, rate_limited
Requestbad_request, not_found, conflict, idempotency_key_invalid, idempotency_key_reused, idempotency_in_progress
Lines and creditsinsufficient_credits, package_disabled, line_banned, username_taken, mac_taken, external_ref_taken, trials_off, trial_limit, plan_overdue, plan_line_limit, awaiting_main
Panelinternal_error

Webhooks for billing systems: besides line.updated, the panel now sends line.suspended and line.unsuspended, and credits.low when the balance falls below the alert threshold after a line charge (section 5). Line events carry the external_ref. Setting up webhooks: Team & account.


11. Who may do what? ​

ActionTeamResellerSub-reseller
Create API keys with scopes and IP allow-list✓✓ (when the API is allowed)✓ (when the API is allowed)
Connect WHMCS✓ (lines are free)✓ (pays credits)✓ (pays credits)
Low credit alert–✓✓
Resellers may use the APIOwner and Admin, Staff with Settings edit––
API allowed on an account✓ (not Viewer; Staff with Resellers on Edit)for accounts below itfor accounts below it
Resellers may sell through another shopOwner and Admin, Staff with Storefronts or Payments on Edit––

A key never has more rights than its account: a reseller's key only sees and changes that reseller's lines.


12. Frequently asked questions ​

Test Connection says the key lacks scopes. The key was created with Read only or Custom. Open Edit key in the panel and choose WHMCS / provisioning, or create a new key with it.

Every order fails with "This API key may not be used from …". WHMCS calls from an address that is not on the key's list. Add the address shown to Allowed IP addresses. The refused calls are in the audit log.

Orders fail with "The API is switched off for this account." The operator's setting Resellers may use the API or the switch API allowed on your account or an account above you is off (section 9).

A renewal failed with insufficient_credits. Top up your credits and run Renew in the service again. Because the renewal is tied to the paid invoice, it runs exactly once, even if you click several times.

I deleted a line in the panel by hand. What does WHMCS do? WHMCS still has the line id saved, so Renew or Suspend fail with Not found. [not_found]. Terminate counts the missing line as done. If the customer should keep their access, click Sync from panel: it clears the saved id and says "The panel has no line for this service (external_ref …)". Then run Create in the service.

Does an upgrade change the expiry date? No. Only Renew adds days. Change Package only charges the difference for the remaining time.

Can I use the API without WHMCS? Yes. Every billing system or script can use the Reseller API v1 with the same key; the reference is on /api-docs (section 10).