Query records operation
The feature described in this topic is available only in preview. To use this feature and other new Windows Azure capabilities, sign up for the free preview.
The query operation returns items from a table.
The request may be specified as follows. Replace <service_name> with your mobile service name and <table_name> with the name of the table to access.
| HTTP Verb | Request URI | HTTP Version |
|---|---|---|
|
GET |
|
HTTP/1.1 |
URI Parameters
Windows Azure Mobile Services supports the following subset of the query option parameters defined by the Open Data Protocol (OData).
| URI Parameter | Required | Description |
|---|---|---|
|
$filter |
No |
Restricts returned items based on a filter predicate. |
|
$inlinecount |
No |
Returns a count of all items that could be returned in the base query without paging applied. You must specify a value of allpages for this parameter. |
|
$orderby |
No |
Orders the returned items by one or more columns. Ordering can be specified as ascending (asc), which is the default, or descending (desc) |
|
$select |
No |
Defines a new projection of data by specifying the columns included in the returned data. |
|
$skip |
No |
Specifies the number of records from the base query to skip before returning items. This is used for paging results. For more information, see Add paging to your queries. |
|
$top |
No |
Specifies the number of items to include in response. This is used for paging results. For more information, see Add paging to your queries. |
For syntax requirements of individual query options, see the OData protocol documentation.
The noscript parameter is also supported:
| URI Parameter | Required | Description |
|---|---|---|
|
noscript |
No |
When a value of true is supplied, the execution of registered scripts is suppressed. To suppress script execution, you must also supply the service master key in the X-ZUMO-MASTER header. |
Request Headers
The following table describes the request headers.
| Request Header | Required | |||
|---|---|---|---|---|
|
Accept |
No |
Set this header to application/json. |
||
|
X-ZUMO-APPLICATION |
Conditional |
The application key of the mobile service. You must specify a valid application key when required to access the table operation. This is the default table operation access permission. |
||
|
X-ZUMO-AUTH |
Conditional |
The service-generated authentication token for an authenticated user. You must specify a token for an authenticated user when required to access the table operation. |
||
|
X-ZUMO-MASTER |
Conditional |
The service master key. You should only include this key when administrator access is required to access the table operation.
|
Request Body
None.
The response includes an HTTP status code, a set of response headers, and a response body.
Status Code
A successfully operation returns status code 200 (OK).
Response Headers
The response for this operation includes the following headers. The response may also include additional standard HTTP headers. All standard headers conform to the HTTP/1.1 protocol specification.
| Response Header | Description |
|---|---|
|
Content-Length |
The length of the response body. |
|
Content-Type |
Header set to application/json. |
|
x-zumo-version |
Indicates which version of the runtime executed the request. |
Response Body
The JSON representation of the query result. Results are represented as a single JSON object or a collection of JSON objects.
Note |
|---|
| When you include the $inlinecount parameter in your query, the JSON in the response is wrapped by a new JSON object with a results property, which includes the results data as a collection of JSON objects, and a count property, which is the total count. |
Authorization depends on the access permission requirements for the table operation, which are summarized as follows:
| Table operation access permission | Required authorization header |
|---|---|
|
Everyone |
None |
|
Anybody with the application key |
X-ZUMO-APPLICATION |
|
Only Authenticated Users |
X-ZUMO-AUTH |
|
Only Scripts and Admins |
X-ZUMO-MASTER |
Access permissions for individual table operations are set in the Windows Azure Management Portal. For more information, see Permissions.
Filtered query request
The following example URI returns JSON objects from the TodoItem table, where the complete property is false.
GET https://todolist.azure-mobile.net/tables/TodoItem?$filter=(complete%20eq%20false)
The request is sent with the following headers.
Accept: application/json X-ZUMO-APPLICATION: UzMAOXRlJdZyqibeUqCMoZZMrUXIRs92 Host: todolist.azure-mobile.net
After the request has been sent, the following response is returned.
HTTP/1.1 200 OK
Content-Type: application/json
x-zumo-version: Zumo.Main.0.1.6.527.Runtime
Date: Thu, 20 Sep 2012 05:59:27 GMT
Content-Length: 188
[{"id":1,"text":"Sign-up for the free trial","complete":false},{"id":2,"text":"Create the mobile service","complete":false },
{"id":3,"text":"Complete the quickstart","complete":false}]
Filtered query request that includes total count
The following example URI returns the same filtered query, including the total count value, which in this case is 3.
GET https://todolist.azure-mobile.net/tables/TodoItem?$filter=(complete%20eq%20false)&$inlinecount=allpages
The request is sent with the following headers.
Accept: application/json X-ZUMO-APPLICATION: UzMAOXRlJdZyqibeUqCMoZZMrUXIRs92 Host: todolist.azure-mobile.net
After the request has been sent, the following response is returned.
HTTP/1.1 200 OK
Content-Type: application/json
x-zumo-version: Zumo.Main.0.1.6.527.Runtime
Date: Thu, 20 Sep 2012 05:59:27 GMT
Content-Length: 211
{"results": [{"id":1,"text":"Sign-up for the free trial","complete":false},{"id":2,"text":"Create the mobile service","complete":false },
{"id":3,"text":"Complete the quickstart","complete":false}],"count":3}
Security Note
Note