200-901 · Question #410
Drag and Drop Question Refer to the exhibit. Drag and drop the code from the bottom onto the box where the code is missing to construct a Python script that calls a REST API request. Not all options…
The correct answer is requests; response; status_code; item. This question tests the ability to construct a Python script using the 'requests' library to make a REST API POST call, correctly identifying the URL variable, Content-Type header, the generic 'request' method, and the request body (payload).
Question
Drag and Drop Question Refer to the exhibit. Drag and drop the code from the bottom onto the box where the code is missing to construct a Python script that calls a REST API request. Not all options are used. Answer:
Exhibit
Answer Area
Drag items
Correct arrangement
- requests
- response
- status_code
- item
Explanation
This question tests the ability to construct a Python script using the 'requests' library to make a REST API POST call, correctly identifying the URL variable, Content-Type header, the generic 'request' method, and the request body (payload).
Approach. The correct interaction involves dragging four specific code snippets into the four blank spaces in the Python script:
-
First blank (variable assignment): The line
_____ = "https://fmc-hostname/api/fmc_tid/v1/domain/tid/source"assigns a URL string to a variable. The most appropriate and common variable name for an API endpoint in this context isurl. So, dragurlinto the first blank. -
Second blank (HTTP header key): The line
headers = { 'X-auth-access-token': 'access_token', _____: 'application/json' }defines HTTP headers. The value'application/json'is a standard specification for the type of content being sent in the request body. The corresponding HTTP header key for this isContent-Type. So, dragContent-Typeinto the second blank. -
Third blank (requests library method): The line
response = requests._____("POST", url, ...)uses therequestslibrary to make an HTTP call. Since the HTTP method"POST"is passed as the first argument, the generic methodrequests.request()is the correct function to use when the HTTP method is specified as a string argument. So, dragrequestinto the third blank. -
Fourth blank (data argument): The line
response = requests.request("POST", url, headers=headers, data=_____)specifies the data to be sent in the request body. Thepayloaddictionary defined earlier in the script (payload = { ... }) holds this data. Therefore,payloadshould be passed to thedataargument. So, dragpayloadinto the fourth blank.
Common mistakes.
- common_mistake. Common mistakes include:
- Using
base_urlinstead ofurl: Whilebase_urlis semantically similar,urlis a more direct and common variable name for the specific endpoint being called in a simple script. - Incorrect header for
application/json: MisidentifyingContent-Typeas another header name would lead to an incorrectly formatted request. - Using
postas therequestsmethod: Whilerequests.post()is a valid method for POST requests, the script explicitly passes"POST"as an argument to the method. This pattern indicates the use of the more genericrequests.request()method, where the HTTP verb is provided as an argument. - Using
Encodingor other irrelevant options: These options do not fit the context of a URL variable, HTTP header, orrequestslibrary function/argument.
Concept tested. The core technical concept being tested is the ability to construct and understand a Python script for making REST API calls using the requests library, specifically focusing on HTTP POST requests, proper URL definition, HTTP header configuration (especially Content-Type), and passing request bodies (payloads).
Topics
Community Discussion
No community discussion yet for this question.
