SharePoint 2010 Rest Interface With Operators and Functions

Introduction

Most users are unaware of the available operators and functions of REST that can be used in SharePoint. In this article we will see the list of operators and functions that can be used with the REST interface.

You can check my earlier article REST interface for an introduction to REST and how to get list data.

The information in this article is:

  • Various operators that can be used with the REST interface
  • Various functions that can be used with the REST interface

Filter operators

The following are the various filter operators that can be used with the REST interface:

  • eq Equal to
  • ne Not equal to
  • gt Greater than
  • ge Greater than or equal to
  • lt Less than
  • le Less than or equal to
  • and Logical and
  • or Logical or
  • not Logical negation
  • add Addition
  • sub Subtraction
  • mul Multiplication
  • div Division
  • mod Modulo
  • ( ) Precedence grouping

Functions

The following are the various functions that can be used with the REST interface:

  • bool substringof(string s0, string s1)
    Checks whether s0 is within s1
  • bool endswith(string s0, string s1)
    Checks whether s0 ends with s1
  • bool startswith(string s0, string s1)
    Checks whether s0 starts with s1
  • int length(string s)
    Length of string s
  • int indexof(string s0, string s1)
    Index of string s0 within s1
  • string insert(string s0, int pos, string s1)
    Inserts s0 into s1 at position pos.
  • string remove(string s0, int pos)
    Removes characters from position pos in s0
  • string remove(string s0, int pos, int length)
    Removes length characters from position pos in s0
  • string replace(string s0, string f0, string s1)
    Replaces f0 in s0 with s1
  • string substring(string s0, int pos)
    Returns the substring from position pos in s0
  • string substring(string s0, int pos, int length)
    Returns the substring from position pos in s0 with the length characters
  • string tolower(string s0)
    Transforms s0 to lowercase
  • string toupper(string s0)
    Transforms s0 to uppercase
  • string trim(string s0)
    Removes leading and trailing whitespaces
  • string concat(strings s0, string s1)
    Concatenates two strings
  • int day(DateTime dt)
    Day of the date dt
  • int hour(DateTime dt)
    Hour of the date dt
  • int minute(DateTime dt)
    Minute of the date dt
  • int month(DateTime dt)
    Month of the date dt
  • int second(DateTime dt)
    Second of the date dt
  • int year(DateTime dt)
    Year of the date dt
  • double round(double dbl)
    Rounded value of dbl with double precision
  • decimal round(decimal dec)
    Rounded value of dec with decimal precision
  • double floor(double dbl)
    Floor value of dbl with double precision
  • decimal floor(decimal dec)
    Floor value of dec with decimal precision

Examples of usage

(Assume there is a list "Employees" that has been created.)

  • /Employees?$filter=Id eq 1
    Filter using the eq operator extracts exactly one element if the filtered element is unique
  • Employees?$filter='Adi,Dasari' eq concat(FirstName, concat(',', LastName))
    Filter after concatinating the column values
  • Employees?$filter=year(Modified) eq 2010
    Filter on the year of the Modified property
  • Employees?$filter=Id eq 3 and substring(Department, 0, 1) eq 'I'
    Filter on the result set along with expression

Conclusion

The REST interface is a great way to access SharePoint data and  hope the preceding operators and functions will provide you a greater ability to take advantage of the REST interface.