14.6.7 Receiving Validation Error in REST API

REST API clients see the same validation errors that end users see in the app.

Your REST APIs URL template handlers call common Action Item logic in the ACTION_ITEMS_COMMON package. If a REST API client tries to create a new action item with duplicate team members, the call fails. The behavior is the same for curl, Postman, or another system.

As shown below, HTTP error 400 signals an application-specific failure, and the JSON response explains why. By using shared logic and error handling, REST clients see the same messages app users see for the same invalid data. The figure shows the result of using the Postman REST API testing tool to POST a request to the endpoint:

https://example.com/ords/cloudcompanion/v1/actionitems

The example request's body contains the following JSON payload where both Levi and Opal team members have the role of LEAD.

{
  "name": "Website Redesign Project",
  "team": [
     {"role":"LEAD",  "name":"Levi"},
     {"role":"LEAD",  "name":"Opal"},
     {"role":"MEMBER","name":"David"},
     {"role":"MEMBER","name":"Georgia"},
  ]
}
The status 400 response body includes the JSON payload:
{"$error":"Only one lead per action team"} 

Figure 14-18 Working with Action Items and Team Members Using Postman