Data extraction with X-Wiki REST API

Hello :slight_smile:

I want to develop a chatbot in Node.js which can call X-Wiki thanks to its RESTful API to extract data of documents that the user needs. I tried requests with PostMan to retrieve data of a page on my X-Wiki without success. I read the documentation but I’m struggling to understand it all : http://platform.xwiki.org/xwiki/bin/view/Features/XWikiRESTfulAPI

I’m looking for some examples that could match my situation, but I couldn’t find anything.

I would be grateful if someone could give me an easy-to-understand example or some instructions?

Thanks in advance for the help :slight_smile:

What are you exactly trying to do that is not working for you ?

You have a few curl based examples in http://platform.xwiki.org/xwiki/bin/view/Features/XWikiRESTfulAPI#HUsingtheRESTfulAPI

I tried to execute these examples with curl, but if I understand the examples allow to add information to our wiki and it’s not what I want to do :frowning:

What I would like to do is call the search function of X-Wiki with the keywords that the user gave to the chatbot through the X-Wiki API, retrieve the first document that emerges from the search and return the contents of the page to the server. However, I do not understand how to do this, and when I try some queries with PostMan, I have an XML file in response but I do not see how to use it to recover the body of the document.

I do not know if it’s well explained … English is not my native language, sorry!

I have an XML file in response

Well that’s what this API (and most REST APIs) is about, you ask for information and you get a XML with the information in it that you need to parse. If your are in Java you can use JAXRS to automatically convert those XMLs into Java objects (it’s possible there is JAXRS support for other languages too but I’m not sure). You have various examples of how those files looks like in http://platform.xwiki.org/xwiki/bin/view/Features/XWikiRESTfulAPI#HFormatsoffiles and a link to the reference xsd.

You can also get a JSON instead of a XML for most of those APIs (see http://platform.xwiki.org/xwiki/bin/view/Features/XWikiRESTfulAPI#HAccessingtheservice) if it’s easier to parse for you.

Thank you for your answer. My application is in Node.js so it’s a little different, but it’s not a problem. As I said earlier, once I retrieve the response in XML (or JSON), I don’t see where the content of the page is located when I parse it. (no property content, body…)

I want to do a GET request with this endpoint (find in the doc) :
/wikis/{wikiName}/search?q={keywords}[[&scope={name,content,title,objects}…]&start=n][&number=n][&orderField=field&order={asc,desc}][distinct={true,false}][&prettyNames={true,false}]

And get a response where I can parse the content of the page I’m looking for.

“/wikis/{wikiName}/search” API return page summaries, not complete pages. In the XML you will find an element “link” which give you the URL leading to complete page API.

I am new to xWiki and I am trying to do what is described in this post. I have spent several hours experimenting with the REST API but I have not been able to achieve my goals.

As a first step, I would lto return the contents of Test Page 1, 2 or 3 in the Sandbox. I have set up my xWiki in a Docker container. I can issue the REST API GET command

http://localhost:8080/rest/wikis/xwiki/spaces/Sandbox/pages/TestPage1

with Postman. This returns the XML of TestPage1. This works great. Now that I have this working I would like to do a search for TestPage1. I tried something like this

http://localhost:8080/rest/wikis/xwiki/spaces/Sandbox/search?q=TestPage1&scope=title

It returned some search results but not what I was expecting. I am new to REST APIs and xWiki.

What am I doing wrong?
Could you provide the correct syntax for this search?
Can you recommend any references where the REST API syntax is explained? (Google is great but not all references are created equal)

Thanks for your help,

Bob

P.S. I know that this post was originally submitted in 2017. However, I saw that you are still active in the xWiki forums so I thought I try my luck.

Here is the output from the search

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>pagexwiki:Sandbox.WebHomeSandbox.WebHomeSandboxxwikiSandboxWebHome2022-03-19T21:38:32ZXWiki.bkraft42571.1xwikixwikiwikihttp://localhost:8080/bin/view/Main/SandboxSandboxspacehttp://localhost:8080/bin/view/Sandbox/WebHomeWebHomedocumenthttp://localhost:8080/bin/view/Sandbox/pagexwiki:Sandbox.WebHomeSandbox.WebHomeSandboxxwikiSandboxWebHome2022-03-19T21:38:32ZXWiki.bkraft42571.1caxwikixwikiwikihttp://localhost:8080/bin/view/Main/SandboxSandboxspacehttp://localhost:8080/bin/view/Sandbox/WebHomeWebHomedocumenthttp://localhost:8080/bin/view/Sandbox/pagexwiki:Sandbox.WebHomeSandbox.WebHomeSandboxxwikiSandboxWebHome2022-03-19T21:38:32ZXWiki.bkraft42571.1daxwikixwikiwikihttp://localhost:8080/bin/view/Main/SandboxSandboxspacehttp://localhost:8080/bin/view/Sandbox/WebHomeWebHomedocumenthttp://localhost:8080/bin/view/Sandbox/pagexwiki:Sandbox.WebHomeSandbox.WebHomeSandboxxwikiSandboxWebHome2022-03-19T21:38:32ZXWiki.bkraft42571.1dexwikixwikiwikihttp://localhost:8080/bin/view/Main/SandboxSandboxspacehttp://localhost:8080/bin/view/Sandbox/WebHomeWebHomedocumenthttp://localhost:8080/bin/view/Sandbox/pagexwiki:Sandbox.WebHomeSandbox.WebHomeSandboxxwikiSandboxWebHome2022-03-19T21:38:32ZXWiki.bkraft42571.1esxwikixwikiwikihttp://localhost:8080/bin/view/Main/SandboxSandboxspacehttp://localhost:8080/bin/view/Sandbox/WebHomeWebHomedocumenthttp://localhost:8080/bin/view/Sandbox/pagexwiki:Sandbox.WebHomeSandbox.WebHomeSandboxxwikiSandboxWebHome2022-03-19T21:38:32ZXWiki.bkraft42571.1frxwikixwikiwikihttp://localhost:8080/bin/view/Main/SandboxSandboxspacehttp://localhost:8080/bin/view/Sandbox/WebHomeWebHomedocumenthttp://localhost:8080/bin/view/Sandbox/pagexwiki:Sandbox.WebHomeSandbox.WebHomeSandboxxwikiSandboxWebHome2022-03-19T21:38:32ZXWiki.bkraft42571.1itxwikixwikiwikihttp://localhost:8080/bin/view/Main/SandboxSandboxspacehttp://localhost:8080/bin/view/Sandbox/WebHomeWebHomedocumenthttp://localhost:8080/bin/view/Sandbox/pagexwiki:Sandbox.WebHomeSandbox.WebHomeSandboxxwikiSandboxWebHome2022-03-19T21:38:32ZXWiki.bkraft42571.1lvxwikixwikiwikihttp://localhost:8080/bin/view/Main/SandboxSandboxspacehttp://localhost:8080/bin/view/Sandbox/WebHomeWebHomedocumenthttp://localhost:8080/bin/view/Sandbox/pagexwiki:Sandbox.WebHomeSandbox.WebHomeSandboxxwikiSandboxWebHome2022-03-19T21:38:32ZXWiki.bkraft42571.1pt_BRxwikixwikiwikihttp://localhost:8080/bin/view/Main/SandboxSandboxspacehttp://localhost:8080/bin/view/Sandbox/WebHomeWebHomedocumenthttp://localhost:8080/bin/view/Sandbox/pagexwiki:Sandbox.WebHomeSandbox.WebHomeSandboxxwikiSandboxWebHome2022-03-19T21:38:32ZXWiki.bkraft42571.1ruxwikixwikiwikihttp://localhost:8080/bin/view/Main/SandboxSandboxspacehttp://localhost:8080/bin/view/Sandbox/WebHomeWebHomedocumenthttp://localhost:8080/bin/view/Sandbox/pagexwiki:Sandbox.WebHomeSandbox.WebHomeSandboxxwikiSandboxWebHome2022-03-19T21:38:32ZXWiki.bkraft42571.1zhxwikixwikiwikihttp://localhost:8080/bin/view/Main/SandboxSandboxspacehttp://localhost:8080/bin/view/Sandbox/WebHomeWebHomedocumenthttp://localhost:8080/bin/view/Sandbox/pagexwiki:Sandbox.WebHomeSandbox.WebHomeSandboxxwikiSandboxWebHome2022-03-19T21:38:32ZXWiki.bkraft42571.1zh_TWxwikixwikiwikihttp://localhost:8080/bin/view/Main/SandboxSandboxspacehttp://localhost:8080/bin/view/Sandbox/WebHomeWebHomedocumenthttp://localhost:8080/bin/view/Sandbox/