New Entity Instance Creation Error

Hi,
I’m trying to create a new entity through the Rest API by following
the office guide CUBA REST API

I followed these steps:

  1. Created a new CUBA project with version 7.2.7 of the CUBA framework
    test_cuba_project.zip (371.3 KB)

with Mysql server 5.7.29
test_db.zip (8.7 KB)

  1. I added the Add-ons rest API (com.haulmont.addon.restapi:restapi-global:7.2.1)

  2. I created a simple “test_NewEntity” entity and creating a single string field

  3. I started the application directly from CUBA Studio (latest version)

  4. From admin UI I created a new “REST” role where I enabled the ability to create new instances of the entity and enabled the use of the rest API

  5. I have assigned the role “REST” to the Admin

  6. From postman I logged into the application as admin usr and got the token
    {
    “access_token.” “4df23e8f-65a8-450f-b53a-e50a201547c3”,
    “token_type”: “bearer”,
    “refresh_token.” “f69e9b82-b1f9-426f-852d-54b3fc3d0c38”,
    “expires_in”: 43199,
    “brooms.” “rest-api”
    }

  7. With postman I send a http POST as indicated in the online guide
    CUBA REST API

with the body :
{
“entityName.” “test_NewEntity”,
“testField”: “test_value”
}

but I get this response:
[
{
“message.” “may not be null.”
“messageTemplate.” “{javax.validation.constraints.NotNull.message}”,
“path.” “testField.”
“invalidValue”: null
}
]

Can you please give me some suggestions?
Thanks Massimo

Hi, @massimo.perani1

It looks like you haven’t set permissions to modify the attributes of the “test_NewEntity”.
That’s why the value of “testField” is not set to the entity. And because of the “testField” is marked as NotNull, you get the error.

You can set entity attribute permissions in the Role editor screen, on the Attributes tab.

Regards,
Gleb

Hi Gleb!
Thanks for your answer
You’re absolutely right, I added permissions and now it works.

Thanks again
Massimo

I just got bit by that same thing.

It’d probably be better if the API replied with an access denied to the field, rather that silently dropping the values. If that weren’t a NotNull field one could end up loosing data without realising it