Versions Compared

Key

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

...

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('https://localhost:8080/admin/api/v0/Contract', 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('https://localhost:8080/admin/api/v0/Contract/{}'.format(ret['id']), json={'firstname' : 'Maxi'})
# {"ret":"success"}

# CREATE a contract with missing birthday -> validation fails
r = session.post('https://localhost:8080/admin/api/v0/Contract', json={'firstname' : 'Missing', 'lastname' : 'Birthday', 'street' : 'Dörfelstraße', 'house_number' : '7', 'zip' : '09496', 'city' : 'Marienberg', 'phone' : '037359387570'}
# {"ret":{"birthday":["The birthday field is required."]}}

# DELETE a contract with a certain id (500001)
r = session.delete('https://localhost:8080/admin/api/v0/Modem/500001')
# {"ret":"success"}


# 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/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.post('https://localhost:8080/admin/api/v0/Qos', json={'name' : 'missing us rate test', 'ds_rate_max' : '1000'})
r = session.delete('https://localhost:8080/admin/api/v0/Modem/{}'.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)


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.

...