Message Boards

API headless-admin-user not fully enabled?

Christian Langmann, modified 3 Years ago.

API headless-admin-user not fully enabled?

New Member Posts: 2 Join Date: 8/28/20 Recent Posts
Hi, I setup a vanilla Liferay instance using latest docker image (liferay/dxp:7.2.10-dxp-7). I tried to use headless-admin-user API to manage users (https://app.swaggerhub.com/apis/liferayinc/headless-admin-user/v1.0#/UserAccount) . Searching and retrieving users works (GET o/headless-admin-user/v1.0/user-accounts), but when trying to alter (PUT or PATCH) or delete an user-account (DELETE) I get an HTTP-Status 405 error (METHOD_NOT_ALLOWED).
Do I have to activate those methods somehow?  Any help is greatly appreciated!
thumbnail
Javier De Arcos, modified 3 Years ago.

RE: API headless-admin-user not fully enabled?

New Member Posts: 9 Join Date: 7/16/20 Recent Posts
The headless-admin-user API is read-only in Liferay DXP 7.2.

Write methods will be available in the next DXP 7.3 release. They are already available in the Liferay Portal CE 7.3 GA3 release
Kirk Stork, modified 2 Years ago.

RE: RE: API headless-admin-user not fully enabled?

Junior Member Posts: 33 Join Date: 5/19/10 Recent Posts

Is it really implemented in 7.3?

 

Using the docker image 

liferay/dxp:7.3.10-dxp-1

 

I try this request

POST http://localhost:8080/o/headless-admin-user/v1.0/user-accounts
Authorization: Basic test@liferay.com test
Content-Type: application/json

{
  "emailAddress": "foo@example.com",
  "familyName": "Bar",
  "givenName": "Foo",
  "x-class-name": "com.liferay.headless.admin.user.dto.v1_0.UserAccount"
}

And get

POST http://localhost:8080/o/headless-admin-user/v1.0/user-accounts

HTTP/1.1 400 
X-Content-Type-Options: nosniff
X-Frame-Options: SAMEORIGIN
X-XSS-Protection: 1
Set-Cookie: JSESSIONID=8F5887DA7E1C910775291489DD6E54E2; Path=/; HttpOnly
Date: Wed, 28 Apr 2021 13:48:46 GMT
Content-Type: application/json
Content-Length: 101
Connection: close

{
  "status": "BAD_REQUEST",
  "title": "Property \"x-class-name\" is not defined in UserAccount"
}

Response code: 400; Time: 155ms; Content length: 101 bytes

 

Christian Langmann, modified 3 Years ago.

RE: API headless-admin-user not fully enabled?

New Member Posts: 2 Join Date: 8/28/20 Recent Posts
Hi Javier,
is this documented somewhere? I haven't found anything...
What alternative is available to update a user, especially with custom fields?
I've only found http://localhost:8080/api/jsonws for update-user, but without custom-fields.
Best regardsChristian
thumbnail
Olaf Kock, modified 3 Years ago.

RE: API headless-admin-user not fully enabled?

Liferay Legend Posts: 6403 Join Date: 9/23/08 Recent Posts
Christian Langmann:

What alternative is available to update a user, especially with custom fields?
I'd expect the Expando API to be used for custom fields, not the user. Expando is the API name for Custom Fields and takes the user as parameter, as it stores the extended and custom fields.
(someone correct me if I'm wrong in the context of the headless APIs)
thumbnail
Jack Bakker, modified 3 Years ago.

RE: API headless-admin-user not fully enabled?

Liferay Master Posts: 978 Join Date: 1/3/10 Recent Posts
Using Altair extension in Chrome, looking at Liferay v7.3.4 GA5 /o/graphql, I see a updateUserAccount including for customFields. Haven't tried it yet though. I believe you also can now look at /o/api where there is an integrated GraphiQL. And if it is there for GraphQL, then it is there for REST also.
thumbnail
Javier De Arcos, modified 3 Years ago.

RE: API headless-admin-user not fully enabled?

New Member Posts: 9 Join Date: 7/16/20 Recent Posts
As Jack Bakker said, there is a new  great tool called Liferay API Explorer to explore REST endpoints and GraphQL You can access to it at o/api url. There you can find all available APIs with their endpoints and try them. You can also do the same for the GraphQL queries and mutations.Another option to check the API definition as documentation is to access the OpenAPI document that is accesible in every Liferay API at /openapi.yaml or /openapi.json. There you can read the API contract with all endpoints and allowed methods. In the case of headless-admin-user you can find it at: /o/headless-admin-user/v1.0/openapi.yaml
For what I have researched I think that at this moment the custom fields are not editable through the API like it happens with jsonws, so your options could be using the Expando API as Olaf suggested or create a custom API that uses the Liferay services to achieve what you want
Kirk Stork, modified 2 Years ago.

RE: API headless-admin-user not fully enabled?

Junior Member Posts: 33 Join Date: 5/19/10 Recent Posts

It seems there are other settings in Liferay that need to be configured in order to allow requests to these endpoints (CORS, authentication methods, etc).  Can't find any dox though --- anyone have some links?

thumbnail
Luis Miguel Barcos, modified 2 Years ago.

RE: RE: API headless-admin-user not fully enabled?

New Member Posts: 5 Join Date: 6/15/18 Recent Posts

Hi Kirk,
What exactly are you trying? The UserAccount endpoints?
AFAIK, CORS is only necessary under development if you are working with a Liferay Portal in your local machine.
Have you tried using Liferay API Explorer? The path is http://localhost:8080/o/api. You need to be logged in to the portal to use it, and you can check if the endpoints work.
If not, let us know and we will be glad to help :)

Kirk Stork, modified 2 Years ago.

RE: RE: API headless-admin-user not fully enabled?

Junior Member Posts: 33 Join Date: 5/19/10 Recent Posts

Thanks Luis,

You're right, it turns out no other config was necessary.  Some other issues I'm working through, but this one appears to be a non-issue.

 

thumbnail
Luis Miguel Barcos, modified 2 Years ago.

RE: RE: API headless-admin-user not fully enabled?

New Member Posts: 5 Join Date: 6/15/18 Recent Posts

Glad to help. If there is something more where we can help, let us know :)