Logo
HOW TO
Windows XP
Windows Vista
Windows 7
Windows Azure
Windows Server
Windows Phone
 
 
Windows Server

Sharepoint 2013 : Overview of The Client-Side Object Model and Rest APIs - REST and OData (part 2) - Filtering and Selecting

8/17/2014 9:27:44 PM

Filtering and Selecting

When you query for data it’s important to ask for only the data you really need. This keeps payload sizes down and speeds up delivery of the data. _Api uses OData semantics to let you do this by filtering records and selecting properties you want. The common operators you can use for manipulating the result set include the following:

  • $filter, for filtering results
  • $select, for selecting properties to return
  • $expand, for expanding properties to return
  • $orderby, for ordering results
  • $top, for taking the top X results

The simplest way to learn about these operations is to try them out for yourself, as shown in the following exercise.


TRY IT OUT: OData Operations on Data
In this exercise you try out querying and filtering for data using the REST/OData _Api in SharePoint 2013.

1. Create a new list in your SharePoint 2013 site by clicking Site Contents from the Quick Launch navigation.

2. Click Add an App.

3. Choose Custom List and call it Movies.

4. After the list is created, add some list items to it of your favorite movie titles.

5. Modify the URL to navigate to the following URI. Review the payload XML that is returned:

https://servername/sitename/_api/Web/Lists/MoviesList/Items
6. Modify the URL by adding (1) on the end (shown in the following code). This returns the first item in the list:

https://servername/sitename/_api/Web/Lists/MoviesList/Items(1)
7. Modify the URL and add a $filter parameter like the following, specifying the title of one of the movies you added earlier:

?$filter=Title eq 'Aliens'
8. Add a $select parameter to just select the Title property of the list item:

https://servername/sitename/_api/Web/Lists/_api/Lists/ /Items?
$filter=Title eq 'Aliens'&$select=Title
You should see a payload similar to the following:
<?xml version="1.0" encoding="utf-8" ?> 
<feed xml:base="https://servername/sitename/_api/"
xmlns="http://www.w3.org/2005/Atom"
xmlns:d="http://schemas.microsoft.com/ado/2007/08/dataservices"
xmlns:m="http://schemas.microsoft.com/ado/2007/08/dataservices/metadata"
xmlns:georss="http://www.georss.org/georss" xmlns:gml="http://www.opengis.net/gml">
<id>0d01b697-f8f4-496a-bc66-81e4ab7d8208</id>
<title />
<updated>2012-11-03T07:07:21Z</updated>
<entry m:etag=""2"">
<id>f6126125-fddb-4651-bedd-d797c6ef06f4</id>
<category term="SP.Data.MoviesListItem"
scheme="http://schemas.microsoft.com/ado/2007/08/dataservices/scheme" />
<link rel="edit"
href="Web/Lists(guid'f57d3ddc-4522-4145-a0fe-72abbd6ea8fc')/Items(1)" />
<title />
<updated>2012-11-03T07:07:21Z</updated>
<author>
<name />
</author>
<content type="application/xml">
<m:properties>
<d:Title>Aliens</d:Title>
</m:properties>
</content>
</entry>
</feed>
Notice that only the Title property is returned.

9. Modify the querystring as follows to order your movie titles alphabetically:
?$select=Title&$orderby=Title
10. Modify the querystring as follows to just retrieve the first movie:
?$select=Title&$orderby=Title&$top=1
How It Works

In this exercise you queried SharePoint list data using the REST/OData API. When a request is made to SharePoint via this API, SharePoint uses WCF Data Services support for OData to parse and interpret the query on the URL. It then uses that information to translate the query into an internal SharePoint list query (called a CAML query) and executes the query. By adding OData support parameters to the URL you are able to refine the query you make to SharePoint and just return the data you specifically need.
Other -----------------
- Sharepoint 2013 : Integrating Apps for Office with SharePoint (part 2) - Apps for Office Integrated with an App for SharePoint
- Sharepoint 2013 : Integrating Apps for Office with SharePoint (part 1) - Standalone Apps for Office
- Sharepoint 2013 : The Office JavaScript Object Model (part 3) - App Security
- Sharepoint 2013 : The Office JavaScript Object Model (part 2) - Functional Capabilities by Office Client,Mailbox-based Apps
- Sharepoint 2013 : The Office JavaScript Object Model (part 1) - Document-based Apps
- SQL Server 2012 : Understanding Latches and Spinlocks (part 3) - Latching Example - With Latching
- SQL Server 2012 : Understanding Latches and Spinlocks (part 2) - Latching Example - Without Latching
- SQL Server 2012 : Understanding Latches and Spinlocks (part 1) - Latching Example
- SQL Server 2012 : Latches and Spinlocks - Symptoms (part 2) - Measuring Latch Contention, Measuring Spinlock Contention , Contention Indicators
- SQL Server 2012 : Latches and Spinlocks - Symptoms (part 1) - Recognizing Symptoms
 
 
REVIEW
- First look: Apple Watch

- 10 Amazing Tools You Should Be Using with Dropbox
 
VIDEO TUTORIAL
- How to create your first Swimlane Diagram or Cross-Functional Flowchart Diagram by using Microsoft Visio 2010 (Part 1)

- How to create your first Swimlane Diagram or Cross-Functional Flowchart Diagram by using Microsoft Visio 2010 (Part 2)

- How to create your first Swimlane Diagram or Cross-Functional Flowchart Diagram by using Microsoft Visio 2010 (Part 3)
 
Popular tags
Microsoft Access Microsoft Excel Microsoft OneNote Microsoft PowerPoint Microsoft Project Microsoft Visio Microsoft Word Active Directory Biztalk Exchange Server Microsoft LynC Server Microsoft Dynamic Sharepoint Sql Server Windows Server 2008 Windows Server 2012 Windows 7 Windows 8 Adobe Indesign Adobe Flash Professional Dreamweaver Adobe Illustrator Adobe After Effects Adobe Photoshop Adobe Fireworks Adobe Flash Catalyst Corel Painter X CorelDRAW X5 CorelDraw 10 QuarkXPress 8 windows Phone 7 windows Phone 8 BlackBerry Android Ipad Iphone iOS
Popular keywords
HOW TO Swimlane in Visio Visio sort key Pen and Touch Creating groups in Windows Server Raid in Windows Server Exchange 2010 maintenance Exchange server mail enabled groups Debugging Tools Collaborating
Top 10
- Microsoft Excel : How to Use the VLookUp Function
- Fix and Tweak Graphics and Video (part 3) : How to Fix : My Screen Is Sluggish - Adjust Hardware Acceleration
- Fix and Tweak Graphics and Video (part 2) : How to Fix : Text on My Screen Is Too Small
- Fix and Tweak Graphics and Video (part 1) : How to Fix : Adjust the Resolution
- Windows Phone 8 Apps : Camera (part 4) - Adjusting Video Settings, Using the Video Light
- Windows Phone 8 Apps : Camera (part 3) - Using the Front Camera, Activating Video Mode
- Windows Phone 8 Apps : Camera (part 2) - Controlling the Camera’s Flash, Changing the Camera’s Behavior with Lenses
- Windows Phone 8 Apps : Camera (part 1) - Adjusting Photo Settings
- MDT's Client Wizard : Package Properties
- MDT's Client Wizard : Driver Properties
 
Windows XP
Windows Vista
Windows 7
Windows Azure
Windows Server
Windows Phone
2015 Camaro