Forums de discussion

json web services to get custom field

Víctor Sáez, modifié il y a 7 années.

json web services to get custom field

New Member Publications: 9 Date d'inscription: 10/03/15 Publications récentes
Hello.

I have defined a custom field for users. Is there any way to get the value of this custom field invoking json web services? what service?

Thanks very much in advanced
Víctor Sáez, modifié il y a 7 années.

RE: json web services to get custom field

New Member Publications: 9 Date d'inscription: 10/03/15 Publications récentes
Hi.

It seems a solution could be to use json web service /api/jsonws/expandovalue/get-json-data, but this service is not working for me en Java code.
If I invoke the service through url /api/jsonws/expandovalue/get-json-data and fill in the form work fine but I use the following code, it returns a empy json : {} . My Java code is :

String urlServicioExpando = "http://localhost:8080/api/jsonws/expandovalue/get-json-data"
+ "/company-id/20154"
+ "/class-name/com.liferay.portal.model.User"
+ "/table-name/CUSTOM_FIELDS"
+ "/column-name/nif"
+ "/class-pk/28402";

CloseableHttpClient httpClient = HttpClientBuilder.create().build();
String credentials = username + ":" + password;
BASE64Encoder encoder = new BASE64Encoder();
String b64 = encoder.encode(credentials.getBytes());

HttpGet request = new HttpGet(url);

String authHeader = "Basic " + new String(b64);
request.setHeader(HttpHeaders.AUTHORIZATION, authHeader);
request.addHeader("content-type", "application/json");

HttpResponse result = httpClient.execute(request);
json = EntityUtils.toString(result.getEntity(), "UTF-8");

username and password are passed to this code as a parameter and the values of ther url in property urlServicioExpando are the same values I use in form.

Any Idea.

Thanks