NMS Prime API
1. Introduction
The NMS Prime API is REST/JSON based. Using the API you can create, modify, delete or inspect database objects. All user input is validated before it is stored. If validation fails, a JSON error message is returned telling you which field failed validation.
The objects most commonly used are:
QoS
Contract
Modem
MTA
Phonenumber (telephone number)
Because the API uses the HTTP/REST transport protocol, any HTTP client can be used. The examples below use curl and Python (the requests library).
See the OpenAPI specification for a full, machine-readable API description: nmsprime.com/api.
2. Authentication
The API is protected with HTTP Basic Auth. Authenticate with the email address of an NMS Prime user as the username and the same password you use to log in to the NMS Prime web interface.
A dedicated API user with the email address api@localhost is available and is authorized to inspect, create, modify and delete any database object. Fine-grained, per-object API permissions (an api role comparable to the WebGUI permissions) are planned for a future release.
If you have not yet installed a valid TLS certificate, HTTPS certificate verification will fail. For quick tests you can disable verification (for example verify=False with Python requests, or -k with curl). For production, install a proper certificate — see Getting a X.509 certificate via Let's Encrypt.
3. Base URL and conventions
All API endpoints live under the /admin/api/v0/ path of your NMS Prime host, followed by the object type (for example Qos, Contract, Modem). The standard REST verbs map to the following operations:
Method | Endpoint | Purpose |
|---|---|---|
|
| List all objects of a type. |
|
| Inspect a single object by id. |
|
| Return the object's fields; those marked with an asterisk (*) are required. |
|
| Create a new object. |
|
| Modify an existing object. |
|
| Delete an object by id. |
Responses are JSON and include a success boolean. Read operations return the matching objects under models; create operations return the new id; failed validation returns a validations object listing the offending fields. You can also filter list endpoints by any model attribute using query parameters, for example ?contract_id=500001.
4. Inspecting database objects
4.1. Inspecting QoS objects using curl
# GET all Qos objects (in this case id 1 and 6)
$ curl -u api@localhost:secret https://localhost:8080/admin/api/v0/Qos
{"models":{"1":{"id":1,"created_at":"2016-09-08 10:38:15","updated_at":"2020-04-10 15:57:34","deleted_at":null,"ds_rate_max":2,"us_rate_max":1,"ds_rate_max_help":2000000,"us_rate_max_help":1000000,"name":"2:1","ds_name":"D2M","us_name":"U1M"},"6":{"id":6,"created_at":"2018-01-11 13:29:00","updated_at":"2018-06-15 18:05:14","deleted_at":null,"ds_rate_max":50,"us_rate_max":2,"ds_rate_max_help":50000000,"us_rate_max_help":2000000,"name":"50:2","ds_name":"D50M","us_name":"U2M"}},"success":true}
# GET Qos object with a certain id (6)
$ curl -u api@localhost:secret https://localhost:8080/admin/api/v0/Qos/6
{"models":{"6":{"id":6,"created_at":"2018-01-11 13:29:00","updated_at":"2018-06-15 18:05:14","deleted_at":null,"ds_rate_max":50,"us_rate_max":2,"ds_rate_max_help":50000000,"us_rate_max_help":2000000,"name":"50:2","ds_name":"D50M","us_name":"U2M"}},"success":true,"id":6}4.2. Inspecting database objects using Python
import json
import requests
# initialize session and authenticate using BasicAuth
session = requests.Session()
session.auth = ('api@localhost', 'secret')
# GET all Qos objects
r = session.get('https://localhost:8080/admin/api/v0/Qos')
# GET Qos object with a certain id (6)
r = session.get('https://localhost:8080/admin/api/v0/Qos/6')
# GET all Contract objects
r = session.get('https://localhost:8080/admin/api/v0/Contract')
# GET Contract object with a certain id (500000)
r = session.get('https://localhost:8080/admin/api/v0/Contract/500000')
# GET all Modem objects
r = session.get('https://localhost:8080/admin/api/v0/Modem')
# GET Modem object with a certain id (100001)
r = session.get('https://localhost:8080/admin/api/v0/Modem/100001')
# GET all Mta objects
r = session.get('https://localhost:8080/admin/api/v0/Mta')
# GET Mta object with a certain id (300001)
r = session.get('https://localhost:8080/admin/api/v0/Mta/300001')
# GET all Phonenumber objects
r = session.get('https://localhost:8080/admin/api/v0/Phonenumber')
# GET Phonenumber object with a certain id (300001)
r = session.get('https://localhost:8080/admin/api/v0/Phonenumber/300001')
# Search using arbitrary model attributes
# returns e.g. cm-100000 (00:11:22:33:44:55) and cm-100001 (66:77:88:99:AA:BB) of contract 500001
r = session.get('https://localhost:8080/admin/api/v0/Modem?contract_id=500001')
# returns only cm-100000 (00:11:22:33:44:55)
r = session.get('https://localhost:8080/admin/api/v0/Modem?contract_id=500001&mac=00:11:22:33:44:55')
print(r.text)5. Creating, modifying and deleting database objects
5.1. Creating database objects using Python
import json
import requests
session = requests.Session()
session.auth = ('api@localhost', 'secret')
# GET a description of all fields of this object; those marked with an asterisk (*) are required, otherwise validation fails
r = session.get('https://localhost:8080/admin/api/v0/Contract/create')
# CREATE a contract
r = session.post('https://localhost:8080/admin/api/v0/Contract', json={'number' : '0123456789', 'firstname' : 'Max', 'lastname' : 'Mustermann', 'street' : 'Dörfelstraße', 'house_number' : '7', 'zip' : '09496', 'city' : 'Marienberg', 'phone' : '037359387570', 'birthday' : '1970-01-01'})
# {"success":true,"id":500001}
# MODIFY the first name of the newly created contract
ret = json.loads(r.text)
r = session.patch('https://localhost:8080/admin/api/v0/Contract/{}'.format(ret['id']), json={'firstname' : 'Maxi'})
# {"success":true,"id":500001}
# CREATE a contract with a missing birthday -> validation fails
r = session.post('https://localhost:8080/admin/api/v0/Contract', json={'number' : '0123456789', 'firstname' : 'Missing', 'lastname' : 'Birthday', 'street' : 'Dörfelstraße', 'house_number' : '7', 'zip' : '09496', 'city' : 'Marienberg', 'phone' : '037359387570'})
# {"validations":{"birthday":["The birthday field is required."]},"success":false}
# DELETE a contract with a certain id (500001)
r = session.delete('https://localhost:8080/admin/api/v0/Contract/500001')
# {"success":true}
# The same operations are available for all other database objects, e.g.:
# QoS
r = session.get('https://localhost:8080/admin/api/v0/Qos/create')
r = session.post('https://localhost:8080/admin/api/v0/Qos', json={'name' : '1000:100 test', 'ds_rate_max' : '1000', 'us_rate_max' : '100'})
ret = json.loads(r.text)
r = session.patch('https://localhost:8080/admin/api/v0/Qos/{}'.format(ret['id']), json={'name' : '100:10 test', 'ds_rate_max' : '100', 'us_rate_max' : '10'})
r = session.delete('https://localhost:8080/admin/api/v0/Qos/{}'.format(ret['id']))
# Modem
r = session.get('https://localhost:8080/admin/api/v0/Modem/create')
r = session.post('https://localhost:8080/admin/api/v0/Modem', json={'mac' : '00:11:22:33:44:55', 'contract_id' : '500000', 'configfile_id' : '3', 'qos_id' : '1'})
ret = json.loads(r.text)
r = session.patch('https://localhost:8080/admin/api/v0/Modem/{}'.format(ret['id']), json={'configfile_id' : '6'})
r = session.delete('https://localhost:8080/admin/api/v0/Modem/{}'.format(ret['id']))
# Mta
r = session.get('https://localhost:8080/admin/api/v0/Mta/create')
r = session.post('https://localhost:8080/admin/api/v0/Mta', json={'mac' : '11:22:33:44:55:66', 'modem_id' : '100000', 'configfile_id' : '186'})
ret = json.loads(r.text)
r = session.patch('https://localhost:8080/admin/api/v0/Mta/{}'.format(ret['id']), json={'configfile_id' : '181'})
r = session.delete('https://localhost:8080/admin/api/v0/Mta/{}'.format(ret['id']))
# Phonenumber
r = session.get('https://localhost:8080/admin/api/v0/Phonenumber/create')
r = session.post('https://localhost:8080/admin/api/v0/Phonenumber', json={'country_code' : '0049', 'prefix_number' : '030', 'number' : '123456', 'mta_id' : '300000', 'port' : '1', 'username' : 'mustermann', 'password' : 'secret', 'sipdomain' : 'sip.provider.com', 'active' : '1'})
ret = json.loads(r.text)
r = session.patch('https://localhost:8080/admin/api/v0/Phonenumber/{}'.format(ret['id']), json={'active' : '0'})
r = session.delete('https://localhost:8080/admin/api/v0/Phonenumber/{}'.format(ret['id']))
print(r.text)5.2. Restarting modems / MTAs and reading modem status
import json
import requests
session = requests.Session()
session.auth = ('api@localhost', 'secret')
# Restart an MTA
r = session.get('https://localhost:8080/admin/api/v0/Mta/300023/restart')
# {"success":true,"id":300023}
r = session.get('https://localhost:8080/admin/api/v0/Mta/300023/restart')
# {"messages":{"errors":["Could not restart MTA! (offline?)"]},"success":true,"id":300023}
# Read a modem's online status and restart it
r = session.get('https://localhost:8080/admin/api/v0/Modem/100003/status')
# {"success":true,"id":100003}
r = session.get('https://localhost:8080/admin/api/v0/Modem/100003/restart')
# {"messages":{"infos":["Das Modem wurde erfolgreich über das NetGw neu gestartet"]},"success":true,"id":100003}
r = session.get('https://localhost:8080/admin/api/v0/Modem/100003/status')
# {"success":false,"id":100003}
r = session.get('https://localhost:8080/admin/api/v0/Modem/100003/restart')
# {"messages":{"errors":["Das Modem konnte nicht neu gestartet werden! (offline?)"]},"success":true,"id":100003}
print(r.text)6. Getting API URLs
To work with object types other than those listed above, look up the corresponding API URL via the WebGUI. Click the object in the interface — for example Provisioning → Endpoints opens https://localhost:8080/admin/Endpoint. The matching API base URL is therefore https://localhost:8080/admin/api/v0/Endpoint.
6.1. Postman demo collection
Set the base_url variable for the collection and enter your credentials (email and password) into the Basic Auth fields.