Sample code for 30+ languages & platforms
PowerBuilder Requires Chilkat v11.6.0+

Azure Table: Insert an Entity with Typed Properties

See more Azure Table Service Examples

Insert into an existing table using Prefer: return-no-content. Requires HTTP 204, avoids parsing its empty body, and captures the ETag for later conditional writes. Insert is create-only; an existing PartitionKey/RowKey pair produces a conflict.

Includes explicit Edm.Guid, Edm.DateTime, and Edm.Int64 annotations. The Int64 is serialized as a string beyond JavaScript's exact integer range, preserving its digits in every generated language. The timestamp is server-managed. AmountDue demonstrates Edm.Double, which is not exact decimal currency. See Table JSON types.

Uses Chilkat.Rest and AuthAzureStorage with Table-specific Shared Key signing. Load a private qa_data/azure/storage.json containing string fields account and access_key (the base64 account key, not a connection string or SAS). Keep this file outside public web content and source control. Targets Azure Storage Table service in the public cloud, not Azure Cosmos DB for Table.

Pins x-ms-version: 2026-04-06, Microsoft's documented fully deployed Storage version at review time, and sends OData 3.0 headers. Older supported versions are not automatically obsolete. See Storage versioning and OData headers.

Microsoft recommends Microsoft Entra ID authorization, preferably managed identity where available. This example retains its existing Shared Key authentication pattern; use it only when account policy permits. TLS certificates are verified, timeouts are bounded, and diagnostic dumps and entity payloads are not printed. A lost response can leave a write's outcome uncertain: inspect the target before retrying.

Microsoft insert entity reference.

Chilkat PowerBuilder Downloads

PowerBuilder
integer li_rc
long li_Success
oleobject loo_TextCompare
oleobject loo_Config
long li_SameText1
long li_SameText2
oleobject loo_AccountText
oleobject loo_AllowedAccountChars
long li_CharIndex
oleobject loo_Endpoint
string ls_ResourcePath
oleobject loo_Rest
oleobject loo_AzAuth
oleobject loo_Connection
oleobject loo_ResponseBody
oleobject loo_Json
oleobject loo_RequestBody
string ls_EntityEtag
long li_SameText3

li_Success = 0

//  StringBuilder compares text by value in every generated language.
loo_TextCompare = create oleobject
li_rc = loo_TextCompare.ConnectToNewObject("Chilkat.StringBuilder")
if li_rc < 0 then
    destroy loo_TextCompare
    MessageBox("Error","Connecting to COM object failed")
    return
end if
//  Assumes Chilkat is unlocked. See Global Unlock Sample.
li_Success = 0
loo_Config = create oleobject
li_rc = loo_Config.ConnectToNewObject("Chilkat.JsonObject")

loo_Config.Strict = 1
li_Success = loo_Config.LoadFile("qa_data/azure/storage.json")
if li_Success <> 1 then
    Write-Debug "Could not load private Azure configuration."
    destroy loo_TextCompare
    destroy loo_Config
    return
end if

loo_TextCompare.Clear()
loo_TextCompare.SetString(loo_Config.StringOf("account"))
li_SameText1 = loo_TextCompare.ContentsEqual("",1)
if (loo_Config.JsonTypeOf("account") <> 1) OR (li_SameText1 = 1) then
    Write-Debug "Supply the storage account name."
    destroy loo_TextCompare
    destroy loo_Config
    return
end if

//  access_key is the base64 account key, not a connection string or SAS.
loo_TextCompare.Clear()
loo_TextCompare.SetString(loo_Config.StringOf("access_key"))
li_SameText2 = loo_TextCompare.ContentsEqual("",1)
if (loo_Config.JsonTypeOf("access_key") <> 1) OR (li_SameText2 = 1) then
    Write-Debug "Supply the base64 account access key."
    destroy loo_TextCompare
    destroy loo_Config
    return
end if

loo_AccountText = create oleobject
li_rc = loo_AccountText.ConnectToNewObject("Chilkat.StringBuilder")

li_Success = loo_AccountText.Append(loo_Config.StringOf("account"))
if li_Success <> 1 then
    Write-Debug "Could not prepare the request."
    destroy loo_TextCompare
    destroy loo_Config
    destroy loo_AccountText
    return
end if

if (loo_AccountText.Length < 3) OR (loo_AccountText.Length > 24) then
    Write-Debug "Storage account names need 3-24 lowercase letters or digits."
    destroy loo_TextCompare
    destroy loo_Config
    destroy loo_AccountText
    return
end if

loo_AllowedAccountChars = create oleobject
li_rc = loo_AllowedAccountChars.ConnectToNewObject("Chilkat.StringBuilder")

li_Success = loo_AllowedAccountChars.Append("abcdefghijklmnopqrstuvwxyz0123456789")
if li_Success <> 1 then
    Write-Debug "Could not prepare the request."
    destroy loo_TextCompare
    destroy loo_Config
    destroy loo_AccountText
    destroy loo_AllowedAccountChars
    return
end if

li_CharIndex = 0
do while (li_CharIndex < loo_AccountText.Length)
    if loo_AllowedAccountChars.Contains(loo_AccountText.GetRange(li_CharIndex,1,0),1) <> 1 then
        Write-Debug "Storage account names need lowercase letters or digits."
        destroy loo_TextCompare
        destroy loo_Config
        destroy loo_AccountText
        destroy loo_AllowedAccountChars
        return
    end if

    li_CharIndex = li_CharIndex + 1
loop
loo_Endpoint = create oleobject
li_rc = loo_Endpoint.ConnectToNewObject("Chilkat.StringBuilder")

li_Success = loo_Endpoint.Append(loo_Config.StringOf("account"))
if li_Success <> 1 then
    Write-Debug "Could not prepare the request."
    destroy loo_TextCompare
    destroy loo_Config
    destroy loo_AccountText
    destroy loo_AllowedAccountChars
    destroy loo_Endpoint
    return
end if

li_Success = loo_Endpoint.Append(".table.core.windows.net")
if li_Success <> 1 then
    Write-Debug "Could not prepare the request."
    destroy loo_TextCompare
    destroy loo_Config
    destroy loo_AccountText
    destroy loo_AllowedAccountChars
    destroy loo_Endpoint
    return
end if

//  Table names contain only letters and digits and are case-insensitive.
//  Entity PartitionKey and RowKey values are case-sensitive.
ls_ResourcePath = "/ExampleCustomers"
loo_Rest = create oleobject
li_rc = loo_Rest.ConnectToNewObject("Chilkat.Rest")

loo_Rest.ConnectTimeoutMs = 20000
loo_Rest.IdleTimeoutMs = 60000
loo_AzAuth = create oleobject
li_rc = loo_AzAuth.ConnectToNewObject("Chilkat.AuthAzureStorage")

loo_AzAuth.Account = loo_Config.StringOf("account")
loo_AzAuth.AccessKey = loo_Config.StringOf("access_key")
loo_AzAuth.Service = "Table"
loo_AzAuth.Scheme = "SharedKey"
loo_AzAuth.XMsVersion = "2026-04-06"
li_Success = loo_Rest.SetAuthAzureStorage(loo_AzAuth)
if li_Success <> 1 then
    Write-Debug "Could not configure Shared Key signing."
    destroy loo_TextCompare
    destroy loo_Config
    destroy loo_AccountText
    destroy loo_AllowedAccountChars
    destroy loo_Endpoint
    destroy loo_Rest
    destroy loo_AzAuth
    return
end if

loo_Connection = create oleobject
li_rc = loo_Connection.ConnectToNewObject("Chilkat.Socket")

loo_Connection.RequireSslCertVerify = 1
loo_Connection.MaxReadIdleMs = 60000
loo_Connection.MaxSendIdleMs = 60000
li_Success = loo_Connection.Connect(loo_Endpoint.GetAsString(),443,1,20000)
if li_Success <> 1 then
    Write-Debug "TLS connection failed; inspect diagnostics privately."
    destroy loo_TextCompare
    destroy loo_Config
    destroy loo_AccountText
    destroy loo_AllowedAccountChars
    destroy loo_Endpoint
    destroy loo_Rest
    destroy loo_AzAuth
    destroy loo_Connection
    return
end if

//  Do not replay a write automatically after losing its response.
li_Success = loo_Rest.UseConnection(loo_Connection,0)
if li_Success <> 1 then
    Write-Debug "Could not prepare the request."
    destroy loo_TextCompare
    destroy loo_Config
    destroy loo_AccountText
    destroy loo_AllowedAccountChars
    destroy loo_Endpoint
    destroy loo_Rest
    destroy loo_AzAuth
    destroy loo_Connection
    return
end if

loo_ResponseBody = create oleobject
li_rc = loo_ResponseBody.ConnectToNewObject("Chilkat.StringBuilder")

li_Success = loo_Rest.AddHeader("DataServiceVersion","3.0;NetFx")
if li_Success <> 1 then
    Write-Debug "Could not prepare the request."
    destroy loo_TextCompare
    destroy loo_Config
    destroy loo_AccountText
    destroy loo_AllowedAccountChars
    destroy loo_Endpoint
    destroy loo_Rest
    destroy loo_AzAuth
    destroy loo_Connection
    destroy loo_ResponseBody
    return
end if

li_Success = loo_Rest.AddHeader("MaxDataServiceVersion","3.0;NetFx")
if li_Success <> 1 then
    Write-Debug "Could not prepare the request."
    destroy loo_TextCompare
    destroy loo_Config
    destroy loo_AccountText
    destroy loo_AllowedAccountChars
    destroy loo_Endpoint
    destroy loo_Rest
    destroy loo_AzAuth
    destroy loo_Connection
    destroy loo_ResponseBody
    return
end if

li_Success = loo_Rest.AddHeader("Content-Type","application/json")
if li_Success <> 1 then
    Write-Debug "Could not prepare the request."
    destroy loo_TextCompare
    destroy loo_Config
    destroy loo_AccountText
    destroy loo_AllowedAccountChars
    destroy loo_Endpoint
    destroy loo_Rest
    destroy loo_AzAuth
    destroy loo_Connection
    destroy loo_ResponseBody
    return
end if

li_Success = loo_Rest.AddHeader("Accept","application/json;odata=minimalmetadata")
if li_Success <> 1 then
    Write-Debug "Could not prepare the request."
    destroy loo_TextCompare
    destroy loo_Config
    destroy loo_AccountText
    destroy loo_AllowedAccountChars
    destroy loo_Endpoint
    destroy loo_Rest
    destroy loo_AzAuth
    destroy loo_Connection
    destroy loo_ResponseBody
    return
end if

li_Success = loo_Rest.AddHeader("Prefer","return-no-content")
if li_Success <> 1 then
    Write-Debug "Could not prepare the request."
    destroy loo_TextCompare
    destroy loo_Config
    destroy loo_AccountText
    destroy loo_AllowedAccountChars
    destroy loo_Endpoint
    destroy loo_Rest
    destroy loo_AzAuth
    destroy loo_Connection
    destroy loo_ResponseBody
    return
end if

//  The table must already exist. Change resourcePath above to your table's name.
//  PartitionKey + RowKey uniquely identify the entity. Inserting an existing pair returns 409.
//  Adapt these fixed sample values; keys cannot contain /, backslash, #, ?, or control characters.
//  Timestamp is server-managed; do not put it in the request.
loo_Json = create oleobject
li_rc = loo_Json.ConnectToNewObject("Chilkat.JsonObject")

li_Success = loo_Json.UpdateString("PartitionKey","customers-west")
if li_Success <> 1 then
    Write-Debug "Could not prepare the request."
    destroy loo_TextCompare
    destroy loo_Config
    destroy loo_AccountText
    destroy loo_AllowedAccountChars
    destroy loo_Endpoint
    destroy loo_Rest
    destroy loo_AzAuth
    destroy loo_Connection
    destroy loo_ResponseBody
    destroy loo_Json
    return
end if

li_Success = loo_Json.UpdateString("RowKey","customer-001")
if li_Success <> 1 then
    Write-Debug "Could not prepare the request."
    destroy loo_TextCompare
    destroy loo_Config
    destroy loo_AccountText
    destroy loo_AllowedAccountChars
    destroy loo_Endpoint
    destroy loo_Rest
    destroy loo_AzAuth
    destroy loo_Connection
    destroy loo_ResponseBody
    destroy loo_Json
    return
end if

li_Success = loo_Json.UpdateString("Address","Mountain View")
if li_Success <> 1 then
    Write-Debug "Could not prepare the request."
    destroy loo_TextCompare
    destroy loo_Config
    destroy loo_AccountText
    destroy loo_AllowedAccountChars
    destroy loo_Endpoint
    destroy loo_Rest
    destroy loo_AzAuth
    destroy loo_Connection
    destroy loo_ResponseBody
    destroy loo_Json
    return
end if

li_Success = loo_Json.UpdateInt("Age",23)
if li_Success <> 1 then
    Write-Debug "Could not prepare the request."
    destroy loo_TextCompare
    destroy loo_Config
    destroy loo_AccountText
    destroy loo_AllowedAccountChars
    destroy loo_Endpoint
    destroy loo_Rest
    destroy loo_AzAuth
    destroy loo_Connection
    destroy loo_ResponseBody
    destroy loo_Json
    return
end if

li_Success = loo_Json.UpdateNumber("AmountDue","200.23")
if li_Success <> 1 then
    Write-Debug "Could not prepare the request."
    destroy loo_TextCompare
    destroy loo_Config
    destroy loo_AccountText
    destroy loo_AllowedAccountChars
    destroy loo_Endpoint
    destroy loo_Rest
    destroy loo_AzAuth
    destroy loo_Connection
    destroy loo_ResponseBody
    destroy loo_Json
    return
end if

//  AmountDue is Edm.Double, not exact decimal currency. Use an integer minor-unit design for exact money.
//  Quote the whole JSON path so @odata.type is a literal property name.
li_Success = loo_Json.UpdateString("~"CustomerCode@odata.type~"","Edm.Guid")
if li_Success <> 1 then
    Write-Debug "Could not prepare the request."
    destroy loo_TextCompare
    destroy loo_Config
    destroy loo_AccountText
    destroy loo_AllowedAccountChars
    destroy loo_Endpoint
    destroy loo_Rest
    destroy loo_AzAuth
    destroy loo_Connection
    destroy loo_ResponseBody
    destroy loo_Json
    return
end if

li_Success = loo_Json.UpdateString("CustomerCode","c9da6455-213d-42c9-9a79-3e9149a57833")
if li_Success <> 1 then
    Write-Debug "Could not prepare the request."
    destroy loo_TextCompare
    destroy loo_Config
    destroy loo_AccountText
    destroy loo_AllowedAccountChars
    destroy loo_Endpoint
    destroy loo_Rest
    destroy loo_AzAuth
    destroy loo_Connection
    destroy loo_ResponseBody
    destroy loo_Json
    return
end if

//  Quote the whole JSON path so @odata.type is a literal property name.
li_Success = loo_Json.UpdateString("~"CustomerSince@odata.type~"","Edm.DateTime")
if li_Success <> 1 then
    Write-Debug "Could not prepare the request."
    destroy loo_TextCompare
    destroy loo_Config
    destroy loo_AccountText
    destroy loo_AllowedAccountChars
    destroy loo_Endpoint
    destroy loo_Rest
    destroy loo_AzAuth
    destroy loo_Connection
    destroy loo_ResponseBody
    destroy loo_Json
    return
end if

li_Success = loo_Json.UpdateString("CustomerSince","2008-07-10T00:00:00Z")
if li_Success <> 1 then
    Write-Debug "Could not prepare the request."
    destroy loo_TextCompare
    destroy loo_Config
    destroy loo_AccountText
    destroy loo_AllowedAccountChars
    destroy loo_Endpoint
    destroy loo_Rest
    destroy loo_AzAuth
    destroy loo_Connection
    destroy loo_ResponseBody
    destroy loo_Json
    return
end if

//  Quote the whole JSON path so @odata.type is a literal property name.
li_Success = loo_Json.UpdateString("~"NumberOfOrders@odata.type~"","Edm.Int64")
if li_Success <> 1 then
    Write-Debug "Could not prepare the request."
    destroy loo_TextCompare
    destroy loo_Config
    destroy loo_AccountText
    destroy loo_AllowedAccountChars
    destroy loo_Endpoint
    destroy loo_Rest
    destroy loo_AzAuth
    destroy loo_Connection
    destroy loo_ResponseBody
    destroy loo_Json
    return
end if

li_Success = loo_Json.UpdateString("NumberOfOrders","9007199254740993")
if li_Success <> 1 then
    Write-Debug "Could not prepare the request."
    destroy loo_TextCompare
    destroy loo_Config
    destroy loo_AccountText
    destroy loo_AllowedAccountChars
    destroy loo_Endpoint
    destroy loo_Rest
    destroy loo_AzAuth
    destroy loo_Connection
    destroy loo_ResponseBody
    destroy loo_Json
    return
end if

li_Success = loo_Json.UpdateBool("IsActive",1)
if li_Success <> 1 then
    Write-Debug "Could not prepare the request."
    destroy loo_TextCompare
    destroy loo_Config
    destroy loo_AccountText
    destroy loo_AllowedAccountChars
    destroy loo_Endpoint
    destroy loo_Rest
    destroy loo_AzAuth
    destroy loo_Connection
    destroy loo_ResponseBody
    destroy loo_Json
    return
end if

loo_RequestBody = create oleobject
li_rc = loo_RequestBody.ConnectToNewObject("Chilkat.StringBuilder")

li_Success = loo_Json.EmitSb(loo_RequestBody)
if li_Success <> 1 then
    Write-Debug "Could not serialize the JSON request."
    destroy loo_TextCompare
    destroy loo_Config
    destroy loo_AccountText
    destroy loo_AllowedAccountChars
    destroy loo_Endpoint
    destroy loo_Rest
    destroy loo_AzAuth
    destroy loo_Connection
    destroy loo_ResponseBody
    destroy loo_Json
    destroy loo_RequestBody
    return
end if

li_Success = loo_Rest.FullRequestSb("POST",ls_ResourcePath,loo_RequestBody,loo_ResponseBody)
if li_Success <> 1 then
    Write-Debug "Request did not complete; check the target before retrying."
    destroy loo_TextCompare
    destroy loo_Config
    destroy loo_AccountText
    destroy loo_AllowedAccountChars
    destroy loo_Endpoint
    destroy loo_Rest
    destroy loo_AzAuth
    destroy loo_Connection
    destroy loo_ResponseBody
    destroy loo_Json
    destroy loo_RequestBody
    return
end if

if loo_Rest.ResponseStatusCode <> 204 then
    Write-Debug "HTTP status: " + string(loo_Rest.ResponseStatusCode)
    Write-Debug "Request ID: " + loo_Rest.ResponseHdrByName("x-ms-request-id")
    //  A conflict is not success. Do not replay or convert this request into an upsert.
    if loo_Rest.ResponseStatusCode = 409 then
        Write-Debug "The table/entity may already exist, or a table may still be deleting. Inspect its state."
    end if

    //  Table errors may be in an OData JSON body instead of x-ms-error-code.
    //  Keep the body and LastErrorText private; they can contain entity data.
    destroy loo_TextCompare
    destroy loo_Config
    destroy loo_AccountText
    destroy loo_AllowedAccountChars
    destroy loo_Endpoint
    destroy loo_Rest
    destroy loo_AzAuth
    destroy loo_Connection
    destroy loo_ResponseBody
    destroy loo_Json
    destroy loo_RequestBody
    return
end if

//  HTTP 204 has no JSON body. Preserve this ETag exactly, including W/ and quotes,
//  for a later conditional update or delete with If-Match.
ls_EntityEtag = loo_Rest.ResponseHdrByName("ETag")
loo_TextCompare.Clear()
loo_TextCompare.SetString(ls_EntityEtag)
li_SameText3 = loo_TextCompare.ContentsEqual("",1)
if li_SameText3 = 1 then
    Write-Debug "Entity inserted, but ETag is missing. Retrieve the entity before a conditional write; do not repeat the insert."
    destroy loo_TextCompare
    destroy loo_Config
    destroy loo_AccountText
    destroy loo_AllowedAccountChars
    destroy loo_Endpoint
    destroy loo_Rest
    destroy loo_AzAuth
    destroy loo_Connection
    destroy loo_ResponseBody
    destroy loo_Json
    destroy loo_RequestBody
    return
end if

Write-Debug "Entity inserted."
Write-Debug "ETag: " + ls_EntityEtag


destroy loo_TextCompare
destroy loo_Config
destroy loo_AccountText
destroy loo_AllowedAccountChars
destroy loo_Endpoint
destroy loo_Rest
destroy loo_AzAuth
destroy loo_Connection
destroy loo_ResponseBody
destroy loo_Json
destroy loo_RequestBody