Python Admin API data format and response
Cloudera Data Visualization provides examples of python Admin API data format and response.
The response data for GET
operations is a list of JSON items.
For POST
operations, such as UPDATE
and
CREATE
, the input format is a structure with a data
field that contains the JSON list of items. The UPDATE
and
CREATE
operations process one item at a time, so
the list is exactly one entry long.
The response data for POST
operations is the updated item,
matching a GET
with detail=1
for the item,
as demonstrated in Example
1.
For item updates, it is only necessary to specify the fields you are updating. Cloudera Data Visualization merges the supplied fields in the input data with the existing item's data, as demonstrated in Example 2.
Example 1: Setting the name for role ID=1 to 'System Admin'
payload = {'name':'System Admin'}
session.post(api_url + '/roles/1', data={'data':json.dumps([payload])})
Note that the API URL has the following form:
[http|htttps]://host:port/arc/adminapi/version
For syntax of other parameters, see Admin API syntax parameters.
Example 2: Checking role ID=2; updating by adding a new user
response = session.get(api_url + '/roles/2?detail=1')
role = response.json()[0]
if 'new_user' not in role['users']:
payload = {'users':role['users'] + ['new_user']}
session.post(api_url + '/roles/2', data={'data':json.dumps([payload])})
For the definition of fields for each data type, see Data type details.