3

I need to get records from a list using REST API based on multiple Id's (Primary Key).

Is it possible to pass multiple Id's in a single REST API call and get all the records in a single fetch ?

Is there anything like "IN (1, 2, 3)" in REST API ?

2 Answers 2

10

According to Use OData query operations in SharePoint REST requests the following OData query operators supported in the SharePoint REST service:

enter image description here

How to query multiple items via SharePoint REST

Since there is no in operator in SharePoint REST, below are provided some equivalents:

Specify items explicitly using chained and and or operators:

/_api/web/lists/getByTitle(listTitle)/items?$filter=(ID eq 1) or (ID eq 2) or (ID eq 3)

Specify items limit in a query using top operator:

/_api/web/lists/getByTitle(listTitle)/items?$top=3&$orderby=ID

Specify the range using lt, le, gt, ge operators:

/_api/web/lists/getByTitle(listTitle)/items?$filter=(ID ge 1) and (ID le 3) 
Sign up to request clarification or add additional context in comments.

Comments

-1

if the resource supports it, then yes. Suppose the provider supports it; if you execute the GET with the right syntax(I don't know if you are doing this with code or a tool like restclient), that resource could be doing the IN(1, 2, 3) in the db call and serve up the records with PKs 1, 2, and 3.

3 Comments

I'm using angularjs for code. But, I didn't properly get your answer. Can you please explain a bit ?
@AnishV It's up to whoever wrote the API. If the API has some way of doing it, then you can. If it doesn't, you're out of luck. You'll need to go through the documentation or contact the vendor.
This is a non-answer. Basically all you've said here is "yes, it's possible, if it's possible". The question is specifically about SharePoint's APIs, so a theoretical, noncommital answer is not merited.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.