Integration, Extension & APIs

Discussion board where members can learn more about Integration, Extensions and API’s for Qlik Sense.

Announcements
Introducing Qlik Answers: A plug-and-play, Generative AI powered RAG solution. READ ALL ABOUT IT!

Who Me Too'd this topic

bakedbean
Contributor II
Contributor II

Qlik Cloud REST API - App Usage

Hello everyone!

We have an issue with our Entitlement Analyzer on Qlik Cloud, it was working and now it's not, the reload times out after 3 hours. 

In the interim I am trying to use python and the REST API to quickly retrieve usage data for specific apps (I really need to see who is accessing)

I can successfully connect using my API token. I have been playing around with some different end points and came to the conclusion I need to use the "v1/licenses/consumption' one. 

The below code seems to be getting close to what I want, which is to give an app ID and see the usage data of said app. I'm not getting all the data back due to the limit, and am struggling to get much further 

import requests
import json
import pandas as pd

# Replace with your Qlik Cloud tenant URL and API key
tenant_url = 'https://your-tenant.us.qlikcloud.com'
api_key = 'your_api_key'
app_id = 'your_app_id'  # Replace with the specific app ID you want to query

# Set up the endpoint and headers
endpoint = f'{tenant_url}/api/v1/licenses/consumption'
headers = {
    'Authorization': f'Bearer {api_key}',
    'Content-Type': 'application/json'
}

# Define the query parameters to filter by app ID
params = {
    'resourceId': app_id,
    'resourceType': 'app',
    'limit': 100,  # Adjust as needed, maximum is 100
    'sort': '-endTime'  # Sort by last used time in descending order
}

# Make the request
response = requests.get(endpoint, headers=headers, params=params)

# Check the response status
if response.status_code == 200:
    license_data = response.json()
    
    # Extract relevant data into a list of dictionaries
    data = [
        {'User ID': item.get('userId'), 'End Time': item.get('endTime')}
        for item in license_data.get('data', [])
    ]
    
    # Create a pandas DataFrame from the list of dictionaries
    df = pd.DataFrame(data)
    
    # Print the DataFrame as a table
    print(df.to_string(index=False))
else:
    print(f"Failed to retrieve data: {response.status_code}")
    print(response.json())

 

If anyone has experience with Python and the REST API I would love to hear your thoughts and any help would be greatly appreciated 🙂

Thanks

 

 

Labels (2)
Who Me Too'd this topic