MikroPanel Agent API

Documents with examples · مستندات با نمونه

English · فارسی · Endpoints · Errors · openapi.json · Postman · Python · PHP

Base address: https://api.mikropanel.ir/v1

Guide

Start

Create a key in the panel: Settings → API access. Your account owner must switch API access on for you first. Keep the key on your own server. Never put it inside a mobile or web app: anyone holding it can sell and delete your services.

curl https://api.mikropanel.ir/v1/me -H "Authorization: Bearer mp_live_..."

Sell a service in 5 calls

curl -X POST https://api.mikropanel.ir/v1/peers \
  -H "Authorization: Bearer mp_live_..." -H "Content-Type: application/json" \
  -H "Idempotency-Key: order-10231-create" \
  -d '{"name":"order10231","router_id":3,"traffic_bytes":32212254720,"days":30,"external_ref":"10231"}'

Units and time

Retries (Idempotency-Key)

Creating, renewing, adding traffic and adding L2TP need the header Idempotency-Key. Make one per operation (for example from your order id) and save it before calling.

Limits

Without fixed IP addresses a key works from anywhere with the lower limits. If your server has a fixed address, add it in Settings → API access: then only those addresses can use your keys, and the limits are higher. Tiers as reads per minute | changes per minute | changes in flight | changes per day. Changes of one account are applied one after another: "in flight" is how many may be sent at the same time, the extra ones waiting up to 15 seconds for their turn (then server_busy; retry with the same Idempotency-Key).

Your account owner may set other values; GET /v1/me shows yours. Every answer carries X-RateLimit-Limit, X-RateLimit-Remaining and X-RateLimit-Reset; on 429 or 503 wait for Retry-After seconds. 20 wrong keys in a minute block an address for the rest of that minute.

Errors

Every error is {"error": {"code", "message", "message_fa", "details", "request_id"}}. Decide by code, never by the message. Give request_id to support. After operation_failed, check the resource before trying again.

Agent types

Examples and tools

Changes

راهنما

شروع

curl https://api.mikropanel.ir/v1/me -H "Authorization: Bearer mp_live_..."

فروش یک سرویس در پنج درخواست

curl -X POST https://api.mikropanel.ir/v1/peers \
  -H "Authorization: Bearer mp_live_..." -H "Content-Type: application/json" \
  -H "Idempotency-Key: order-10231-create" \
  -d '{"name":"order10231","router_id":3,"traffic_bytes":32212254720,"days":30,"external_ref":"10231"}'

واحدها و زمان

تلاش دوباره (Idempotency-Key)

ساخت، تمدید، افزایش حجم و افزودن L2TP هدر Idempotency-Key می‌خواهند. برای هر عملیات یک مقدار تازه بسازید (مثلاً از شمارهٔ سفارش) و پیش از ارسال ذخیره‌اش کنید.

محدودیت درخواست‌ها

اگر IP ثابت ثبت نکنید، کلید از هر نشانی‌ای کار می‌کند ولی سقف پایین‌تری دارد. اگر سرورتان IP ثابت دارد، آن را در «تنظیمات ← دسترسی API» وارد کنید: از آن پس فقط همان نشانی‌ها می‌توانند از کلیدهایتان استفاده کنند و سقف بالاتر می‌رود. ترتیب عددها: خواندن در دقیقه | تغییر در دقیقه | تغییر هم‌زمان | تغییر در روز. تغییرهای یک حساب پشت سر هم اجرا می‌شوند. «تغییر هم‌زمان» شمار درخواست‌هایی است که می‌توانید با هم بفرستید؛ بقیه تا ۱۵ ثانیه منتظر نوبت می‌مانند و اگر نوبتشان نشود server_busy می‌گیرند (با همان Idempotency-Key دوباره بفرستید).

صاحب حساب می‌تواند مقدارهای دیگری تعیین کند؛ GET /v1/me مقدارهای شما را نشان می‌دهد. هر پاسخ هدرهای X-RateLimit-Limit، X-RateLimit-Remaining و X-RateLimit-Reset دارد. پس از خطای 429 یا 503 به اندازهٔ Retry-After ثانیه صبر کنید. اگر از یک نشانی در یک دقیقه 20 کلید نادرست برسد، آن نشانی تا پایان همان دقیقه مسدود می‌شود.

خطاها

هر خطا به شکل {"error": {"code", "message", "message_fa", "details", "request_id"}} است. برنامه باید بر اساس code تصمیم بگیرد، نه متن پیام. هنگام تماس با پشتیبانی request_id را بفرستید. پس از operation_failed، پیش از تلاش دوباره وضعیت را بررسی کنید.

انواع نماینده

نمونه‌کدها و ابزارها

تغییرها

Endpoints

Account

GET /v1/me — Who this key is, what it may do and its limits

Scope: read

GET /v1/me/balance — Traffic credit, peer quota and plan credits

Scope: read

GET /v1/me/stats — Peer counts and traffic sold

Scope: read

L2TP clients

GET /v1/clients — List your clients, newest first

Scope: read

Query

NameTypeMeaning
limitintItems per page (default 50).
cursorintnext_cursor of the previous page.
statusstrOnly this status. Values: inactive, active, limit_reached, suspended, not_started
router_idintOnly this router.
namestrName contains this text.
updated_sincedatetimeChanged at or after this time.
DELETE /v1/clients/{client_id} — Delete a client

Scope: peers:write

The L2TP account is removed. The WireGuard peer stays, switched off; delete it with DELETE /peers/{id} (a limited agent is refunded then).

GET /v1/clients/{client_id} — One client with its accounts

Scope: read

POST /v1/clients/{client_id}/add-traffic — Raise a client's traffic limit

Scope: peers:write · needs Idempotency-Key

A limited agent pays the added traffic from its wallet.

Body (JSON)

NameTypeMeaning
traffic_bytes *intBytes to add.
GET /v1/clients/{client_id}/credentials — L2TP login of a client

Scope: peers:config

POST /v1/clients/{client_id}/disable — Disable a client (all protocols)

Scope: peers:write

POST /v1/clients/{client_id}/enable — Enable a client

Scope: peers:write

Refused with renew_required when the traffic or time is used up.

POST /v1/clients/{client_id}/l2tp — Add L2TP to a client

Scope: peers:write · needs Idempotency-Key

POST /v1/clients/{client_id}/renew — Start a new period for a client

Scope: peers:write · needs Idempotency-Key

Give plan_id, or both traffic (or unlimited_traffic) and days (or unlimited_time). Usage restarts. Limited agents: at most 90 days.

Body (JSON)

NameTypeMeaning
plan_idintUse a credit plan: it decides every limit.
start_nowboolWith a plan: start the clock now instead of at the first connection.
traffic_bytesintTraffic limit in bytes.
unlimited_trafficboolNo traffic limit (unlimited agents only).
daysintDuration in days.
unlimited_timeboolNo expiry (unlimited agents only).
start_on_first_connectboolCount the days from the first connection.
POST /v1/clients/from-peer — Turn one of your peers into a client

Scope: peers:write · needs Idempotency-Key

The client takes over the peer's limit, expiry and usage; L2TP is added. A peer made from a plan can only get the protocols of that plan.

Body (JSON)

NameTypeMeaning
peer_id *intYour standalone peer.
protocolsstrlistDefault ["wireguard","l2tp"].
GET /v1/l2tp-servers — Routers where you can sell L2TP

Scope: read

Peers

GET /v1/peers — List your peers, newest first

Scope: read

Query

NameTypeMeaning
limitintItems per page (default 50).
cursorintnext_cursor of the previous page.
statusstrOnly this status. Values: suspended, active, limit_reached, disabled_by_owner, not_started, pending_deletion
router_idintOnly this router.
namestrName contains this text.
external_refstrExactly this external_ref.
customer_telegram_idintExactly this Telegram id.
updated_sincedatetimeSettings or status changed at or after this time (traffic counters alone do not count).
POST /v1/peers — Create a peer (WireGuard, optionally with L2TP)

Scope: peers:write · needs Idempotency-Key

Give plan_id, or your own traffic and duration. Unlimited traffic or time must be asked for explicitly and only unlimited agents may do it. With protocols ["wireguard","l2tp"] both are made, or neither. The answer includes the config only when the key has the peers:config scope.

Body (JSON)

NameTypeMeaning
name *str3-30 characters: letters, digits, - and _. Unique per router.
router_idintNeeded when you have several routers and the plan does not fix one.
plan_idintUse a credit plan: it decides every limit.
start_nowboolWith a plan: start the clock now instead of at the first connection.
traffic_bytesintTraffic limit in bytes.
unlimited_trafficboolNo traffic limit (unlimited agents only).
daysintDuration in days.
unlimited_timeboolNo expiry (unlimited agents only).
expires_atdatetimeExact expiry instead of (or besides) days.
start_on_first_connectboolCount the days from the first connection.
show_as_unlimitedboolLimited agents: show the customer "unlimited" (the limit still applies).
protocolsstrlist["wireguard"] (default) or ["wireguard","l2tp"]. A plan decides this itself.
descriptionstrYour note.
external_refstrYour own id for this peer (order id). Unique among your peers.
customer_telegram_idintTelegram id of your customer.
DELETE /v1/peers/{peer_id} — Delete a peer

Scope: peers:write

A limited agent gets the unused traffic back as the panel does. A peer with L2TP is deleted together with its client.

GET /v1/peers/{peer_id} — One peer with its gift code and public page link

Scope: read

PATCH /v1/peers/{peer_id} — Change name, description or your own references

Scope: peers:write

Body (JSON)

NameTypeMeaning
namestrNew name (also renamed on the router).
descriptionstrNew note; "" clears it.
external_refstrYour own id; "" clears it.
customer_telegram_idintTelegram id of your customer; 0 clears it.
GET /v1/peers/{peer_id}/config — WireGuard configuration

Scope: peers:config

Query

NameTypeMeaning
formatstrjson (default) or file. Values: json, file
use_domainboolUse the router's current domain as endpoint (default true).
GET /v1/peers/{peer_id}/qr — QR code of the configuration (PNG)

Scope: peers:config

Query

NameTypeMeaning
use_domainboolUse the router's current domain as endpoint (default true).
POST /v1/peers/{peer_id}/renew — Renew a peer with a plan or your own limits

Scope: peers:write · needs Idempotency-Key

mode "set" (default) replaces the limits, "add" adds to them. Limited agents: at most 90 days; lowering the traffic returns nothing at once, the unused amount comes back on delete or reset. A peer that also has L2TP is renewed as a whole (set only, new traffic and duration, usage restarts). The answer includes the config only when the key has the peers:config scope.

Body (JSON)

NameTypeMeaning
plan_idintUse a credit plan: it decides every limit.
start_nowboolWith a plan: start the clock now instead of at the first connection.
traffic_bytesintTraffic limit in bytes.
unlimited_trafficboolNo traffic limit (unlimited agents only).
daysintDuration in days.
unlimited_timeboolNo expiry (unlimited agents only).
expires_atdatetimeExact new expiry.
modestrset or add. Values: set, add
reset_usageboolStart counting usage from zero (set mode; say the new traffic too).
start_on_first_connectboolOnly for a peer with L2TP renewed with your own limits.
POST /v1/peers/{peer_id}/suspend — Suspend a peer

Scope: peers:write

POST /v1/peers/{peer_id}/unsuspend — Lift a suspension

Scope: peers:write

Refused with renew_required when the traffic or time is used up.

Plans

GET /v1/plans — Your credit plans with remaining credits

Scope: read

GET /v1/plans/{plan_id} — One credit plan

Scope: read

Routers

GET /v1/routers — Routers assigned to you, with limits and availability

Scope: read

GET /v1/routers/{router_id} — One assigned router

Scope: read

Service

GET /v1/docs — This reference (HTML)

No key needed

GET /v1/examples/mikropanel.php — Example client in PHP

No key needed

GET /v1/examples/mikropanel.py — Example client in Python

No key needed

GET /v1/health — Is the API up and can it reach its database

No key needed

GET /v1/openapi.json — OpenAPI 3.1 description

No key needed

GET /v1/postman.json — Postman collection of every endpoint

No key needed

Usage

GET /v1/peers/{peer_id}/usage — Daily or hourly traffic of one peer

Scope: read

A day range covers at most 366 days. L2TP traffic has totals only (see the client).

Query

NameTypeMeaning
intervalstrday (default) or hour. Values: day, hour
fromdateinterval=day: first day (default 29 days before "to").
todateinterval=day: last day (default today).
datedateinterval=hour: the day (default today).
GET /v1/usage — Daily or hourly traffic of all your peers

Scope: read

Query

NameTypeMeaning
intervalstrday (default) or hour. Values: day, hour
fromdateinterval=day: first day (default 29 days before "to").
todateinterval=day: last day (default today).
datedateinterval=hour: the day (default today).

Error codes

CodeHTTPEnglishفارسی
account_inactive403The account is suspended or expired.حساب غیرفعال یا منقضی شده است.
add_to_unlimited409There is no limit to add to: this is already unlimited.مقدار فعلی نامحدود است و افزودن معنا ندارد.
agent_needs_wireguard403Agents make L2TP services on a WireGuard peer.نماینده L2TP را روی یک کلاینت وایرگارد می‌سازد.
already_member409The peer already belongs to a client.این کلاینت از قبل عضو یک سرویس است.
api_disabled403API access is not enabled for this account.دسترسی API برای این حساب فعال نیست.
bad_content_type415Send the body as application/json.بدنه را با نوع application/json بفرستید.
bad_json400The request body is not valid JSON.بدنهٔ درخواست JSON معتبر نیست.
bad_protocols422protocols must name wireguard and/or l2tp.پروتکل‌ها نامعتبر است.
bad_value422A field has an invalid value.مقدار یک فیلد نامعتبر است.
billing_unsupported409This plan cannot be used for this operation.این پلن برای این عملیات قابل استفاده نیست.
body_too_large413The request body is too large.بدنهٔ درخواست بیش از حد بزرگ است.
client_renew_unsupported409A service with L2TP only supports a full renewal.سرویس دارای L2TP فقط تمدید کامل دارد.
clients_disabled404L2TP clients are not enabled on this panel.قابلیت L2TP روی پنل فعال نیست.
clients_not_allowed403L2TP clients are not enabled for this account.L2TP برای این حساب فعال نیست.
config_unavailable404No configuration is stored for this peer.پیکربندی این کلاینت موجود نیست.
conflicting_fields422These fields cannot be used together.این فیلدها با هم قابل استفاده نیستند.
credits_expired409Your credit for this plan has expired.اعتبار این پلن منقضی شده است.
daily_limit_reached429The daily limit of changes is used up.سقف روزانهٔ تغییرات تمام شده است.
database_unavailable503The database is not available.پایگاه داده در دسترس نیست.
duration_required422Give days, expires_at or unlimited_time.مدت زمان را مشخص کنید.
encryption_unavailable503Secret storage is not available on this server.سرویس رمزنگاری در دسترس نیست.
expiry_in_past422The expiry date must be in the future.تاریخ انقضا باید در آینده باشد.
external_ref_taken409Another of your peers already has this external_ref.این external_ref برای کلاینت دیگری ثبت شده است.
group_not_supported409This peer is part of a multi-device group. Manage it in the dashboard for now.این کلاینت عضو یک گروه چنددستگاهی است؛ فعلاً از داشبورد مدیریت کنید.
https_required403Use HTTPS.از HTTPS استفاده کنید.
idempotency_key_required422Send an Idempotency-Key header (8 to 128 characters).هدر Idempotency-Key الزامی است.
idempotency_key_reused422This Idempotency-Key was used for a different request.این Idempotency-Key برای درخواست دیگری استفاده شده است.
in_client409This peer belongs to a client; manage it through /clients.این کلاینت عضو یک سرویس است.
in_group409The peer is part of a multi-device group.این کلاینت عضو گروه چنددستگاهی است.
insufficient_credit409Not enough traffic credit.اعتبار ترافیک کافی نیست.
insufficient_credits409Not enough credits for this plan.اعتبار پلن کافی نیست.
insufficient_scope403This key does not have the needed scope.این کلید دسترسی لازم را ندارد.
internal_error500Unexpected server error. Quote the request id to support.خطای غیرمنتظره سرور؛ شناسهٔ درخواست را به پشتیبانی بدهید.
invalid_api_key401The API key is not valid, expired or revoked.کلید API نامعتبر، منقضی یا باطل شده است.
invalid_name422The name must be 3 to 30 characters: a-z, A-Z, 0-9, "-" and "_".نام باید ۳ تا ۳۰ نویسهٔ انگلیسی، عدد، - یا _ باشد.
invalid_plan422The plan id is not valid.پلن نامعتبر است.
ip_not_allowed403This IP address is not in the allowed list of the account.این آدرس IP در فهرست مجاز حساب نیست.
l2tp_failed502L2TP could not be added.افزودن L2TP ناموفق بود.
l2tp_not_allowed403L2TP is not allowed on this router for your account.L2TP روی این روتر برای شما مجاز نیست.
l2tp_unavailable409L2TP is not available on this router.L2TP روی این روتر در دسترس نیست.
member_not_found404Peer not found.کلاینت پیدا نشد.
method_not_allowed405This method is not allowed here.این متد مجاز نیست.
missing_api_key401Send your key as "Authorization: Bearer <key>".کلید API ارسال نشده است.
missing_field422A required field is missing.یک فیلد الزامی ارسال نشده است.
name_taken409This name is already used on this router.این نام روی این روتر استفاده شده است.
no_agent_profile403The account has no agent profile.پروفایل نماینده ثبت نشده است.
no_credits409You have no credit for this plan.برای این پلن اعتباری ندارید.
no_free_ip409No free address is left on this router.آدرس آزاد روی این روتر باقی نمانده است.
no_l2tp404This client has no L2TP account.این کلاینت حساب L2TP ندارد.
no_router_assigned409No router is assigned to this account.روتری به این حساب اختصاص داده نشده است.
no_server409This client has no router.این سرویس روتری ندارد.
not_agent403The API is for agent accounts.این API مخصوص حساب نماینده است.
not_found404Not found.پیدا نشد.
nothing_to_renew422The renewal changes nothing.تمدید هیچ تغییری ندارد.
operation_failed502The operation failed. Check the resource before retrying; quote the request id to support.عملیات ناموفق بود؛ پیش از تلاش دوباره وضعیت را بررسی کنید.
out_of_range422A value is outside the allowed range.مقدار خارج از بازه مجاز است.
outcome_unknown409The first request with this key did not finish cleanly. Check the resource (for example by external_ref) before sending a new key.نتیجه درخواست قبلی نامشخص است؛ پیش از تلاش دوباره وضعیت را بررسی کنید.
peer_limit_reached409Your peer limit is used up.سقف تعداد کلاینت شما تکمیل است.
peer_locked409This peer is locked by the account owner or by a package limit.این کلاینت توسط صاحب حساب یا محدودیت بسته قفل شده است.
peer_manager_unavailable503Peer management is not available right now.مدیریت کلاینت در دسترس نیست.
peer_not_attachable409This peer cannot become a client in its current state.این کلاینت در وضعیت فعلی قابل تبدیل نیست.
plan_conversion_needs_limits422Renewing a plan peer with custom limits needs both traffic and duration.برای تبدیل کلاینت پلنی، حجم و زمان هر دو لازم است.
plan_credit_only403This account works with credit plans only.این حساب فقط با پلن اعتباری کار می‌کند.
plan_group_unsupported409A multi-device client cannot be renewed with a plan.کلاینت چنددستگاهی با پلن تمدید نمی‌شود.
plan_mode_disabled403Credit plans are not enabled for this account.پلن اعتباری برای این حساب فعال نیست.
plan_not_found404Plan not found or inactive.پلن پیدا نشد یا غیرفعال است.
plan_protocols409The plan and the protocols do not match.پروتکل‌ها با پلن هم‌خوانی ندارند.
plan_router_mismatch409This plan cannot be used on this router.این پلن برای این روتر نیست.
protocol_present409The client already has L2TP.این کلاینت از قبل L2TP دارد.
rate_limited429Too many requests. Wait and retry.تعداد درخواست‌ها زیاد است؛ کمی صبر کنید.
renew_days_limit403A limited agent can renew for at most 90 days.تمدید نمایندهٔ محدود حداکثر ۹۰ روز است.
renew_required409This peer reached its limit or expiry. Renew it first.محدودیت یا زمان این کلاینت تمام شده؛ ابتدا تمدید کنید.
request_in_progress409The first request with this key is still running.درخواست قبلی با این کلید هنوز در حال اجراست.
router_busy503Another change is running on this router. Retry in a few seconds.عملیات دیگری روی این روتر در حال انجام است.
router_full409This router has no free capacity.ظرفیت این روتر تکمیل است.
router_not_assigned403This router is not assigned to you.این روتر به شما اختصاص داده نشده است.
router_not_found404Router not found.روتر پیدا نشد.
router_not_ready409WireGuard is not set up on this router.سرویس وایرگارد این روتر راه‌اندازی نشده است.
router_peer_cap_reached409Your peer limit on this router is used up.سقف کلاینت شما روی این روتر تکمیل است.
router_peer_cap_unset409No peer limit is set for you on this router yet.سقف کلاینت این روتر برای شما تعیین نشده است.
router_required422Say which router (router_id).روتر (router_id) را مشخص کنید.
router_unreachable502The router could not be reached.اتصال به روتر برقرار نشد.
server_busy503The server is busy. Retry in a few seconds.سرور مشغول است؛ چند ثانیه بعد تلاش کنید.
speed_not_allowed422Agents cannot set a speed per peer; the shared agent speed applies.نماینده نمی‌تواند سرعت جداگانه تعیین کند؛ سرعت مشترک نماینده اعمال می‌شود.
too_many_auth_failures429Too many failed keys from this address.تلاش ناموفق زیاد از این آدرس.
too_many_concurrent_writes429Too many changes running at the same time.تعداد عملیات هم‌زمان بیش از حد است.
traffic_required422Give traffic_bytes or unlimited_traffic.مقدار ترافیک را مشخص کنید.
unknown_field422The request has fields this endpoint does not accept.درخواست فیلد ناشناخته دارد.
unlimited409This client has no traffic limit, so there is nothing to add to.این سرویس محدودیت حجم ندارد.
unlimited_not_allowed403A limited agent cannot give unlimited traffic or time.نمایندهٔ محدود نمی‌تواند ترافیک یا زمان نامحدود بدهد.