Share via

Pagination for cloud app security api

Husum Hansen, Sarah DK - DAE 0 Reputation points
2023-09-12T11:10:23.1033333+00:00

Hi all,

how do I paginate in the API for cloud app security api?

im currently working with the requests Python package.

AZURE_CLIENT_ID = os.getenv("AZURE_CLIENT_ID")
AZURE_CLIENT_SECRET = os.getenv("AZURE_CLIENT_SECRET")
AZURE_TENANT_ID = os.getenv("AZURE_TENANT_ID")
RESOURCE_ID = os.getenv("RESOURCE_ID")

def get_access_token_cloud_app() -> str:
    """ Get access token for graph API

    Returns:
        str: Access token
    """
    auth_url = f"https://login.microsoftonline.com/{AZURE_TENANT_ID}/oauth2/token"

    auth_body = {
        'resource': RESOURCE_ID,
        'client_id': AZURE_CLIENT_ID,
        'client_secret': AZURE_CLIENT_SECRET,
        'grant_type': 'client_credentials'
    }

    auth_response = requests.post(url=auth_url, data=auth_body, timeout=300)
    auth_response_json = auth_response.json()
    aad_token = auth_response_json["access_token"]

    headers = { 
        'Content-Type': 'application/json',
        'Accept': 'application/json',
        'Authorization': f"Bearer {aad_token}"
    }
    return headers

headers = get_access_token_cloud_app()
url = "https://<tenant_id>.<tenant_region>.cloudappsecurity.com/api/v1/discovery/discovered_apps/"
response = requests.get(url=url, headers=headers, timeout=300)



Hope you can help!

Best regards

Sarah

Microsoft Security | Microsoft Graph
0 comments No comments

Your answer

Answers can be marked as 'Accepted' by the question author and 'Recommended' by moderators, which helps users know the answer solved the author's problem.