DevNet Associate (DEVASC) v1.0Understanding and Using APIsHard

A network automation developer is using Postman to test a new REST API endpoint on a Cisco router. The API documentation specifies that the endpoint `/restconf/data/interfaces/interface=GigabitEthernet1` expects a `PUT` request with a JSON payload to modify the interface configuration. The developer constructs the request in Postman, but the router consistently returns a `400 Bad Request` error, even though the JSON payload appears correct. Which of the following is the MOST likely cause of the `400 Bad Request` error in this scenario?

  1. AThe authentication token has expired or is invalid.
  2. BThe API is expecting XML data instead of JSON.
  3. CThe API endpoint requires `PATCH` instead of `PUT` for partial updates.
  4. DThe `Content-Type` header is not set correctly to `application/yang-data+json`.
Show answer & explanation

Correct answer: D. The `Content-Type` header is not set correctly to `application/yang-data+json`.

A `400 Bad Request` with a seemingly correct JSON payload often indicates that the server cannot parse or understand the request body due to an incorrect `Content-Type` header. For YANG-model-based APIs like RESTCONF on Cisco devices, the `Content-Type` header typically needs to be `application/yang-data+json` (or `application/yang.data+json`), not just `application/json`.

Why the other options are wrong

  • A. An expired or invalid authentication token typically results in a `401 Unauthorized` or `403 Forbidden` error, not `400 Bad Request`.
  • B. The scenario states the payload is JSON, and RESTCONF commonly supports YANG-data+JSON. If XML was expected, the documentation would specify it, and a `415 Unsupported Media Type` would be more likely.
  • C. While `PATCH` is for partial updates, `PUT` for full resource replacement is valid. A method mismatch usually results in a `405 Method Not Allowed`, not `400 Bad Request`.

RESTCONF Content-Type

For RESTCONF APIs, especially when using YANG models, the `Content-Type` header for JSON payloads is often `application/yang-data+json` (or `application/yang.data+json`), specifying the data adheres to a YANG model.

  • Crucial for server to correctly parse the request body.
  • Differs from generic `application/json` for YANG-structured data.
  • Incorrect `Content-Type` often leads to `400 Bad Request` or `415 Unsupported Media Type`.

Memory trick: Bad Request? Check Headers First, Then Body, Then Method.

More Understanding and Using APIs questions