When creating or updating a resource, you may need to validate it without actually saving the data. The validate operation runs all validations and returns any errors, but rolls back the database transaction so no data is persisted.
How to enable
Validation must be enabled per resource in config/api.yml:
api:
entities:
Oro\Bundle\OrderBundle\Entity\Order:
documentation_resource: '@OroOrderBundle/Resources/doc/api/order.md'
enable_validation: true
Once enabled, the resource documentation in the API Sandbox will contain a corresponding note.
Trigger validation
Set the validate option to true in the meta section of the request body. The validate operation is supported by POST and PATCH requests.
The validate operation rolls back the database transaction, which also prevents asynchronous operations (e.g., search reindexing, sending emails). If you enable validation on an entity, ensure no irreversible operations are performed during create or update actions for that entity.
Examples
POST validate
Request
POST /api/orders HTTP/1.1
Content-Type: application/vnd.api+json
Accept: application/vnd.api+json
Request body
{
"data": {
"type": "orders",
"meta": {
"validate": true
},
"attributes": {
"identifier": "FR1012401Z",
"poNumber": "CV032342USDD"
}
}
}
PATCH validate
Request
PATCH /api/orders/1 HTTP/1.1
Content-Type: application/vnd.api+json
Accept: application/vnd.api+json
Request body
{
"data": {
"type": "orders",
"id": "1",
"meta": {
"validate": true
},
"attributes": {
"customerNotes": "Please, call before delivery"
}
}
}