Forum Discussion
I've had mixed results with field and filter through the SDK. Works fine when accessing the API directly, but something about the SDK doesn't quite handle it right.
As to size and offset, they are related. Size is max number of items to fetch (regardless of group), and it defaults to 50. When you were calling without size, you were asking the API to get you the first 50 items. I've also had mixed results with the API concerning the "total" number returned not matching the actual number returned. This is why I asked what `len(api_response.items)`. That's the real way I know how many items I got back, since I can't trust the "total" number.
All of this has to do with pagination, which is pretty common when dealing with APIs. The API will only let you fetch a certain number of items at a time. This prevents a single request for 9,999,999 items from bogging down the system. LM's API does the same thing, defaulting to only returning the first 50 items unless you specify a size, which can be as high as 1000. So, when you specify a size of 1000, you will get a max of 1000 items back. If you only have 133, you'll get all 133.
But what happens if you have 1500 items? That's where offset comes in. First of all, you need to recognize that you'll have to make multiple calls to the API, since you can fetch 1000 items max per request. For 1500 items, you'll need to do 2 requests. The first request would have a size of 1000 and an offset of 0 (the default for offset). The second request needs to specify a size of 1000. An offset of 1000 would tell LM to return not the first 1000 items, but the second 1000 items.
Think of it this way: size=1000, offset=0 --> returns up to 1000 items starting with the 0th item. size=1000, offset=1000 --> returns up to 1000 items starting with the 1000th item. Size=1000, offset=2000 would return 1000 items starting with the 2000th item.
Example code of how to do pagination coming up...
Related Content
- 2 years ago
- 2 years ago