MOR API v2 user assign provider
Assign or unassign an unassigned provider trunk to a simple user so the provider can place calls using that user's balance — the same workflow as Configure Provider which can make calls in the GUI.
GUI equivalent
Who may use the API: Admin, Accountant (with the rights below), or Reseller when provider management is allowed for that reseller. Simple users cannot assign providers.
Menu path (admin / accountant): SETTINGS → Users → Users — open the Devices link for a simple user, then use Assign Provider to pick an unassigned provider. To remove an assignment, open the provider and use Unassign provider (or the unassign action from the user's Devices view when shown).
Restrictions (same as GUI): The path user must be a simple user (not a reseller or accountant). The provider must be unassigned before being assigned. A user may have more than one provider assigned.
Authentication
MOR API v2 Bearer JWT — obtain a token via POST /billing/api/v2/authentication/login (see Usage on the hub page).
API permission methods
When the authenticated user has API restrictions enabled, the user's API permission group must grant:
| API method key | Permission (Write) | Used for |
|---|---|---|
v2_users_assign_provider |
Assign Provider to User | POST …/assign_provider
|
v2_users_unassign_provider |
Unassign Provider from User | DELETE …/assign_provider
|
See How to block access to some API functions for restricting API methods per user.
Accountant GUI rights
In addition to the API methods above, an accountant needs write access on all of:
acc_device_manage(Devices)manage_provider(Providers)user_manage(Users)
See Accountant permissions for how accountant groups are configured.
Reseller
Allowed only when the reseller is permitted to manage providers (same rule as legacy provider API write access). The target user must belong to that reseller.
Assign provider
POST /billing/api/v2/users/{id}/assign_provider
Path
{id}— target simple user id.
JSON body
| Field | Required | Description |
|---|---|---|
provider_id |
yes* | Provider id to assign. |
provider_device_id |
no | Provider trunk device id (GUI provdevice). Ignored when provider_id is present.
|
- One of
provider_idorprovider_device_idis required.
Success (200)
{
"status": "assigned",
"user_id": 123,
"provider_id": 1,
"device_id": 456,
"warnings": []
}
warnings may contain a localized hint when another provider under the same owner shares the same registration (login, password, IP, and port) — the same caution as the GUI Avoid routing problems message.
If the device extension configuration fails after assignment, the API returns 422 and does not mark the assignment as successful (stricter than the GUI, which may show a partial state).
Unassign provider
DELETE /billing/api/v2/users/{id}/assign_provider
Path
{id}— same simple user as assign.
Query parameters (preferred for automation)
| Parameter | Required | Description |
|---|---|---|
provider_id |
yes* | Provider id to remove from this user. |
provider_device_id |
no | Provider trunk device id. Ignored when provider_id is set.
|
- One of
provider_idorprovider_device_idis required.
Success (200)
{
"status": "unassigned",
"user_id": 123,
"provider_id": 1,
"device_id": 456
}
Unassign is blocked when the provider device still has CLIs configured (same as the GUI).
Errors
| HTTP | Typical cause |
|---|---|
401 |
Invalid or missing JWT, API disabled, missing accountant/reseller rights, or API method not permitted (v2_users_assign_provider / v2_users_unassign_provider).
|
403 |
Target user not under the authenticated owner (forbidden). |
404 |
User or provider not found, or provider not available for assignment (already assigned / wrong owner). |
422 |
Path user is not a simple user; provider already assigned; provider not assigned to this user; CLIs block unassign; assign rolled back after extension configuration failure. |
Examples
Assign
curl -s -X POST -H "Authorization: Bearer $TOKEN" -H "Content-Type: application/json" \
-d '{"provider_id":1}' \
"https://example.com/billing/api/v2/users/123/assign_provider"
Unassign
curl -s -X DELETE -H "Authorization: Bearer $TOKEN" \ "https://example.com/billing/api/v2/users/123/assign_provider?provider_id=1"
See also
- MOR API v2 — authentication and OpenAPI (
/billing/api/v2/api-docs/) - Configure Provider which can make calls — product workflow and balance behaviour
- Providers — creating and editing providers
- Users — simple users and devices
- Accountant permissions — accountant group rights
- How to block access to some API functions — per-user API method groups