Querying list items with REST - is there a way around the URL size limit?
What type of issue is this?
Question
What SharePoint development model, framework, SDK or API is this about?
SharePoint REST API
Target SharePoint environment
SharePoint Online, and ideally 2013+ as well
What browser(s) / client(s) have you tested
- [ ] 💥 Internet Explorer
- [ ] 💥 Microsoft Edge
- [X] 💥 Google Chrome
- [ ] 💥 FireFox
- [ ] 💥 Safari
- [ ] mobile (iOS/iPadOS)
- [ ] mobile (Android)
- [ ] not applicable
- [ ] other (enter in the "Additional environment details" area below)
Additional environment details
-
browser version: Chrome 99.0.4844.84
-
SharePoint version: Ideally, SP Online and 2013+, but at least SP Online
Issue description
I am maintaining an app that requires the ability to query list data with an arbitrary set of columns (i.e. the user chooses which columns to query).
Until recently, I have used CSOM/JSOM for this, but I have problems with this because they do not return usernames from person columns (only numeric id, e-mail, and display name).
I can perform a second query using several web.SiteUserInfoList.GetItemById(id)s with the numeric IDs in order to resolve the usernames, but if any of the IDs belongs to an invalid/deleted user, the query fails. I can get around this with an ExceptionHandlingScope, but ideally, I would like to be able to obtain the display name and username even if they are invalid.
So basically, what I'm looking to do is:
- Query list items from an arbitrary number of columns
- Obtain the username and display name for person columns (even if they are invalid)
At first, it seems that REST would be a viable solution to this, since it allows me to get the user values I need (even for invalid users) in a single query by $expanding the user columns. But I have quickly run into a different issue where the query fails if the URL is too long. I have one user trying to query about 80 columns, and the URL is about 2500 characters.
It seems silly to me that the ability to query list items would be subject to a limit in the size of the URL, but I'm unable to find any way around this.
Ideally, I would like to be able to use the REST API to query list items but somehow use POST instead of GET, and pass the $select, $expand, etc. in the body of the request instead of the URL.
Is there a way to do that? I'm aware of the GetItems REST endpoint, but it seems that brings me back to where I was with CSOM since there doesn't seem to be a way to expand the user values (or is there?). I'm also aware that I can send my requests in a batch, but as far as I can tell, any requests within a batch are still subject to the same URL limits, so that doesn't seem to be a way around the URL limit.
Thank you for reporting this issue. We will be triaging your incoming issue as soon as possible.
If you are still having this issue, you can use pnp/js batching to eliminate this issue as the lengthy URL simply becomes part of the request payload.
@JLRishe - for POST requests you can use RenderListDataAsStream or just GetItems endpoint with POST method