QuestionQ577

Understanding and Using APIs

Refer to the exhibit. An engineer sends a request to collect data through the Cisco AMP for Endpoints API. The engineer must list guide and hostname data for all computers, but the first request returns only 500 items out of 2,000. The engineer then adds a loop to retrieve all the data. What must be inserted at the missing location to complete the requests?

Drag & Drop
next_url = response_json ['metadata'] ['links'] ['next']
url = 'https://api.amp.cisco.com/v1/computers'
response = session.get (url)
response_json = response.json ()

for item in response_json ['data']:
    print(item['connector_guid'], item['hostname'])

while 'next' in response_json['metadata'] ['links']:
    
    response = session.get (next_url)
    response_json = response.json()
    for item in response_json['data']:
        print(item['connector_guid'], item['hostname'])
Explanation

Cisco AMP for Endpoints paginates list responses and provides the URL of the next page in metadata.links.next. Assigning that value to next_url lets the loop retrieve each subsequent page until no next link remains.

Learn more

Community Discussion

No comments yet. Be the first to start the discussion!