Ask Questions and Find Answers
Important:
Ask is now read-only. You can review any existing questions and answers, but not add anything new.
But - don't panic! While ask is no more, we've replaced it with discuss - the new Liferay Discussion Forum! Read more here here or just visit the site here:
discuss.liferay.com
Bug: 404-error in RESTful service for custom object
Short description
GET or POST on the RESTful service automatically deployed for a custom object causes a 404-error.
How to reproduce
Go into Control Panel => Object / Objects.
Click the "+"-button to create a new object.
Enter some data -- which does not matter, but here's my example:
- Label: Blabla
- Plural label: Blablas
- Object name: Blabla
Click "Save".
The new object is now listed in the table. Click on "Blabla" in this table to edit it further.
Click on the tab "Fields".
Click on the "+" to add a new field. Here's what I entered:
- Label: Owner
- Field name: owner
- Type: Text
Click "Save".
Now switch to the tab "Details" and click "Publish" to publish the object. Liferay confirms in a small green box that it published it.
Open a new tab in the browser and go to the "Liferay API Explorer" -- mine is on: https://dragonkingchocolate.com/liferay/o/api
Click on "REST Applications" and the newly added object is available as RESTful API there: c/blablas
Select "c/blablas" from the drop-down.
Click on "GET / getBlablasPage" for querying the list of the objects. It opens the details for this RESTful operation.
Click on "Execute". I'd expect an empty list (with some meta-data being present), i.e. one single instance of the BlablasPage without any items. But I get a 404-error.
Click on "POST / postBlabla". The JSON to be sent doesn't really matter, because all data should be optional, but neither a full-blown JSON nor a minimal "{}" or "{ "owner": "abc" }" works -- all leads to a 404-error.
Liferay version
Liferay Community Edition Portal 7.4.3.129 CE GA129 (December 09, 2024)
Liferay Community Edition Portal 7.4.3.120 CE GA120 (June 12, 2024)
...the error is the same in both versions.
Page-building works
Note that the building of a page to list/create/edit/delete instances of my custom object works fine. My object seems to be fully functional in the page I created for it -- but the RESTful API only gets 404-errors.
Hi Marco, you said:
Click on "POST / postBlabla". The JSON to be sent doesn't really matter, because all data should be optional, but neither a full-blown JSON nor a minimal "{}" or "{ "owner": "abc" }" works -- all leads to a 404-error.
This does not seem to be true. Try posting with just this request body:
{
"owner": "blabla"
}
I had no issue at all with the GET request, it returned a 200 for me.
The only caveat is that I did not test on the exact versions you mentioned. I'm on a more recent build, DXP U131.
Thanks a lot for your reply!
Since the "owner" is optional, it should also work fine with an empty JSON-object according to my understanding of an ordinary RESTful resource (not specifically Liferay, but REST in general).
But as I already pointed out in my original post, I tried many different variations, including the one you mentioned (with the "owner" only) and even a full-blown object with all properties. None of them worked. Also, the GET / should IMHO always work (even before creating the first object, leading to an empty "page"-JSON) -- but all of them give me a 404.
I should also mention that I use Liferay in docker. Maybe this makes a difference.
=> https://hub.docker.com/r/liferay/portal
=> image: liferay/portal:7.4.3.129-ga129
Powered by Liferay™