Solved

Nested calls with POST API


We are struggling with nested calls in a POST API with custom body. We don't change the URI on every input, but need to change the body on every request:

We use Cursor based pagination using rows@next for pagination. And as it seems you can only use one pagination per rsd, we can only get one iteration using nested calls.

Query slicers only seem to be able to slice URI's (https://cdn.cdata.com/help/DWG/jdbc/pg_queryslicer.htm). 

In our example, we are extracting ReservationId's from a Reservation request and need them as a body input for ReservationItems in batches of 1000.

Any help would be appreciated, let me know if you need anymore information.

icon

Best answer by rory.smith 9 June 2023, 09:55

View original

12 replies

Userlevel 6
Badge +5

Do you know how many batches you would need? I mean what would the max value be.

You may be able to put it into a enum loop, that increases the values with 1000 on each iteration.

What about the ReservationIds do you get that in a list, or do you need to make a file for each one?

I'm having 62.000 Reservations. Increasing it to 1000 will make a huge difference already.

I'm now using the Query Editor to get all reservations, as they also need different timeframes per request.

Userlevel 6
Badge +5

You can make all fields an input to add it with an outside query.

I don’t know if query slicers only affect URIs, but you can make the reservation id a input, it may just need to be added as a field.

That's what I have right now, but that's not really workable. My query looks like this:

SELECT * FROM [ReservationItems] WHERE [ReservationId] = ‘1’
UNION
SELECT * FROM [ReservationItems] WHERE [ReservationId] = ‘2’
UNION
SELECT * FROM [ReservationItems] WHERE [ReservationId] = ‘3’
UNION
SELECT * FROM [ReservationItems] WHERE [ReservationId] = ‘4’
UNION, etc. for 62.000 lines

Userlevel 6
Badge +5

You can’t do a file/uri that gives the ids in a list?

If you can do a file that runs a loop just adding the ids to a single field.

You could change the query to be

SELECT * FROM [ReservationItems] WHERE [ReservationId] IN (SELECT ID FROM [ReservationIds])

then.

I can’t get that to work. It only works for me with:

WHERE ReservationId = ‘123’

This one doens't work:

WHERE ReservationId IN (‘123’)

I got ik working now with an enum picking up one item per loop. I can set it at any number I want, also >1000. However I'm still trying to find a way that it stops once it's done, as I don't know the number of iterations.

Userlevel 6
Badge +5

Hi @JeroenS 

If you can’t find the max value, just check how faster or slower it becomes if it does not have any values past a certain amount. Then you can add a value high enough that it wont be an issue.

Yeah but I'm ending up with duplicate values at the end. It keeps on looping the last Id.

Userlevel 5
Badge +7

@JeroenS ,

 

I believe it should be possible to save the highest id in a call in a global variable and build a check to detect the end of your loop. If the new highest id is equal to the last highest id then stop the loop.

Thanks Thomas and Rory.
Ended up using an enum with a very high PageCount and a global variable indicating whether the call should be executed. 

Userlevel 6
Badge +5

Hi @JeroenS 

Good, you could also use a Break() function to go out of the loop, but the other method will work as well.

Reply