Skip to main content

How can I access the HTTP Response Headers when retrieving data from the CData Rest Connector?


I need to read values from it to set up pagination in the .rsd file. In my case it contains the current page, records per page and total number of records.

Hi Madelon


In my case I always use the PostMan program. It shows me all available options and the xpath to them.


With http it may be different. Can you make it show a specific page and number of records by ending the uri with ?page=2&rows=100 or similar?

It may be that you can just connect to them with a mapped path to json\currentPage and json\pages.


Hi Thomas,

Thank you for your response!

Yes, I can point to any specific page by using ?page=2&per_page=25 (25 is default) 

The problem is the total number of pages. The request returns these headers, where Page is the current page, per-page is the nr of rows per page and total is the total number of rows:

So I would need to calculate: total / per-page = nr of pages, or at least know the total and set per-page fixed to 25.

I just can't seem to retrieve these values from the headers. I know I need to map them:

<api:set attr="elementmappath#1" value="/json/total" />
<api:set attr="elementmapname#1" value="total" />

But I don't think the xpath is correct.


Hi Madelon

I would set the per_page to 1 and then use the total as the max amount of pages.

I have also seen that sometimes the max amount of pages isn't shown or usable and then that is the best solution.

If it doesn't seem to work with total, does it give an error? If not try to set up an log in the REST CData provider.

 


Hi Thomas,


It does give me an error. The element mapping does not seem to work. When I try to use the value of total: 


Error: Formatter total ] failed in the evaluation of output.total]. The error was: The value of the attribute could not be accessed: The attribute does not exist.


When I use any arbitrary number for the last page, the script works, but if I try to pass a value from the header this error occurs. 


My guess is that the xpath for it is incorrect, but I don't know what it should be. Can I see that in PostMan?


Hi Madelon

Yes, I suppose you can. If you want I can take a look at it, but I would probably require some login info which maybe isn't something I am allowed to see or use.


Send the request to support@timextender.com


That is also me by the way.


Reply