200-901 Software Development and Design Practice Question
A developer is building a REST API client in Python using the requests library. They need to send a JSON payload with authentication. Which code snippet correctly sends a POST request with a JSON body and a Bearer token?
Answer choices
Why each option matters
Answer the question above first, then reveal the full breakdown to understand why each option is right or wrong.
Correct answer & explanation
✓
requests.post(url, json=payload, headers={'Authorization': f'Bearer {token}'})
The correct way is to use json parameter for JSON body and headers for authorization.
Answer analysis
Option-by-option breakdown
For each option: why learners choose it and why it is or isn't the right answer here.
- ✗
requests.post(url, data=payload, auth=token)
Why it's wrong here
Passing a raw token to auth produces invalid Basic authentication, and data sends form-encoded content rather than JSON. This pattern suits simple HTTP Basic credentials against form endpoints, not a Bearer-token JSON API, where headers and the json parameter are required.
- ✓
requests.post(url, json=payload, headers={'Authorization': f'Bearer {token}'})
Why this is correct
Passing json=payload serialises the dict and sets Content-Type to application/json automatically, while the headers dict supplies the Bearer token in the Authorization header. This satisfies both the JSON body and authenticated POST requirements in one call.
- ✗
requests.post(url, data=json.dumps(payload), headers={'Authorization': token})
Why it's wrong here
json.dumps with data sends a JSON string but omits the Content-Type: application/json header, and the Authorization value lacks the required 'Bearer ' prefix. This approach fits APIs accepting raw bodies with custom headers, not standard Bearer-token JSON endpoints.
- ✗
requests.post(url, params=payload, auth=('Bearer', token))
Why it's wrong here
params places the payload in the URL query string rather than the request body, and auth=('Bearer', token) generates Basic authentication, not a Bearer header. Query parameters suit GET filtering; Bearer JSON APIs need the json parameter and an Authorization header.
Go deeper
Related to this question
About these practice questions
This 200-901 question is part of Courseiva's 975-question bank — original exam-style content with full explanations and wrong-answer analysis, never real exam questions or exam dumps. Learn why practice questions differ from exam dumps →
JA
Written by Johnson Ajibi, MSc IT Security
Senior Network & Security Engineer · founder of Courseiva
This 200-901 practice question is part of Courseiva's free Cisco certification practice question bank. Courseiva provides original exam-style practice questions with explanations, topic-based practice, mock exams, readiness tracking, and study analytics to help learners prepare for the 200-901 exam.