REST API ignores type parameter

classic Classic list List threaded Threaded
8 messages Options
Reply | Threaded
Open this post in threaded view
|

REST API ignores type parameter

Mark Sack
I'm trying to use the REST API to retrieve some data but the API seems to be ignoring the type parameter.
My environment is XWiki 7.4.2, Debian 8, PostgreSQL, Tomcat 8, Openjdk 8

If I try to fetch some data using the browser and the following URL:

http:// ... /rest/wikis/query?q=select%20obj.first_name,obj.last_name%20from%20Document%20doc,%20doc.object%28XWiki.XWikiUsers%29%20as%20obj&type=xwql

the result is as follows (I'm reproducing here only the first few lines - there are actually 10 items returned)

<searchResults template="http://10.1.16.192:8080/wiki/rest?q={solrquery}(&number={number})(&start={start})(&orderField={fieldname}(&order={asc|desc}))(&distinct=1)(&prettyNames={false|true})(&wikis={wikis})(&className={classname})"><searchResult><link href="http://10.1.16.192:8080/wiki/rest/wikis/xwiki/spaces/XWiki/pages/DocumentTreeMacros" rel="http://www.xwiki.org/rel/page"/><type>page</type><id>xwiki:XWiki.DocumentTreeMacros</id><pageFullName>XWiki.DocumentTreeMacros</pageFullName><wiki>xwiki</wiki><space>XWiki</space><pageName>DocumentTreeMacros</pageName><modified>2016-02-15T12:14:34-03:00</modified><author>xwiki:XWiki.Admin</author><version>4.1</version><score>0.75986093</score></searchResult><searchResult><link href="http://10.1.16.192:8080/wiki/rest/wikis/xwiki/spaces/Panels/pages/DocumentInformation" rel="http://www.xwiki.org/rel/page"/><type>page</type><id>xwiki:Panels.DocumentInformation</id><pageFullName>Panels.DocumentInformation</pageFullName><wiki>xwiki</wiki><space>Panels</space><pageName>DocumentInformation</pageName><modified>2016-01-12T09:56:52-03:00</modified><author>xwiki:XWiki.superadmin</author><version>1.1</version><score>0.63381535</score></searchResult>

The result is not related in any way to the user data or their names. From the template on the first line, it seems to think that the query is a SOLR query not xwql. I've verified that the query is correct xwql syntax and gives a valid result by trying it in a velocity script on an actual xwiki page. The result is basically the same if I just query for the first name instead of both the first name and last name.

How should I be executing xwql queries using the REST API?

Regards
Mark Sack
Reply | Threaded
Open this post in threaded view
|

Re: REST API ignores type parameter

Marius Dumitru Florea
Did you check
http://platform.xwiki.org/xwiki/bin/view/Features/XWikiRESTfulAPI#HRootresources
?

/wikis/query
[since 6.4] using a SOLR query (there's no type parameter)

/wikis/{wikiName}/query
Allow to execute HQL, XWQL, Lucene or SOLR queries on the given {wikiName}.
(has a type parameter)

The first is a cross wiki query/search, that cannot be performed with HQL
or XWQL because each wiki is stored in a separate database schema. Solr on
the other hand keeps an external index (outside the database) that is cross
wiki.

The second REST resource targets a specific wiki (database) which allows
you to use XWQL.

Hope this helps,
Marius

On Tue, May 24, 2016 at 3:33 PM, Mark Sack <[hidden email]>
wrote:

> I'm trying to use the REST API to retrieve some data but the API seems to
> be
> ignoring the type parameter.
> My environment is XWiki 7.4.2, Debian 8, PostgreSQL, Tomcat 8, Openjdk 8
>
> If I try to fetch some data using the browser and the following URL:
>
> http:// ...
>
> /rest/wikis/query?q=select%20obj.first_name,obj.last_name%20from%20Document%20doc,%20doc.object%28XWiki.XWikiUsers%29%20as%20obj&type=xwql
>
> the result is as follows (I'm reproducing here only the first few lines -
> there are actually 10 items returned)
>
> <searchResults
> template="
> http://10.1.16.192:8080/wiki/rest?q={solrquery}(&number={number})(&start={start})(&orderField={fieldname}(&order={asc|desc}))(&distinct=1)(&prettyNames={false|true})(&wikis={wikis})(&className={classname})
> "><searchResult><link
> href="
> http://10.1.16.192:8080/wiki/rest/wikis/xwiki/spaces/XWiki/pages/DocumentTreeMacros
> "
> rel="http://www.xwiki.org/rel/page
> "/><type>page</type><id>xwiki:XWiki.DocumentTreeMacros</id><pageFullName>XWiki.DocumentTreeMacros</pageFullName><wiki>xwiki</wiki><space>XWiki</space><pageName>DocumentTreeMacros</pageName><modified>2016-02-15T12:14:34-03:00</modified><author>xwiki:XWiki.Admin</author><version>4.1</version><score>0.75986093</score></searchResult><searchResult><link
> href="
> http://10.1.16.192:8080/wiki/rest/wikis/xwiki/spaces/Panels/pages/DocumentInformation
> "
> rel="http://www.xwiki.org/rel/page
> "/><type>page</type><id>xwiki:Panels.DocumentInformation</id><pageFullName>Panels.DocumentInformation</pageFullName><wiki>xwiki</wiki><space>Panels</space><pageName>DocumentInformation</pageName><modified>2016-01-12T09:56:52-03:00</modified><author>xwiki:XWiki.superadmin</author><version>1.1</version><score>0.63381535</score></searchResult>
>
> The result is not related in any way to the user data or their names. From
> the template on the first line, it seems to think that the query is a SOLR
> query not xwql. I've verified that the query is correct xwql syntax and
> gives a valid result by trying it in a velocity script on an actual xwiki
> page. The result is basically the same if I just query for the first name
> instead of both the first name and last name.
>
> How should I be executing xwql queries using the REST API?
>
> Regards
> Mark Sack
>
>
>
> --
> View this message in context:
> http://xwiki.475771.n2.nabble.com/REST-API-ignores-type-parameter-tp7599586.html
> Sent from the XWiki- Users mailing list archive at Nabble.com.
> _______________________________________________
> users mailing list
> [hidden email]
> http://lists.xwiki.org/mailman/listinfo/users
>
_______________________________________________
users mailing list
[hidden email]
http://lists.xwiki.org/mailman/listinfo/users
Reply | Threaded
Open this post in threaded view
|

Re: REST API ignores type parameter

Mark Sack
You're right - I was missing the wiki name. But, for some reason, I still can't get the queries to work. Here is what I've found so far.

There is only one wiki - confirmed by the following REST call: http://10.1.16.192/wiki/rest/wikis/ which returns

<wikis><link href="http://10.1.16.192:8080/wiki/rest/wikis/query" rel="http://www.xwiki.org/rel/query"/><wiki><link href="http://10.1.16.192:8080/wiki/rest/wikis/xwiki/spaces" rel="http://www.xwiki.org/rel/spaces"/><link href="http://10.1.16.192:8080/wiki/rest/wikis/xwiki/classes" rel="http://www.xwiki.org/rel/classes"/><link href="http://10.1.16.192:8080/wiki/rest/wikis/xwiki/modifications" rel="http://www.xwiki.org/rel/modifications"/><link href="http://10.1.16.192:8080/wiki/rest/wikis/xwiki/search" rel="http://www.xwiki.org/rel/search"/><link href="http://10.1.16.192:8080/wiki/rest/wikis/xwiki/query" rel="http://www.xwiki.org/rel/query"/><id>xwiki</id><name>xwiki</name></wiki></wikis>

I can get some information about the wiki using http://10.1.16.192/wiki/rest/wikis/xwiki/ which returns

<wiki><link href="http://10.1.16.192:8080/wiki/rest/wikis/xwiki/spaces" rel="http://www.xwiki.org/rel/spaces"/><link href="http://10.1.16.192:8080/wiki/rest/wikis/xwiki/classes" rel="http://www.xwiki.org/rel/classes"/><link href="http://10.1.16.192:8080/wiki/rest/wikis/xwiki/modifications" rel="http://www.xwiki.org/rel/modifications"/><link href="http://10.1.16.192:8080/wiki/rest/wikis/xwiki/search" rel="http://www.xwiki.org/rel/search"/><link href="http://10.1.16.192:8080/wiki/rest/wikis/xwiki/query" rel="http://www.xwiki.org/rel/query"/><id>xwiki</id><name>xwiki</name></wiki>

I can get a list of spaces in the wiki using http://10.1.16.192/wiki/rest/wikis/xwiki/spaces/
I won't reproduce the results as it is quite long but it looks correct and includes those that I've added.

But if I try to do a simple query such as

.../rest/wikis/xwiki/query?q=select+obj.first_name+from+Document+doc%2C+doc.object%28XWiki.XWikiUsers%29+as+obj&type=xwql

the result is

<searchResults template="http://10.1.16.192:8080/wiki/rest/wikis/xwiki/query?q={query}(&type={type})(&number={number})(&start={start})(&orderField={fieldname}(&order={asc|desc}))(&distinct=1)(&prettyNames={false|true})(&wikis={wikis})(&className={classname})"/>

whereas the same query executed in velocity (without the URL encoding) returns the correct result.

This is again probably some simple item I've overlooked. I appreciate your help in resolving this problem.

Regards
Mark Sack

Reply | Threaded
Open this post in threaded view
|

Re: REST API ignores type parameter

Marius Dumitru Florea
On Wed, May 25, 2016 at 3:00 PM, Mark Sack <[hidden email]>
wrote:

> You're right - I was missing the wiki name. But, for some reason, I still
> can't get the queries to work. Here is what I've found so far.
>
> There is only one wiki - confirmed by the following REST call:
> http://10.1.16.192/wiki/rest/wikis/ which returns
>
> <wikis><link href="http://10.1.16.192:8080/wiki/rest/wikis/query"
> rel="http://www.xwiki.org/rel/query"/><wiki><link
> href="http://10.1.16.192:8080/wiki/rest/wikis/xwiki/spaces"
> rel="http://www.xwiki.org/rel/spaces"/><link
> href="http://10.1.16.192:8080/wiki/rest/wikis/xwiki/classes"
> rel="http://www.xwiki.org/rel/classes"/><link
> href="http://10.1.16.192:8080/wiki/rest/wikis/xwiki/modifications"
> rel="http://www.xwiki.org/rel/modifications"/><link
> href="http://10.1.16.192:8080/wiki/rest/wikis/xwiki/search"
> rel="http://www.xwiki.org/rel/search"/><link
> href="http://10.1.16.192:8080/wiki/rest/wikis/xwiki/query"
> rel="http://www.xwiki.org/rel/query
> "/><id>xwiki</id><name>xwiki</name></wiki></wikis>
>
> I can get some information about the wiki using
> http://10.1.16.192/wiki/rest/wikis/xwiki/ which returns
>
> <wiki><link href="http://10.1.16.192:8080/wiki/rest/wikis/xwiki/spaces"
> rel="http://www.xwiki.org/rel/spaces"/><link
> href="http://10.1.16.192:8080/wiki/rest/wikis/xwiki/classes"
> rel="http://www.xwiki.org/rel/classes"/><link
> href="http://10.1.16.192:8080/wiki/rest/wikis/xwiki/modifications"
> rel="http://www.xwiki.org/rel/modifications"/><link
> href="http://10.1.16.192:8080/wiki/rest/wikis/xwiki/search"
> rel="http://www.xwiki.org/rel/search"/><link
> href="http://10.1.16.192:8080/wiki/rest/wikis/xwiki/query"
> rel="http://www.xwiki.org/rel/query
> "/><id>xwiki</id><name>xwiki</name></wiki>
>
> I can get a list of spaces in the wiki using
> http://10.1.16.192/wiki/rest/wikis/xwiki/spaces/
> I won't reproduce the results as it is quite long but it looks correct and
> includes those that I've added.
>
> But if I try to do a simple query such as
>
>
> .../rest/wikis/xwiki/query?q=select+obj.first_name+from+Document+doc%2C+doc.object%28XWiki.XWikiUsers%29+as+obj&type=xwql
>
> the result is
>
> <searchResults
> template="
> http://10.1.16.192:8080/wiki/rest/wikis/xwiki/query?q={query}(&type={type})(&number={number})(&start={start})(&orderField={fieldname}(&order={asc|desc}))(&distinct=1)(&prettyNames={false|true})(&wikis={wikis})(&className={classname})
> "/>
>
> whereas the same query executed in velocity (without the URL encoding)
> returns the correct result.
>

I checked the code and it seems you are not allowed to use full statements
(i.e. that start with 'select'). You have to use instead:

, <additional FROM clause> where ...

or

where ...

Unfortunately using a short query is not enough for XWQL. It seems the code
doesn't do anything special for XWQL query type and it treats it as HQL. So
for now you'll have to rely on HQL. See
http://extensions.xwiki.org/xwiki/bin/view/Extension/Query+Module .

You should probably report a bug regarding the fact that XWQL cannot be
used.

Hope this helps,
Marius


>
> This is again probably some simple item I've overlooked. I appreciate your
> help in resolving this problem.
>
> Regards
> Mark Sack
>
>
>
>
>
> --
> View this message in context:
> http://xwiki.475771.n2.nabble.com/REST-API-ignores-type-parameter-tp7599586p7599636.html
> Sent from the XWiki- Users mailing list archive at Nabble.com.
> _______________________________________________
> users mailing list
> [hidden email]
> http://lists.xwiki.org/mailman/listinfo/users
>
_______________________________________________
users mailing list
[hidden email]
http://lists.xwiki.org/mailman/listinfo/users
Reply | Threaded
Open this post in threaded view
|

Re: REST API ignores type parameter

Mark Sack
Created http://jira.xwiki.org/browse/XWIKI-13458
Please check that I got all of the parameters right.

Thanks for your help.

Mark Sack
Reply | Threaded
Open this post in threaded view
|

Re: REST API ignores type parameter

Mark Sack
In reply to this post by Marius Dumitru Florea
For some reason, I can't get the select query to work as HQL either. I picked a simple query (as a test) from
http://platform.xwiki.org/xwiki/bin/view/DevGuide/velocityHqlExamples
and confirmed that it works in a velocity script in a test page.

But when I try to use the same query in the rest interface, the response is as follows:

Not Found

The server has not found anything matching the request URI

You can get technical details here.
Please continue your visit at our home page.

The rest url I used is as follows:

../rest/wikis/xwiki/query=q?select+obj.name+from+BaseObject+obj+where+obj.className%3D%27XWiki.XWikiUsers%27&type=hql

Regards
Mark Sack
Reply | Threaded
Open this post in threaded view
|

Re: REST API ignores type parameter

Marius Dumitru Florea
On Fri, May 27, 2016 at 4:46 PM, Mark Sack <[hidden email]>
wrote:

> For some reason, I can't get the select query to work as HQL either. I
> picked
> a simple query (as a test) from
> http://platform.xwiki.org/xwiki/bin/view/DevGuide/velocityHqlExamples
> and confirmed that it works in a velocity script in a test page.
>
> But when I try to use the same query in the rest interface, the response is
> as follows:
>
> Not Found
>
> The server has not found anything matching the request URI
>
> You can get technical details here.
> Please continue your visit at our home page.
>
> The rest url I used is as follows:
>
>

> ../rest/wikis/xwiki/query=q?select+obj.name
> +from+BaseObject+obj+where+obj.className%3D%27XWiki.XWikiUsers%27&type=hql
>

I just said you cannot use full statements :). This works for me

/xwiki/rest/wikis/xwiki/query?q=where+doc.space=%27Main%27&type=hql

and  this also

/xwiki/rest/wikis/xwiki/query?q=,+BaseObject+as+obj+where+doc.fullName+%3D+
obj.name+and+obj.className+=+%27XWiki.XWikiUsers%27&type=hql

See http://extensions.xwiki.org/xwiki/bin/view/Extension/Query+Module .

Hope this helps,
Marius


>
> Regards
> Mark Sack
>
>
>
> --
> View this message in context:
> http://xwiki.475771.n2.nabble.com/REST-API-ignores-type-parameter-tp7599586p7599695.html
> Sent from the XWiki- Users mailing list archive at Nabble.com.
> _______________________________________________
> users mailing list
> [hidden email]
> http://lists.xwiki.org/mailman/listinfo/users
>
_______________________________________________
users mailing list
[hidden email]
http://lists.xwiki.org/mailman/listinfo/users
Reply | Threaded
Open this post in threaded view
|

Re: REST API ignores type parameter

Mark Sack
Sorry - I misread your explanation as only applying to XWQL. But without full statements the call just retrieves specific documents. I want a call that retrieves specific attributes of the users.

I'll be very specific about what I'm trying to accomplish:
- I've added a date field to the user profile that contains the user's birthday. The year is not entered or displayed so it defaults to 1970 in the database.
- With a single REST call, I want to retrieve the first name, last name, birthday and avatar image of all the users who are not hidden and whose birthday is in a specific month (typically the current month).

I can figure out the where part of the clause . But without the select part of the clause, it is not clear how I can retrieve multiple attributes in a single statement. I hope this helps clarify where I'm stuck.

Regards
Mark