What should my cursor be for my API?

Hello, I am just starting to work with API and I can not figure out how the paging cursor works and what I should put for it. Any help is much appreciated!

2 Likes

The Roblox API is a bit confusing. Basically, when you make the default request (with no page cursor), along with the data, you will also receive a nextPageCursor string. You then use this string to make a request again (same URL), but now, you’ll attach the cursor in the end. Think of a page cursor as a number (page 1, page 2, etc), but instead of being a number, it is a complex string specialized for your request.

Here is an implementation of this utilizing the clothes API in JavaScript:

async function getClothesById(userId, nextPageCursor, clothes=[]) {
    let URL = (nextPageCursor) ? `https://inventory.roblox.com/v2/users/${userId}/inventory?assetTypes=Shirt%2CPants%2CTShirt&limit=100&sortOrder=Asc&cursor=${nextPageCursor}` : `https://inventory.roblox.com/v2/users/${userId}/inventory?assetTypes=Shirt%2CPants%2CTShirt&limit=100&sortOrder=Asc`
    let response = await axios({
        method: "GET",
        url: URL,
        validateStatus: function () {
            return true;
        }
    })
    if (response.status == 200) {
        let json = response.data
        clothes = clothes.concat(json["data"])
        if (json["nextPageCursor"]) {
            return await getClothesById(userId, json["nextPageCursor"], clothes)
        } else {
            return clothes
        }
    } else if (response.status == 403) {
        return null
    } else {
        return clothes
    }
}
5 Likes

Adding onto the response from @Batimius: a cursor is essentially an array of entries. There’s a limit as to the number of entries an endpoint can return, especially when handling large volumes of data (like searching the marketplace, or a list of users), ergo you can split the number of entries that calling an endpoint will return to a sensible number, like 10 or 20.

It’s good to think of cursors as pages of an address book. Each page contains a list of entries, and you can flip the page to get the next list.

2 Likes

This is my response from the API


and I did not get any next page cursor unless if I am missing something…

No page cursor means you reached the end of the end of the list. If you get no page cursors, then end your function there and return the results. Also, there is a next page cursor. Third line:

Alright I see how it works now thank you so much!

I edited the previous reply, but the DevForum doesn’t re-notify. In your specific request, there is actually a nextPageCursor. See the image above. What you should do is take your request URL and add &cursor=[YOUR NEXT PAGE CURSOR] to the end of it, and of course, the [YOUR NEXT PAGE CURSOR] is nextPageCursor.

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.