200-901 · Question #82
200-901 Question #82: Real Exam Question with Answer & Explanation
A Python script creating a Meraki network using the API requires filling in the correct HTTP method, API endpoint segments, authentication header, content type, and request body parameters.
Question
Drag and Drop Question Refer to the exhibit. Drag and drop the code from the left onto the item numbers on the right to complete to Meraki python script shown in the exhibit. Answer:
Explanation
A Python script creating a Meraki network using the API requires filling in the correct HTTP method, API endpoint segments, authentication header, content type, and request body parameters.
Approach. To correctly complete the Python script, each placeholder must be filled based on the Meraki API documentation and standard requests library usage:
- <item 1>: The API documentation specifies a
POSTrequest to create a new network. Therefore,postshould be dragged here to callrequests.post(). - <item 2>: The URL construction starts with the
base_urldefined earlier in the script. So,base_urlis the correct choice. - <item 3>: Following the
base_urland the first slash, the API path (from Exhibit 1) is/organizations/{organizationId}/networks. Thus,organizationsprecedes theorg_idvariable. - <item 4>: After the
org_idand the subsequent slash, the path concludes withnetworksto target the network creation endpoint. - <item 5>: The
X-Cisco-Meraki-API-Keyheader is for authentication and requires the API key, which is stored in theapi_keyvariable. - <item 6>: When sending a JSON payload, the
Content-Typeheader must be set toapplication/json. - <item 7>: The
json.dumps()function is used to serialize a Python dictionary into a JSON string. When passing a pre-serialized JSON string torequests.post(), it should be assigned to thedataparameter, notjson(which is for Python dictionaries thatrequestswill serialize itself). - <item 8>: The API documentation states that the 'name' parameter in the request body is for the network's name. The script defines
network_name = 'New Network', sonetwork_nameis the correct variable.
Common mistakes.
- common_mistake. Common mistakes would include using
getinstead ofpostfor Item 1 (incorrect HTTP method for resource creation), mixing up the order oforganizationsandnetworksin the URL path (Items 3 and 4), using an incorrect variable for the API key (Item 5) or content type (Item 6), or incorrectly passing the JSON payload. For instance, ifjsonwere used for Item 7 instead ofdata, therequestslibrary would attempt to serialize the already serialized JSON string again, potentially leading to malformed JSON or an error. Usingorg_idorapi_keyfor Item 8 would incorrectly set the network name. These errors demonstrate a lack of understanding of REST API principles, Python'srequestslibrary, or specific Meraki API requirements.
Concept tested. REST API interaction using Python's requests library, including making POST requests, constructing API endpoint URLs, setting HTTP headers for authentication and content type, and handling JSON request bodies. It also tests understanding of specific Meraki API conventions for creating network resources.
Topics
Community Discussion
No community discussion yet for this question.