Cisco
300-435 · Question #138
Refer to the exhibit. A network engineer developed a script to automate the method to retrieve a list of network devices that are deployed to an enterprise. When the script is executed, it fails to…
The correct answer is A. Change PUT to GET. The REST API for retrieving (reading) network device information requires an HTTP GET request, not PUT. Changing PUT to GET will allow the script to properly retrieve the list of devices.
Network Automation Foundation
Question
Refer to the exhibit. A network engineer developed a script to automate the method to retrieve a list of network devices that are deployed to an enterprise. When the script is executed, it fails to retrieve the list of devices. Which action resolve the issue?
1 def network_device_list(apic, ticket, id=None):
2
3 # Use the REST API to retrieve the list of network devices.
4 # If a device id is provided, return only that device
5
6 url = "https://{}/api/v1/network-device".format(apic)
7 headers = {"X-auth-token": " " + ticket}
8
9 # Change URL to single device given an id
10 if id:
11 url += "/{}".format(id)
12
13 # Make API request and return the response body
14 response = requests.request("PUT", url, headers=headers, verify=False)
15
16 # Always return a list object, even if single device for consistency
17 if id:
18 return [response.json()] ["response"]
19
20 return response.json() ["response"]
Exhibit
Options
- AChange PUT to GET.
- BChange PUT to DELETE.
- CChange PUT to POST.
- DChange PUT to PATCH.
How the community answered
(23 responses)- A91% (21)
- C4% (1)
- D4% (1)
Explanation
The REST API for retrieving (reading) network device information requires an HTTP GET request, not PUT. Changing PUT to GET will allow the script to properly retrieve the list of devices.
Topics
#REST API#HTTP methods#Python requests#API troubleshooting
Community Discussion
No community discussion yet for this question.
