My URL is below
https://tiation.eu2.portal.cloudappsecurity.com/api/v1/discovery/discovered_apps
This returns JSON response of defender API:
{
"data": [
{
"_id": "5ee1ee8ad68d0eb7d71cc7ac",
"_tid": 85526804,
"appId": 11394,
]
}
],
"hasNext": true,
"total": 11902
}
It is hasnext which is fine and total. But i do not get next url or next link.
I tried multiple things like ?page= , ?offset=100&limit=1
Not able to get its documentation for paging in this API.
Can someone suggest better idea?
I got a python script which says:
# -*- coding: utf-8 -*-
import json
import sys
import requests
import msal
msal_tenant_id = '' ### Paste your tenant ID here
msal_client_id = '' ### Paste your Application ID here
msal_client_secret = '' ### Paste your Application key here
global_token_cache = msal.TokenCache()
msal_authority = f"https://login.microsoftonline.com/{msal_tenant_id}"
msal_scope = ["05a65629-4c1b-48c1-a78b-804c4abdd4af/.default"]
global_app = msal.ConfidentialClientApplication(
msal_client_id, authority=msal_authority,
client_credential=msal_client_secret,
token_cache=global_token_cache, # Let this app (re)use an existing token cache.
# If absent, ClientApplication will create its own empty token cache
)
result = global_app.acquire_token_for_client(scopes=msal_scope)
if "access_token" in result:
print("Token was obtained from:", result["token_source"])
headers = {
'Authorization': f'Bearer {result["access_token"]}',
}
filters = {
# optionally, edit to match your filters
}
request_data = {
'filters': filters,
'limit' : 1,
'streamId' : '<stream-id>'
}
APPLICATIONS_URL = f'https://<tenant-name>.<tenant-region>.portal.cloudappsecurity.com/api/v1/discovery/discovered_apps/'
records = []
has_next = False
while has_next:
content = json.loads(requests.post(APPLICATIONS_URL, json=request_data, headers=headers).content)
response_data = content.get('data', [])
records += response_data
print('Got {} more records'.format(len(response_data)))
has_next = content.get('hasNext', False)
request_data['filters'] = content.get('nextQueryFilters')
print('Got {} records in total'.format(len(records)))
print(records)
else:
print("Token acquisition failed")
sys.exit(0)
But here also nextQueryFilters not got in response anywhere. So anyone can help? (BTW, I am using Postman and will code in Java and above was from Postman Response).
Update:
Pagination not working at all.
Tried following changing Skip:
{
"limit": 100,
"streamId": "5ee1ecbb862d7370de23c481",
"sortDirection":"asc",
"skip": 100
}
Still Failing
It worked as query parameter:
And bad part i got all examples as Request Body whether python or powershell.
So it was just hit and trial