cancel
Showing results for 
Search instead for 
Did you mean: 

Search through REStful Api

lakshya
Champ in-the-making
Champ in-the-making
Hello,
I need to run POST /alfresco/service/api/query

Code I have written for it is :
       URL = "http://localhost:8081/alfresco/service/api/query";
       PostMethod method = new PostMethod(URL);
       String filePath = "query.xml";
       String contentType = "application/atom+xml;type=query"; // tried with "application/cmsrequest+xml;type=query" also

       File upload = new File(filePath);      
       method.setRequestHeader("name", upload.getName());
       method.setRequestHeader("Content-type", contentType);
       method.setRequestBody(new FileInputStream(upload));
       client.executeMethod(method);
       System.out.println(method.getResponseBodyAsString());

and query.xml is:
<?xml version="1.0"?>
<query xmlns="http://www.cmis.org/CMIS/2008/05">
    <statement>SELECT * FROM document</statement>
   <searchAllVersions>false</searchAllVersions>
    <pageSize>0</pageSize>
    <skipCount>0</skipCount>
    <returnAllowableActions>false</returnAllowableActions>
    </query>

I am getting the following error:
org.alfresco.service.cmr.repository.TemplateException -
Error during processing of the template 'Expression statement is undefined on line 12, column 58 in org/alfresco/repository/search/query.post.atomfeed.ftl.'. Please contact your system administrator.</td></tr>

Can anyone help me out to get the way for sending query through RESt.

Regards,
4 REPLIES 4

sangireddi
Champ in-the-making
Champ in-the-making
hi …did u get success for this one…?
can u share with us?i also have similar requirement…
thanks in advance

lakshya
Champ in-the-making
Champ in-the-making
Sorry…
I didn't get the result from that, later i tried
http://wiki.alfresco.com/wiki/2.1_REST_API#Alfresco_Keyword_Search_.28OpenSearch_Enabled.29

with GET method. It works.

Regards

paulraby
Champ in-the-making
Champ in-the-making
For reference of anyone else who gets stuck with this the content type should be: application/cmisquery+xml

There should be nothing following it, and the 'a' in application must be lower case, not upper case.

lakshya
Champ in-the-making
Champ in-the-making
Thanks  paulraby

Now I am able to get search results from POST request also by providing content type : application/cmisquery+xml.
But it gives all documents of specified folder.
I want to search on the basis of keyword.

Where & How can I pass the search keyword???

I am passing the query as :
<?xml version="1.0"?>
<query>
<statement>SELECT * FROM Document WHERE IN_FOLDER('workspace://SpacesStore/4b66ac62-192d-419a-8991-a472d05cec52')</statement>
<searchAllVersions>false</searchAllVersions>
<pageSize>0</pageSize>
<skipCount>0</skipCount>
<returnAllowableActions>false</returnAllowableActions>
</query>