Solved

Pagination question for TX Rest datasource

  • 11 June 2024
  • 6 replies
  • 42 views

Userlevel 2
Badge +1

I have a REST datasource that uses pagination with URL paramater page. Fairly simple.

The next page (if there is one) is returned not as a header but as an element in the json result:

 

 

So, to enable paging I have to set up something like this:
 

And:

I have two questions on this: I get an error on the XPath Value saying ‘Expression must evaluate to a node-set.’ . How do I determine the correct XPath to the json element? And my second question is how do I make sure the complete URL is replaced instead of only the /api/… part?

icon

Best answer by wouter.goslinga 11 June 2024, 14:02

View original

6 replies

Userlevel 6
Badge +5

Hi @wouter.goslinga 

If you start by set up a call without pagination you will get a xml file that you can locate if you use caching to a file. It should contain the proper XPath value for the hydra.next field.

For reference see the Graph API guide.

So perhaps, it will work like this.

 /TX_Autogenerated_Root/TX_Autogenerated_Element/hydra:view/hydra:next

Userlevel 2
Badge +1

Hi @Thomas Lind 

The file cache gives me the following:

 

So I've tried setting the XPath to your suggestion because it looks spot on:

I've also added the sql expression to add the value in the ‘next’ field to create a new URI.

And of course use it:
 

But now when I sync the data source I get the error:

System.Xml.XPath.XPathException: Namespace prefix 'hydra' is not defined.

Userlevel 6
Badge +5

Why do you need the SQL expression, wouldn’t it just add the whole thing to the base url?

Userlevel 6
Badge +5

Alternatively you could change the Replaced URL to be 

https:/baseurl/{nextpage}

instead of doing it in the SQL expression.

Userlevel 2
Badge +1

That would make it simpler, I have changed that but the problem arises sooner in the XPath. It does not support the custom namespace hydra: prefix in the element.

Userlevel 2
Badge +1

@Thomas Lind  as it turns out, it's not possible to use custom namespaces (i.e. the ‘hydra:’ prefix in the element) in an XPath. So I had to change the XPath to:

 

/TX_Autogenerated_Root/TX_Autogenerated_Element/*["view"=local-name()]/*["next"=local-name()]

Instead of:

/TX_Autogenerated_Root/TX_Autogenerated_Element/hydra:view/hydra:next

 

Reply