4 out of 4 rated this helpful - Rate this topic

Insert Entity (REST API)

The Insert Entity operation inserts a new entity into a table.

Request

The Insert Entity request may be constructed as follows. HTTPS is recommended. Replace myaccount with the name of your storage account, and mytable with the name of your table:

 

Method Request URI HTTP Version

POST

https://myaccount.table.core.windows.net/mytable

HTTP/1.1

Emulated Storage Service URI

When making a request against the emulated storage service, specify the emulator hostname and Table service port as 127.0.0.1:10002, followed by the emulated storage account name:

 

Method Request URI HTTP Version

POST

http://127.0.0.1:10002/devstoreaccount1/mytable

HTTP/1.1

The Table service in the storage emulator differs from the Windows® Azure™ Table service in several ways. For more information, see About Development Storage and Differences between Development Storage and Cloud Storage Services.

URI Parameters

None.

Request Headers

The following table describes required and optional request headers.

 

Request header Description

Authorization

Required. Specifies the authentication scheme, account name, and signature. For more information, see Authentication for the Windows Azure Storage Services.

Date or x-ms-date

Required. Specifies the Coordinated Universal Time (UTC) for the request. For more information, see Authentication for the Windows Azure Storage Services.

x-ms-version

Optional. Specifies the version of the operation to use for this request. For more information, see Versioning for the Blob, Queue, and Table services in Windows Azure.

Content-Type

Required. The content type of the request body. Currently, this header should be set to application/atom+xml.

Content-Length

Required. The length of the request body.

Request Body

The Insert Entity operation sends the entity to be inserted as a WCF entity set, which is an Atom feed. For more information, see Inserting and Updating Entities.

Here is a sample request body for the Insert Entity operation.

<?xml version="1.0" encoding="utf-8" standalone="yes"?>
<entry xmlns:d="http://schemas.microsoft.com/ado/2007/08/dataservices" xmlns:m="http://schemas.microsoft.com/ado/2007/08/dataservices/metadata" xmlns="http://www.w3.org/2005/Atom">
  <title />
  <updated>2008-09-18T23:46:19.3857256Z</updated>
  <author>
    <name />
  </author>
  <id />
  <content type="application/xml">
    <m:properties>
      <d:Address>Mountain View</d:Address>
      <d:Age m:type="Edm.Int32">23</d:Age>
      <d:AmountDue m:type="Edm.Double">200.23</d:AmountDue>
      <d:BinaryData m:type="Edm.Binary" m:null="true" />
      <d:CustomerCode m:type="Edm.Guid">c9da6455-213d-42c9-9a79-3e9149a57833</d:CustomerCode>
      <d:CustomerSince m:type="Edm.DateTime">2008-07-10T00:00:00</d:CustomerSince>
      <d:IsActive m:type="Edm.Boolean">true</d:IsActive>
      <d:NumOfOrders m:type="Edm.Int64">255</d:NumOfOrders>
      <d:PartitionKey>mypartitionkey</d:PartitionKey>
      <d:RowKey>myrowkey1</d:RowKey>
      <d:Timestamp m:type="Edm.DateTime">0001-01-01T00:00:00</d:Timestamp>
    </m:properties>
  </content>
</entry>

Response

The response includes an HTTP status code, a set of response headers, and a response body.

Status Code

A successful operation returns status code 201 (Created).

For information about status codes, see Status and Error Codes and Table Service Error Codes.

Response Headers

The response 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

x-ms-request-id

This header uniquely identifies the request that was made and can be used for troubleshooting the request. For more information, see Troubleshooting API Operations.

x-ms-version

Indicates the version of the Table service used to execute the request. This header is returned for requests made against version 2009-09-19 and later.

Date

A UTC date/time value generated by the service that indicates the time at which the response was initiated.

Response Body

The response body for the Insert Entity operation is also a WCF entity set.

Here is a sample response body for the Insert Entity operation.

<?xml version="1.0" encoding="utf-8" standalone="yes"?>
<entry xml:base="https://myaccount.table.core.windows.net/" xmlns:d="http://schemas.microsoft.com/ado/2007/08/dataservices" xmlns:m="http://schemas.microsoft.com/ado/2007/08/dataservices/metadata" m:etag="W/&quot;datetime'2008-09-18T23%3A46%3A19.4277424Z'&quot;" xmlns="http://www.w3.org/2005/Atom">
  <id>https://myaccount.table.core.windows.net/mytable(PartitionKey='mypartitionkey',RowKey='myrowkey1')</id>
  <title type="text"></title>
  <updated>2008-09-18T23:46:19.3857256Z</updated>
  <author>
    <name />
  </author>
  <link rel="edit" title="mytable" href="mytable(PartitionKey='mypartitionkey',RowKey='myrowkey1')" />
  <category term="myaccount.Tables" scheme="http://schemas.microsoft.com/ado/2007/08/dataservices/scheme" />
  <content type="application/xml">
    <m:properties>
      <d:PartitionKey>mypartitionkey</d:PartitionKey>
      <d:RowKey>myrowkey1</d:RowKey>
      <d:Timestamp m:type="Edm.DateTime">2008-09-18T23:46:19.4277424Z</d:Timestamp>
      <d:Address>Mountain View</d:Address>
      <d:Age m:type="Edm.Int32">23</d:Age>
      <d:AmountDue m:type="Edm.Double">200.23</d:AmountDue>
      <d:CustomerCode m:type="Edm.Guid">c9da6455-213d-42c9-9a79-3e9149a57833</d:CustomerCode>
      <d:CustomerSince m:type="Edm.DateTime">2008-07-10T00:00:00</d:CustomerSince>
      <d:IsActive m:type="Edm.Boolean">true</d:IsActive>
      <d:NumOfOrders m:type="Edm.Int64">255</d:NumOfOrders>
    </m:properties>
  </content>
</entry>

Authorization

This operation can be performed by the account owner and by anyone with a shared access signature that has permission to perform this operation.

Remarks

When inserting an entity into a table, you must specify values for the PartitionKey and RowKey system properties. Together, these properties form the primary key and must be unique within the table.

Both the PartitionKey and RowKey values must be string values; each key value may be up to 64 KB in size. If you are using an integer value for the key value, you should convert the integer to a fixed-width string, because they are canonically sorted. For example, you should convert the value 1 to 0000001 to ensure proper sorting.

To explicitly type a property, specify the appropriate WCF Data Services type by setting the m:type attribute within the property definition in the Atom feed. For more information about typing properties, see Inserting and Updating Entities.

Any application that can authenticate and send an HTTP POST request can insert an entity. For more information about constructing a query by using HTTP POST, see How to: Add Modify, and Delete Entities (WCF Data Services).

Note that you can also use the .NET Client Library for WCF Data Services to insert an entity into a table.

For information about performing batch insert operations, see Performing Entity Group Transactions.

See Also

Did you find this helpful?
(1500 characters remaining)
© 2013 Microsoft. All rights reserved.
facebook page visit twitter rss feed newsletter