Setting up a session
CDP Data Visualization Admin API supports two alternatives for setting up a session: standard login access and APIKey access.
Standard login access
To establish a session with username/password login, use the following
code:
username = "" #(user name as obtained from external source)
password = "" #(password as obtained from external source)
session = requests.session()
response = session.get(login_url)
session.headers['referer'] = response.url
payload = {'username':username,'password':password,'csrfmiddlewaretoken': session.cookies['arccsrftoken']}
session.post(login_url, data = payload)
APIKey access
To establish a session through the Cloudera API Key system and avoid the login process,
use the following
code:
apikey = (apikey string)
session = requests.session()
session.headers['AUTHORIZATION'] = 'apikey %s' % apikey
In this approach, the client code must obtain the DataViz access key through a client-controlled mechanism, then add the APIKey to the request header and avoid explicit login.
Fetch data from all datasets in the system
After setting up a session, you can fetch the entire data from all datasets in the
system, by using the following
code:
response = session.get(api_url + 'datasets?detail=1')
datasets = response.json()