共用方式為


Update record operation

 

Updates an existing item in a table.

Request

The request may be specified as follows. Replace <service_name> with your mobile service name, <table_name> with the name of the table to access, and <item_id> with the ID of the item to be updated.

HTTP Verb

Request URI

HTTP Version

PATCH

https://<service_name>.azure-mobile.net/tables/<table_name>/<item_id>

HTTP/1.1

URI Parameters

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.

Content-Length

Yes

The length of the request body.

Content-Type

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.

System_CAPS_security Security Note

The service master key is a critical security credential that provides administrator access to your data service. Do not share this secret with anyone or distribute it with your app. This key must always be securely distributed over an encrypted channel.

Request Body

The updated values encoded in JavaScript Object Notation (JSON) format, along with the optional id value of the object.

Response

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 updated item.

Authorization

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.

Sample Request and Response

The following example URI updates an existing item in the TodoItem table.

PATCH https://todolist.azure-mobile.net/tables/TodoItem/18

The request is sent with the following headers.

Accept: application/json
X-ZUMO-APPLICATION: UzMAOXRlJdZyqibeUqCMoZZMrUXIRs92
Content-Type: application/json
Host: todolist.azure-mobile.net
Content-Length: 56

The request is sent with the following JSON object in the body.

{"complete":true}

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 15:49:06 GMT
Content-Length: 56

{"text":"Complete the tutorial","complete":true,"id":18}

See Also

Operations on a table in Mobile Services
Azure Mobile Services REST API Reference