nerdexam
Cisco

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).

Understanding and Using APIs

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

200-901 question #410 exhibit

Answer Area

Drag items

itemresponserequestsget()status_codestatus

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:

  1. 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 is url. So, drag url into the first blank.

  2. 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 is Content-Type. So, drag Content-Type into the second blank.

  3. Third blank (requests library method): The line response = requests._____("POST", url, ...) uses the requests library to make an HTTP call. Since the HTTP method "POST" is passed as the first argument, the generic method requests.request() is the correct function to use when the HTTP method is specified as a string argument. So, drag request into the third blank.

  4. Fourth blank (data argument): The line response = requests.request("POST", url, headers=headers, data=_____) specifies the data to be sent in the request body. The payload dictionary defined earlier in the script (payload = { ... }) holds this data. Therefore, payload should be passed to the data argument. So, drag payload into the fourth blank.

Common mistakes.

  • common_mistake. Common mistakes include:
  • Using base_url instead of url: While base_url is semantically similar, url is a more direct and common variable name for the specific endpoint being called in a simple script.
  • Incorrect header for application/json: Misidentifying Content-Type as another header name would lead to an incorrectly formatted request.
  • Using post as the requests method: While requests.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 generic requests.request() method, where the HTTP verb is provided as an argument.
  • Using Encoding or other irrelevant options: These options do not fit the context of a URL variable, HTTP header, or requests library 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

#Python scripting#REST API#HTTP requests#requests library

Community Discussion

No community discussion yet for this question.

Full 200-901 Practice