I work with the JSONAPI and I noticed that I got an error message:
{
"jsonapi": {
"version": "1.0",
"meta": {}
},
"errors": [
{
"title": "Unprocessable Entity",
"status": "422",
"detail": "name: This value should not be null.",
"source": {
"file": "/foo......./modules/jsonapi/src/Entity/EntityValidationTrait.php",
"line": 59,
"pointer": "/data/attributes/name"
},
"meta": {
which was a suprise to me because I have setup the auto-pattern for the name
field.
Instead of manually entering a name on each Storage entity within a form, you can define a name pattern here for auto-generating a value for it. This pattern will be applied everytime a Storage entity is being saved. Tokens are allowed, e.g. [storage:string-representation]. Leave empty to not use a name pattern for entities of this Storage type. If a name pattern is being used, you may optionally hide the name field in the Manage form display settings.
I just noticed, that the help description is talks about a form, as an example how useful it might be to use a pattern.
How to reproduce
- Create a storage type bernd
- create a plain text field with name 'label'
- setup the autofill pattern for the storage engine name as [storage:field_label:value]
- hide the name
field as suggested
- create a storage entity bernd
via Drupal UI and notice, that just filling the Label will successfully create the storage entity.
- notice, if module devel is installed, that the name field is filled with the same name as the field_label
- fire up Postman or your favorite REST client.
- use the correct JSONAPI call to create a storage entity of typ 'bernd'.
POST body
{
"data": {
"type": "storage--bernd",
"attributes": {
"field_label": "Karlzz"
}
}
}
You'll get the error message shown above, that the "name: This value should not be null." cannot be null. Which - in my case - is unexpected, because I have setup an auto-pattern to fill it.