Jaa


Insert Entity

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

Request

You can construct the Insert Entity request 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 you make a request against the emulated storage service, specify the emulator hostname and Azure Table Storage 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

Table Storage in the Storage emulator differs from Azure Table Storage in several ways. For more information, see Differences between the Storage emulator and Azure Storage services.

URI parameters

You can specify the following additional parameters on the request URI.

Parameter Description
timeout Optional. The timeout parameter is expressed in seconds. For more information, see Setting timeouts for Table Storage operations.

Request headers

The following table describes required and optional request headers.

Request header Description
Authorization Required. Specifies the authorization scheme, account name, and signature. For more information, see Authorize requests to Azure Storage.
Date or x-ms-date Required. Specifies the Coordinated Universal Time (UTC) for the request. For more information, see Authorize requests to Azure Storage.
x-ms-version Optional. Specifies the version of the operation to use for this request. For more information, see Versioning for the Azure Storage services.
Content-Type Required. Specifies the content type of the payload. Possible values are application/atom+xml (versions prior to 2015-12-11 only), and application/json.

For more formation about valid content types, see Payload format for Table Storage operations.
Content-Length Required. The length of the request body.
Accept Optional. Specifies the accepted content type of the response payload. Possible values are:

- application/atom+xml (versions prior to 2015-12-11 only)
- application/json;odata=nometadata
- application/json;odata=minimalmetadata
- application/json;odata=fullmetadata

For more information, see Payload format for Table Storage operations.
Prefer Optional. Specifies whether the response should include the inserted entity in the payload. Possible values are return-no-content and return-content. For more information, see Setting the Prefer header to manage response echo on insert operations.
x-ms-client-request-id Optional. Provides a client-generated, opaque value with a 1-kibibyte (KiB) character limit that's recorded in the logs when logging is configured. We highly recommend that you use this header to correlate client-side activities with requests that the server receives. For more information, see Monitor Azure Table Storage.

Request body

The Insert Entity operation sends the entity to be inserted as an OData entity, which is either a JSON or an Atom feed. For more information, see Inserting and updating entities.

Note

JSON is the recommended payload format, and is the only format supported for version 2015-12-11 and later.

JSON (version 2013-08-15 and later)

Here's a sample JSON request body for the Insert Entity operation:

{  
   "Address":"Mountain View",  
   "Age":23,  
   "AmountDue":200.23,  
   "CustomerCode@odata.type":"Edm.Guid",  
   "CustomerCode":"c9da6455-213d-42c9-9a79-3e9149a57833",  
   "CustomerSince@odata.type":"Edm.DateTime",  
   "CustomerSince":"2008-07-10T00:00:00",  
   "IsActive":true,  
   "NumberOfOrders@odata.type":"Edm.Int64",  
   "NumberOfOrders":"255",  
   "PartitionKey":"mypartitionkey",  
   "RowKey":"myrowkey"  
}  

Atom feed (versions prior to 2015-12-11)

Here's a sample Atom 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="https://www.w3.org/2005/Atom">  
  <title />  
  <updated>2013-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>  
    </m:properties>  
  </content>  
</entry>  

Response

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

Status code

The status code depends on the value of the Prefer header. If the Prefer header is set to return-no-content, then a successful operation returns status code 204 (No Content). If the Prefer header isn't specified, or if it's set to return-content, then a successful operation returns status code 201 (Created). For more information, see Setting the Prefer header to manage response echo on insert operations.

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 can also include additional, standard HTTP headers. All standard headers conform to the HTTP/1.1 protocol specification.

Response header Description
x-ms-request-id 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 Table Storage used to run the request. This header is returned for requests made against version 2009-09-19 and later.
Date A UTC date/time value that indicates the time at which the response was initiated. The service generates this value.
ETag The ETag for the entity.
Preference-Applied Indicates whether the Prefer request header was honored. If the response doesn't include this header, then the Prefer header was not honored. If this header is returned, its value will either be return-content or return-no-content.

For more information, see Setting the Prefer header to manage response echo on insert operations.
Content-Type Indicates the content type of the payload. The value depends on the value specified for the Accept request header. Possible values are:

- application/atom+xml
- application/json;odata=nometadata
- application/json;odata=minimalmetadata
- application/json;odata=fullmetadata

For more information about content types, see Payload format for Table Storage operations.
x-ms-client-request-id Can be used to troubleshoot requests and corresponding responses. The value of this header is equal to the value of the x-ms-client-request-id header, if it's present in the request. The value is at most 1,024 visible ASCII characters. If the x-ms-client-request-id header isn't present in the request, it won't be present in the response.

Response body

If the request includes the Prefer header with the value return-no-content, no response body is returned. Otherwise, the response body is an OData entity set.

Note

JSON is the recommended payload format, and is the only format supported for version 2015-12-11 and later.

JSON (version 2013-08-15 and later)

Here's a sample JSON response for each metadata level:

No metadata:

{  
   "PartitionKey":"mypartitionkey",  
   "RowKey":"myrowkey",  
   "Timestamp":"2013-08-22T01:12:06.2608595Z",  
   "Address":"Mountain View",  
   "Age":23,  
   "AmountDue":200.23,  
   "CustomerCode":"c9da6455-213d-42c9-9a79-3e9149a57833",  
   "CustomerSince":"2008-07-10T00:00:00",  
   "IsActive":true,  
   "NumberOfOrders":"255"  
}  
  

Minimal metadata:

{  
   "odata.metadata":"https://myaccount.table.core.windows.net/Customer/$metadata#Customers/@Element",  
   "PartitionKey":"mypartitionkey",  
   "RowKey":"myrowkey",  
   "Timestamp":"2013-08-22T01:12:06.2608595Z",  
   "Address":"Mountain View",  
   "Age":23,  
   "AmountDue":200.23,  
   "CustomerCode@odata.type":"Edm.Guid",  
   "CustomerCode":"c9da6455-213d-42c9-9a79-3e9149a57833",  
   "CustomerSince@odata.type":"Edm.DateTime",  
   "CustomerSince":"2008-07-10T00:00:00",  
   "IsActive":true,  
   "NumberOfOrders@odata.type":"Edm.Int64",  
   "NumberOfOrders":"255"  
}  
  

Full metadata:

{  
   "odata.metadata":"https://myaccount.table.core.windows.net/Customer/$metadata#Customers/@Element",  
   "odata.type":"myaccount.Customers",  
   "odata.id":" https://myaccount.table.core.windows.net/Customers(PartitionKey='mypartitionkey',RowKey='myrowkey')",  
   "odata.etag":"W/\"0x5B168C7B6E589D2\"",  
   "odata.editLink":"Customers(PartitionKey='mypartitionkey',RowKey='myrowkey')",  
   "PartitionKey":"mypartitionkey",  
   "RowKey":"myrowkey",  
   "Timestamp@odata.type":"Edm.DateTime",  
   "Timestamp":"2013-08-22T01:12:06.2608595Z",  
   "Address":"Mountain View",  
   "Age":23,  
   "AmountDue":200.23,  
   "CustomerCode@odata.type":"Edm.Guid",  
   "CustomerCode":"c9da6455-213d-42c9-9a79-3e9149a57833",  
   "CustomerSince@odata.type":"Edm.DateTime",  
   "CustomerSince":"2008-07-10T00:00:00",  
   "IsActive":true,  
   "NumberOfOrders@odata.type":"Edm.Int64",  
   "NumberOfOrders":"255"  
}  

Atom feed (versions prior to 2015-12-11)

Here is a sample Atom 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/"0x5B168C7B6E589D2"" xmlns="https://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

The account owner can perform this operation. Additionally, anyone with a shared access signature that has permission to perform this operation can do so.

Remarks

When you insert 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. PartitionKey and RowKey values can be up to 1024 characters in size. If you use an integer value for the key value, you should convert the integer to a fixed-width string, because they're canonically sorted. For example, convert the value 1 to 0000001, to ensure proper sorting.

To explicitly type a property, specify the appropriate OData data 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.

Table Storage doesn't make null values for properties persistent. Specifying a property with a null value is equivalent to omitting that property in the request.

For information about performing batch insert operations, see Performing entity group transactions.

See also

Authorize requests to Azure Storage
Setting the OData data service version headers
Inserting and updating entities
Status and error codes
Table Storage error codes