Friday, August 28, 2015

ODATA (REST) OPERATIONS ON DATA

ODATA (REST) OPERATIONS ON DATA

n this small exercise you try out querying and filtering for data using the REST/OData _Api in SharePoint 2013.
  1. Create new list in SharePoint 2013 site by clicking on Site Contents using Quick Launch navigation
  2. Click Add an App
  3. Choose Custom List and name it Movies
  4. After the list creation, add some list items to it of some 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
  9. 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>
    Observe that only the Title property is returned
  10. Customize the querystring as follows to order your movie titles alphabetically:?$select=Title&$orderby=Title
  11. Customize the querystring as follows to just retrieve the fi rst movie:?$select=Title&$orderby=Title&$top=1

No comments:

Post a Comment