1

I have a problem with getting all SP list item (257 currently) with fetch.

I have the following code:

var tasks = new Request(
        webUrl + "/_api/web/lists/GetByTitle('" + listName + "')/items?$top=300"
    , {
        method: "GET",
        credentials: 'same-origin',    
        headers: new Headers({
            "Accept": "application/json; odata=nometadata",
        })
    });


    fetch(tasks)
        .then((response) => response.json())
        .then((data) => {
            let items = data.value;
            console.log('Van: ' + data["@odata.nextLink"])
            items.forEach((item) => {
                console.log(item.ID,item.Title,item.Program);
            });
        });

Without the top=300 part it is only listing 131 item. And it wont work with a list with 1000+ row.

The odata.nextLink is undefined. So it seems I don't get that. How can I get all data?

8
  • How many items it is returning with $top=300? Commented Jun 18, 2024 at 11:48
  • List currently has~250row. So top300 return it all. Commented Jun 18, 2024 at 13:31
  • This is the default behavior of SharePoint REST APIs. If you do not mention $top, it returns 100 items by default. So, you have to use $top to retrieve more items. You can get up to 5000 items using $top in one API call. Let me know if it helps. Commented Jun 18, 2024 at 13:36
  • If you want to get more than 5000 items, use $top=5000 and then in response, you will get nextLink property. Commented Jun 18, 2024 at 13:49
  • 1
    Thank you Ganesh. $top=5000 working. i get all 6200 item back now. Commented Jun 19, 2024 at 9:28

1 Answer 1

0

This is the default behavior of SharePoint REST APIs:

  • If you do not mention $top in REST API endpoint, it returns 100 items by default.

So, you have to use $top to retrieve more than 100 items in single API call. You can get up to 5000 items using $top in one API call.

If you want to get more than 5000 items, use $top=5000 and then in response, you will get nextLink (__next) property.

Check answers given here for full code to retrieve more than 5000 items in recursive API calls:

  1. Rest to read more than 5000 items from document library
  2. SharePoint Online list items 5000 +, rest query

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.