Validation

In this guide, we will talk about how validation works with the Wunderite API.

When you send a request, the Wunderite API will validate all parameters and return a 422 status code with a message and a list of validation errors if there are any.


List requests

Each endpoint has a list of available filters, sorts, and includable relations in the object model. Values specified in the filters, sorts, and includes are validated appropriately, and will be returned as part of the validation response if there are any errors.

Example

Example request

GET
/api/v1/risks/{risk}/data/buildings
curl -X GET https://app.wunderite.com/api/v1/risks/{risk}/data/buildings \
-H "Authorization: Bearer {token}" \
-H "Content-Type: application/json" \
-d 'include=foo,bar'

Example response

{
  "message": {
    "include": ["Requested include(s) [foo, bar] are not supported."]
  },
  "status": 422,
  "validation": true
}

Create requests

Each endpoint has a list of available properties and includable relations in the object model. Make sure to note which fields are required! Values specified in the request body are validated appropriately, and will be returned as part of the validation response if there are any errors.

Example

Example request

POST
/api/v1/risks/{risk}/data/buildings
curl -X POST https://app.wunderite.com/api/v1/risks/{risk}/data/buildings \
-H Authorization: Bearer {token} \
-H Content-Type: application/json \
-d '{
  "data": [
    {
      "object": "building",
      "data": {
        "number": 1
      }
    }
  ]
}'

Example response

{
  "message": {
    "data.0.data.premise": ["The premise field is required."]
  },
  "status": 422,
  "validation": true
}

Update requests

Each endpoint has a list of available properties in the object model. Values specified in the request body are validated appropriately, and will be returned as part of the validation response if there are any errors.

Example

Example request

PATCH
/api/v1/risks/{risk}/data
curl -X POST https://app.wunderite.com/api/v1/risks/{risk}/data \
-H Authorization: Bearer {token} \
-H Content-Type: application/json \
-d '{
  "data": [
    {
      "object": "building",
      "data": {
        "number": "this-is-not-a-number"
      }
    }
  ]
}'

Example response

{
  "message": {
    "data.0.data.number": ["The number field is not a number."]
  },
  "status": 422,
  "validation": true
}

Delete requests

Delete requests are the most simple in terms of validation. They only require a valid object and uuid pair that you have access to delete.

Example

Example request

PATCH
/api/v1/risks/{risk}/data
curl -X POST https://app.wunderite.com/api/v1/risks/{risk}/data \
-H Authorization: Bearer {token} \
-H Content-Type: application/json \
-d '{
  "data": [
    {
      "object": "building",
      "uuid": "8f2c9f0a-cd6a-4ea7-9ed3-b5d013d01c5b"
    }
  ]
}'

Example response

{
  "message": {
    "data.0.uuid": ["The UUID provided could not be found in the risk profile."]
  },
  "status": 422,
  "validation": true
}

Dry-run validation

Validation can be run to test that provided data is valid without operations occurring on the corresponding objects. This is helpful if you want to provide immediate UI feedback as changes are being made without committing to the changes.

  • To conduct a dry-run, you can set a Precognition header with a value of true in applicable requests.
  • For a successful validation, the response will come back with a 204 status code and a Precognition-Success header with a value of true.
  • For a failed validation, the response will come back with a 422 status code and a Precognition-Success header with a value of false, as well as a list of validation errors as normal.

Example request

POST
/api/v1/risks/{risk}/data/buildings
curl -X POST https://app.wunderite.com/api/v1/risks/{risk}/data/buildings \
-H "Authorization: Bearer {token}" \
-H "Content-Type: application/json" \
-H "Precognition: true" \
-d '{
  "data": [
    {
      "object": "building",
      "data": {
        "premise": "8f2c9f0a-cd6a-4ea7-9ed3-b5d013d01c5b",
        "number": 1
      }
    }
  ]
}'

Example success response

HTTP/1.1 204 No Content
Content-Type: application/json
Precognition-Success: true

Example failure response

HTTP/1.1 422 Unprocessable Entity
Content-Type: application/json
Precognition-Success: false
{
  "message": {
    "data.0.data.number": ["The data.0.data.number field is required."]
  },
  "status": 422,
  "validation": true
}