Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.


1.1. Introduction to the NMS Prime API

The NMS Prime API is REST/JSON based. Using the API one can create, modify, delete or inspect database objects. The user input will be validated prior to storing it. If the validation fails a corresponding error message will be returned, informing the user which field failed validation.

A user is authenticated using BasicAuth. Currently only the user with the email address "api@localhost" is allowed to access the API. This user is authorized to create, modify, delete or inspect any database object. In future there will be the role "api" which can be assigned to any user having API access. Furthermore one will be able to grant the various API users different fine-grained access rights for the database objects, just like it is possible for the normal WebGUI.

For most users the most interesting objects will be:

  1. Qos

  2. Contract

  3. Modem

  4. MTA

  5. Telephone Number

By virtue of the HTTP/REST transport protocol many different clients can be used. We will only use curl and python in the upcoming examples.


See OpenAPI for a full API description: https://www.nmsprime.com/api/ 

Drawio
bordertrue
viewerToolbartrue
fitWindowfalse
diagramNameoss-bss
simpleViewerfalse
width600
diagramWidth1020
revision2
title


Info

Please use the email address as username, when trying to authenticate with the API. The password is the same you use to login to the NMS Prime web interface.

1.2. Inspecting database objects

Code Blocklanguagebash
1.2.1.1.1. Inspecting Qos objects using curl
collapse
Code Block
language
true
bash
# GET all Qos objects 
$
(in 
curl
this 
-u
case id 1 and 6)
$ curl -u api@localhost:secret https://localhost:8080/admin/api/v0/Qos
[
{"models":{"1":{"id":1,"created_at":"
2015
2016-
12
09-
16
08 
14
10:
20
38:
25
15","updated_at":"
2018
2020-
06
04-10 15
18
:
05
57:
14
34","deleted_at":null,"ds_rate_max":
100
2,"us_rate_max":
10
1,"ds_rate_max_help":
104857600
2000000,"us_rate_max_help":
10485760
1000000,"name":"
100M
2:1"
},
,"ds_name":"D2M","us_name":"U1M"},"6":{"id":
2
6,"created_at":"
2016
2018-
02
01-
15
11 
14
13:
11
29:
40
00","updated_at":"2018-06-15 18:05:14","deleted_at":null,"ds_rate_max":
25
50,"us_rate_max":2,"ds_rate_max_help":
26214400
50000000,"us_rate_max_help":
2097152
2000000,"name":"
25M
50:2"
}
,
{
"
id
ds_name":
3
"D50M","
created
us_
at
name":"
2016-02-15 14:11:55","updated_at":"2018-06-15 18:05:14","deleted_at":null,"ds_rate_max
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,"
us_rate_max":2,"ds_rate_max_help":6291456,"us_rate_max_help":2097152,"name":"6M"},{"id":6,"created_at":"2018-01-11 13:29:00","updated_at":"2018-
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":
52428800
50000000,"us_rate_max_help":
2097152
2000000,"name":"50
M
:2"
}
,
{"id":7,"created_at
"ds_name":"
2018-01-26 14:00:36
D50M","
updated
us_
at
name":"
2018-06-15 18:05:14","deleted_at":null,"ds_rate_max":1,"us_rate_max":0.5,"ds_rate_max_help":1048576,"us_rate_max_help":524288,"name":"1 M"}] # GET Qos object with a certain id (6) $ curl -u api@localhost:secret
U2M"}},"success":true,"id":6}


Info

You need to add verify=False in the get/post/patch statements, if you haven't set up a proper TLS certificate yet. You may do so using Getting a X.509 certificate via Let's Encrypt


1.2.1.1.2. Inspecting database objects using python
Code Block
languagepy
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
/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":52428800,"us_rate_max_help":2097152,"name":"50 M"}
Info

You need to add verify=False in the get/post/patch statements, if you haven't set up a proper TLS certificate yet. You may do so using Getting a X.509 certificate via Let's Encrypt.

Code Block
languagepy
titleInspecting database objects using python
linenumberstrue
collapsetrue
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 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/
Qos
Mta')
# GET 
Qos
Mta object with a certain id (
6
300001)
r = session.get('https://localhost:8080/admin/api/v0/
Qos
Mta/
6
300001')

# GET all 
Contract
Phonenumber objects
r = session.get('https://localhost:8080/admin/api/v0/
Contract
Phonenumber')
# GET 
Contract
Phonenumber object with a certain id (
500000
300001)
r = session.get('https://localhost:8080/admin/api/v0/
Contract
Phonenumber/
500000
300001')

# 
GET all Modem objects
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')
# 
GET
returns 
Modem object with a certain id (100001
only cm-100000 (00:11:22:33:44:55)
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)
?contract_id=500001&mac=00:11:22:33:44:55')

print(r.text)

1.3. Creating, modifying and deleting database objects

1.3.1.1.1. Creating database objects using python
Code Block
languagepy
import json
import requests
session = requests.Session()
session.auth = ('api@localhost', 'secret')

# GET description of all fields of this object, the ones with an asterisk (*) must be provided, otherwise validation will fail
r = session.get('https://localhost:8080/admin/api/v0/
Mta
Contract/
300001
create')

# 
GET
CREATE 
all
a 
Phonenumber objects
contract
r = session.
get
post('https://localhost:8080/admin/api/v0/
Phonenumber
Contract'
) # 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
, 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 first name of newly created contract
ret = json.loads(r.text)
r = session.
get
patch('https://localhost:8080/admin/api/v0/
Modem?contract_id=500001&mac=00:11:22:33:44:55') print(r.text)

Creating, modifying and deleting database objects

Code Block
languagepy
titleCreating database objects using python
linenumberstrue
collapsetrue
import json import requests session = requests.Session() session.auth = ('api@localhost', 'secret') # GET description of all fields of this object, the ones with an asterisk (*) must be provided, otherwise validation will fail r = session.get('https://localhost:8080/admin/api/v0/Contract/create') # CREATE a contract r = session.post
Contract/{}'.format(ret['id']), json={'firstname' : 'Maxi'})
# {"success":true,"id":500001}

# CREATE a contract with 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'
,
)
# 
json={'firstname' : 'Max', 'lastname' : 'Mustermann', 'street' : 'Dörfelstraße', 'house_number' : '7', 'zip' : '09496', 'city' : 'Marienberg', 'phone' : '037359387570', 'birthday' : '1970-01-01'}) # {"ret":"success","id":500001} # MODIFY first name of newly created contract ret = json.loads(r.text) r = session.patch(
{"success":true}


# The same operations are available for all the other database objects as well. e.g.:
# Qos
r = session.get('https://localhost:8080/admin/api/v0/Qos/create')
r = session.post('https://localhost:8080/admin/api/v0/
Contract/{}'.format(ret['id']), json={'firstname
Qos', json={'name' : '1000:100 test', 'ds_rate_max' : '
Maxi
1000'
}) # {"ret":"success"} # CREATE a contract with missing birthday -> validation fails r
, 'us_rate_max' : '100'})
ret = json.loads(r.text)
r = session.
post
patch('https://localhost:8080/admin/api/v0
/Contract',
/Qos/{}'.format(ret['id']) json={'
firstname
name' : '
Missing
100:10 test', '
lastname
ds_rate_max' : '
Birthday
100', '
street
us_rate_max' : '
Dörfelstraße
10'
, 'house_number' : '7', 'zip
})
r = session.post('https://localhost:8080/admin/api/v0/Qos', json={'name' : '
09496', 'city' : 'Marienberg
missing us rate test', '
phone
ds_rate_max' : '
037359387570
1000'})
r 
# {"ret":{"birthday":["The birthday field is required."]}} # DELETE a contract with a certain id (500001) r = session.
= session.delete('https://localhost:8080/admin/api/v0/Modem/
500001') # {"ret":"success"}
{}'.format(ret['id']))

# 
The same operations are available for all the other database objects as well. e.g.: # Qos
Modem
r = session.get('https://localhost:8080/admin/api/v0/
Qos
Modem/create')
r = session.post('https://localhost:8080/admin/api/v0/
Qos
Modem', json={'
name
mac' : '
1000:100 test
00:11:22:33:44:55', '
ds_rate_max
contract_id' : '500000', 'configfile_id' : '
1000
3', '
us
qos_
rate_max
id' : '
100
1'})
ret = json.loads(r.text)
r = session.patch('https://localhost:8080/admin/api/v0/
Qos
Modem/{}'.format(ret['id']) json={'
name
configfile_id' : '
100:10 test', 'ds_rate_max' : '100', 'us_rate_max' : '10'})
6'})
r = session.delete('https://localhost:8080/admin/api/v0/Modem/{}'.format(ret['id']))

# Mta
r = session.
post
get('https://localhost:8080/admin/api/v0/Mta/
Qos
create'
,
)
r 
json
=
{'name' : 'missing us rate test', 'ds_rate_max' : '1000'}) r = session.delete
 session.post('https://localhost:8080/admin/api/v0/
Modem/{}'.format(ret['id'])) # Modem r
Mta', json={'mac' : '11:22:33:44:55:66', 'modem_id' : '100000', 'configfile_id' : '186'})
ret = json.loads(r.text)
r = session.
get
patch('https://localhost:8080/admin/api/v0/
Modem
Mta/
create')
{}'.format(ret['id']) json={'configfile_id' : '181'})
r = session.
post
delete('https://localhost:8080/admin/api/v0/Mta/
Modem', json={'mac' : '00:11:22:33:44:55', 'contract_id
{}'.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' : '
500000
0049', '
configfile
prefix_
id
number' : '
3
030', '
qos_id
number' : '
1
123456'
}) ret = json.loads(r.text) r = session.patch('https://localhost:8080/admin/api/v0/Modem/{}'.format(ret['id']) json={'configfile_id
, 'mta_id' : '300000', 'port' : '1', 'username' : 'mustermann', 'password' : 'secret', 'sipdomain' : 'sip.provider.com', 'active' : '
6
1'})
ret = json.loads(r.text)
r = session.
delete
patch('https://localhost:8080/admin/api/v0/
Modem
Phonenumber/{}'.format(ret['id'])
)
 
# Mta
json={'active' : '0'})
r = session.
get
delete('https://localhost:8080/admin/api/v0/
Mta
Phonenumber/
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)
{}'.format(ret['id']))

print(r.text)


1.3.1.1.2. Restarting modems/MTAs and getting the online status of a modem
Code Block
languagepy
import json
import requests
session = requests.Session()
session.auth = ('api@localhost', 'secret')

r = session.
patch
get('https://localhost:8080/admin/api/v0/Mta
/{}'.format(ret['id']) json={'configfile_id' : '181'})
/300023/restart')
# {"success":true,"id":300023}
r = session.
delete
get('https://localhost:8080/admin/api/v0/Mta
/{}'.format(ret['id'])) # Phonenumber r = session.get('https://
/300023/restart')
# {"messages":{"errors":["Could not restart MTA! (offline?)"]},"success":true,"id":300023}

r = session.get('https://localhost:8080/admin/api/v0/Modem/
Phonenumber
100003/
create
status')
# {"success":true,"id":100003}
r = session.
post
get('https://localhost:8080/admin/api/v0/Modem/100003/
Phonenumber
restart'
,
)
# 
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)
{"messages":{"infos":["Das Modem wurde erfolgreich \u00fcber 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.
patch
get('https://localhost:8080/admin/api/v0/Modem/
Phonenumber/{}'.format(ret['id']) json={'active' : '0'}) r = session.delete('https://localhost:8080/admin/api/v0/Phonenumber/{}'.format(ret['id']))
100003/restart')
# {"messages":{"errors":["Das Modem konnte nicht neu gestartet werden! (offline?)"]},"success":true,"id":100003}

print(r.text)
Code Block
languagepy
titleRestarting modems/MTAs and getting the online status of a modem
linenumberstrue
collapsetrue
import json
import requests
session = requests.Session()
session.auth = ('api@localhost', 'secret')

r = session.get('https://localhost:8080/admin/api/v0/Mta/300023/restart')
# {"ret":"success"}
r = session.get('https://localhost:8080/admin/api/v0/Mta/300023/restart')
# {"ret":"Could not restart MTA! (offline?)"}


r = session.get('https://localhost:8080/admin/api/v0/Modem/100003/status')
# {"ret":"success","online":true}
r = session.get('https://localhost:8080/admin/api/v0/Modem/100003/restart')
# {"ret":"Das Modem wurde erfolgreich über das CMTS neugestartet"}
r = session.get('https://localhost:8080/admin/api/v0/Modem/100003/status')
# {"ret":"success","online":false}
r = session.get('https://localhost:8080/admin/api/v0/Modem/100003/restart')
# {"ret":"Das Modem konnte nicht neugestartet werden! (offline?)"}

print(r.text)

Getting API URLs

In order to modify objects of other types than the ones mentioned above one needs to find the according API URL. This can be accomplished using the WebGUI by clicking on the according object. For example one may want to modify Endpoints. They can be retrieved using the WebGUI by clicking on "Provisioning" → "Endpoints". This leads to the URL https://localhost:8080/admin/Endpoint. Thus the API Base-URL for the endpoints will be: https://localhost:8080/admin/api/v0/Endpoint.

1.4. Getting API URLs

In order to modify objects of other types than the ones mentioned above one needs to find the according API URL. This can be accomplished using the WebGUI by clicking on the according object. For example one may want to modify Endpoints. They can be retrieved using the WebGUI by clicking on "Provisioning" → "Endpoints". This leads to the URL https://localhost:8080/admin/Endpoint. Thus the API Base-URL for the endpoints will be: https://localhost:8080/admin/api/v0/Endpoint.


1.4.1. Postman API Demo Collection:

Set the variable "base_url" for the collection and enter your credentials (email and password) into Basic Auth fields.

Run in PostmanImage Added or import the json from here:

View file
nameNMS Prime API Demo.postman_collection.json