Skip to main content

How to Choose Which Fields a SharePoint REST Request Returns with $select

· 4 min read
Jagdish Kumawat
Founder @ Dewiride

A SharePoint REST request returns every field of what it asks for unless you say otherwise. Adding $select to the address names the fields you want, and the answer holds only those. This guide reads two fields of a list in the browser.

Syntax​

General form
<request address>?$select=<field>,<field>
  • <request address>: a SharePoint REST address that returns something with fields, such as a list: https://<site address>/_api/web/lists/getbytitle('<list name>').
  • $select=: the query option, after a ?. If the address already has a query option, join the next one with & instead.
  • <field>: a field's name, such as Title. Separate several with commas, without spaces.

Microsoft's Use OData query operations in SharePoint REST requests says: Use the $select query option to specify which fields to return for a given list, list item, or other SharePoint object represented by an entity set. You can use $select=* to return all available fields.

The Example​

The address reads two fields of the Suggestions list on the root site contoso.sharepoint.com: its Title and its ItemCount, the number of items in it.

Prerequisites​

  • Access to the list and a signed-in SharePoint session in the same browser. The browser sends your sign-in with the request.

Step 1: Open the Address​

In the browser where you use SharePoint, type the address in the address bar and press Enter:

Browser address bar
https://contoso.sharepoint.com/_api/web/lists/getbytitle('Suggestions')?$select=Title,ItemCount

Use your own site's address in place of contoso.sharepoint.com.

Step 2: Read the Answer​

The browser sends no Accept header asking for JSON, so SharePoint answers in XML. In my browser it appeared as plain text:

The browser showing SharePoint's XML answer for the Suggestions list, with m holding only d 0, marked Edm.Int32, and d Suggestions; the list's ID is masked

Inside m:properties there are exactly the two fields named in $select:

ElementValue
d:ItemCount0
d:TitleSuggestions

The list is empty, so its count is 0. Everything else around them, such as the id and the link, is how SharePoint describes any answer in XML, whatever $select asks for.

Common Mistakes​

MistakeWhat happensDo this instead
Leaving a field out of $selectIt isn't in the answerName every field you need
A second ? for another query optionOnly one ? starts the query optionsJoin the next option with &, as in ?$filter=…&$select=…
Expecting every field when $select is left outA few fields only come back when you name themName them in $select

Troubleshooting​

SymptomLikely causeFix
A field you expected is missingIt isn't in the $select listAdd it
A field is missing although you didn't use $selectIt's one of the fields SharePoint returns only when askedName it in $select
A sign-in page or an access errorThe browser isn't signed in, or you can't open the listSign in to SharePoint in the same browser

FAQ​

Why use $select at all?​

The answer is smaller and holds only what you need, which makes it easier to read, in the browser or in a flow. Some fields are only returned when you name them: Microsoft's article gives EffectiveBasePermissions of a site as an example.

Does $select work on items too?​

Yes. On …/items, it picks the columns of every item, such as …/items?$select=Title.

Is this safe to try on a real list?​

Yes. Opening an address in the browser sends a GET request, which only reads.

Conclusion​

Add ?$select=<field>,<field> to a SharePoint REST address, and the answer holds only those fields. …/lists/getbytitle('Suggestions')?$select=Title,ItemCount returned the list's title and its item count, 0.

Additional Resources​