The Mobenzi API utilises Microsoft's WCF Data Services (formerly known as "ADO.NET Data Services"). This enables you to execute queries using familiar .NET Framework programming patterns, including using language integrated query (LINQ).


The following sections outline some useful mechanisms provided by the Microsoft WCF Data Services framework to work with the data returned by the Mobenzi API endpoints.


Query String Options


Option
Description
Example
 expand
The ‘expand’ option allows you to embed one or more sets of related entities in the results. For example, if you want to display a Submission and its Responses, you could execute two requests, one for /Submissions(guid’42d4de6e-38b9-4b88-bcb1-df70227aff0a’) and one for /Submissions(guid’42d4de6e-38b9-4b88-bcb1-df70227aff0a’)/Responses. 

The ‘expand’ option on the other hand allows you to return the related entities in-line with the response of the parent in a single HTTP request. You may specify multiple navigation properties to expand by separating them with commas, and you may traverse more than one relationship by using a dot to jump to the next navigation property.
A Submission with related Responses: /Submissions(guid’42d4de6e-38b9-4b88-bcb1-df70227aff0a’)?$expand=Responses. 

A Submission with related Responses and Response Options related to each Response: /Submissions(guid’42d4de6e-38b9-4b88-bcb1-df70227aff0a’)?$expand=Responses/ResponseOptions. 

A Submission with related Responses and Survey: Orders with related /Submissions(guid’42d4de6e-38b9-4b88-bcb1-df70227aff0a’)?$expand=Responses,Survey
 orderby
Sort the results by the criteria given in this value. Multiple properties can be indicated by separating them with a comma. The sort order can be controlled by using the “asc” (default) and “desc” modifiers.
/Submissions?$orderby=uploaddate /Submissions?$orderby=uploaddate desc 
/Submissions?$orderby=uploaddate,survey_id desc
 skip
Skip a given number of rows when returning results. This is useful in combination with “top” to implement paging (e.g. if using 10-entity pages, saying $skip=30&$top=10 would return the fourth page). NOTE: Skip only makes sense on sorted sets; if an orderby option is included, ‘skip’ will skip entities in the order given by that option. If no orderby option is given, ‘skip’ will sort the entities by their primary key and then perform the skip operation.
Return all Submissions except the first 10: 
/Submissions?$skip=10 

Return the 4th page where each page shows only 10
Submissions: /Submissions?$skip=30&$top=10
 top
Restrict the maximum number of entities to be returned. This option is useful both by itself and in combination with skip, where it can be used to implement paging as discussed in the description of ‘skip’.
Top 10 Submissions: /Submissions?$top=10 
Get the last 10 Submissions: /Submissions?$orderby=uploaddate desc&$top=10
 filter
Restrict the entities returned from a query by applying the expression specified in this operator to the entity set identified by the last segment of the URL path.
Get all Submissions for Survey with Id 101 : 
/Submissions?$filter=survey_id eq 101 
Get all Questions where the question name contains “health”: /Questions?$filter=substringof(‘health’, name)


Logical Operators


Operator
Description
Example
eq
Equal
/Submissions?filter=modifiedby eq 'Test user'
ne
Not equal 
/Submissions?filter=IsIncomplete ne false
gt
Greater than
/Submissions?$filter=year(uploaddate) gt 2009
ge
Greater than or equal
/Submissions?$filter=year(uploaddate) ge 2010
lt
Less than
/Submissions?$filter=year(uploaddate) lt 2009
le
Less than or equal
/Submissions?$filter=year(uploaddate) le 2010
and
Logical "AND"
/Submissions?$filter=year(uploaddate) le 2010 and survey_id = 101
or
Logical "OR"
/Submissions?$filter=year(uploaddate) eq 2008 or year(uploaddate) eq 2010
not
Logical negation
/Submissions?$filter=not substringof(modifiedby,'test')


Arithmetic Operators


Operator
Description
Example
add
Addition
/Submissions?$filter=hour(uploaddate) add 5 gt 10
sub
Subtraction
/Submissions?$filter=hour(uploaddate) sub 5 gt 3
mul
Multiplication
/Submissions?$filter=minute(uploaddate) mul 0.5 lt 3
div
Division
/Submissions?$filter=minute(uploaddate) div 2 lt 3
mod
Modulo
/Submissions?$filter=minute(uploaddate) mod 2 eq 3


Grouping Operators


Operator
Description
Example
 ()
Precedence grouping
/Submissions?filter=(year(Submission/uploaddate) sub 5) lt 2005


Other Functions


String Functions
Date Functions
Math Functions
bool substringof(string p0, string p1)
int day(DateTime p0)
double round(double p0)
bool endswith(string p0, string p1)
int hour(DateTime p0)
decimal round(decimal p0)
bool startswith(string p0, string p1)
int minute(DateTime p0)
double floor(double p0)
int length(string p0)
int month(DateTime p0)
decimal floor(decimal p0)
int indexof(string arg)
int second(DateTime p0)
double ceiling(double p0)
string insert(string p0, int pos, string p1)
int year(DateTime p0)
decimal ceiling(decimal p0)
string remove(string p0, int pos)
 
 
string remove(string p0, int pos, int length)
 
 
string replace(string p0, string find, string replace)
 
 
string substring(string p0, int pos)
 
 
string substring(string p0, int pos, int length)
 
 
string tolower(string p0)
 
 
string toupper(string p0)
 
 
string trim(string p0)
 
 
string concat(string p0, string p1)