Azure Table: Read an Entity with a Supplied Table SAS
See more Azure Table Service Examples
Loads table-sas.txt created by the related service-SAS example, or supplied by a trusted issuer. storage.json needs only account. Sends no Authorization header or account key; Chilkat parses and encodes the token query once. The endpoint and entity path remain fixed by the application, not by the supplied token. A 403 may indicate expiry, insufficient permission, account policy or an entity outside the signed range.
Targets Azure Storage Table service in the public cloud, not Azure Cosmos DB for Table. Uses Chilkat 11.6.0 or later and an unlocked library. Direct data requests pin x-ms-version 2026-04-06 and OData 3.0. Shared Key examples read private qa_data/azure/storage.json with account and access_key string fields. Authentication examples explain their additional fields. Create private local directories before running; keep credentials, tokens, SAS, entity values, checkpoints and diagnostics outside public content and source control.
HTTPS certificates are verified. Transport completion and HTTP status are checked separately. Writes are not automatically retried after an uncertain outcome. Entity keys, ETags and continuation tokens remain strings. Examples operate on the existing ExampleCustomers table unless noted; review the targets before adapting them. Microsoft Entra ID with suitable Table data roles is preferred where available.
Chilkat PowerBuilder Downloads
integer li_rc
long li_Success
oleobject loo_TextCompare
oleobject loo_Config
long li_SameText1
oleobject loo_AccountText
oleobject loo_AllowedAccountChars
long li_CharIndex
oleobject loo_Endpoint
string ls_ResourcePath
oleobject loo_Rest
oleobject loo_Connection
string ls_ResponseText
oleobject loo_Result
oleobject loo_SasText
string ls_PartitionKey
string ls_RowKey
oleobject loo_EncodedPk
long li_EscapedencodedPk
oleobject loo_EncodedRk
long li_EscapedencodedRk
oleobject loo_EntityPath
long li_SameText2
long li_SameText3
long li_SameText4
long li_SameText5
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
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_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_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_Connection
return
end if
loo_Result = create oleobject
li_rc = loo_Result.ConnectToNewObject("Chilkat.JsonObject")
loo_Result.Strict = 1
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_Connection
destroy loo_Result
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_Connection
destroy loo_Result
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_Connection
destroy loo_Result
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_Connection
destroy loo_Result
return
end if
li_Success = loo_Rest.AddHeader("x-ms-version","2026-04-06")
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_Connection
destroy loo_Result
return
end if
loo_SasText = create oleobject
li_rc = loo_SasText.ConnectToNewObject("Chilkat.StringBuilder")
li_Success = loo_SasText.LoadFile("qa_data/azure/table-sas.txt","utf-8")
if li_Success <> 1 then
Write-Debug "Could not read private SAS token."
destroy loo_TextCompare
destroy loo_Config
destroy loo_AccountText
destroy loo_AllowedAccountChars
destroy loo_Endpoint
destroy loo_Rest
destroy loo_Connection
destroy loo_Result
destroy loo_SasText
return
end if
li_Success = loo_SasText.Trim()
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_Connection
destroy loo_Result
destroy loo_SasText
return
end if
if (loo_SasText.Length = 0) OR (loo_SasText.Contains("?",1) = 1) OR (loo_SasText.Contains("#",1) = 1) OR (loo_SasText.Contains("~r",1) = 1) OR (loo_SasText.Contains("~n",1) = 1) then
Write-Debug "Expected a SAS query string without a leading ?, fragment, or line break."
destroy loo_TextCompare
destroy loo_Config
destroy loo_AccountText
destroy loo_AllowedAccountChars
destroy loo_Endpoint
destroy loo_Rest
destroy loo_Connection
destroy loo_Result
destroy loo_SasText
return
end if
li_Success = loo_Rest.AddQueryParams(loo_SasText.GetAsString())
if li_Success <> 1 then
Write-Debug "Could not parse SAS query parameters."
destroy loo_TextCompare
destroy loo_Config
destroy loo_AccountText
destroy loo_AllowedAccountChars
destroy loo_Endpoint
destroy loo_Rest
destroy loo_Connection
destroy loo_Result
destroy loo_SasText
return
end if
ls_PartitionKey = "customers-west"
ls_RowKey = "customer-001"
loo_EncodedPk = create oleobject
li_rc = loo_EncodedPk.ConnectToNewObject("Chilkat.StringBuilder")
li_Success = loo_EncodedPk.Append(ls_PartitionKey)
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_Connection
destroy loo_Result
destroy loo_SasText
destroy loo_EncodedPk
return
end if
li_EscapedencodedPk = loo_EncodedPk.Replace("'","''")
li_Success = loo_EncodedPk.Encode("url_rfc3986","utf-8")
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_Connection
destroy loo_Result
destroy loo_SasText
destroy loo_EncodedPk
return
end if
loo_EncodedRk = create oleobject
li_rc = loo_EncodedRk.ConnectToNewObject("Chilkat.StringBuilder")
li_Success = loo_EncodedRk.Append(ls_RowKey)
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_Connection
destroy loo_Result
destroy loo_SasText
destroy loo_EncodedPk
destroy loo_EncodedRk
return
end if
li_EscapedencodedRk = loo_EncodedRk.Replace("'","''")
li_Success = loo_EncodedRk.Encode("url_rfc3986","utf-8")
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_Connection
destroy loo_Result
destroy loo_SasText
destroy loo_EncodedPk
destroy loo_EncodedRk
return
end if
// Escape apostrophes for OData first, then percent-encode each key once.
loo_EntityPath = create oleobject
li_rc = loo_EntityPath.ConnectToNewObject("Chilkat.StringBuilder")
li_Success = loo_EntityPath.Append("/ExampleCustomers(PartitionKey='")
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_Connection
destroy loo_Result
destroy loo_SasText
destroy loo_EncodedPk
destroy loo_EncodedRk
destroy loo_EntityPath
return
end if
li_Success = loo_EntityPath.Append(loo_EncodedPk.GetAsString())
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_Connection
destroy loo_Result
destroy loo_SasText
destroy loo_EncodedPk
destroy loo_EncodedRk
destroy loo_EntityPath
return
end if
li_Success = loo_EntityPath.Append("',RowKey='")
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_Connection
destroy loo_Result
destroy loo_SasText
destroy loo_EncodedPk
destroy loo_EncodedRk
destroy loo_EntityPath
return
end if
li_Success = loo_EntityPath.Append(loo_EncodedRk.GetAsString())
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_Connection
destroy loo_Result
destroy loo_SasText
destroy loo_EncodedPk
destroy loo_EncodedRk
destroy loo_EntityPath
return
end if
li_Success = loo_EntityPath.Append("')")
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_Connection
destroy loo_Result
destroy loo_SasText
destroy loo_EncodedPk
destroy loo_EncodedRk
destroy loo_EntityPath
return
end if
ls_ResourcePath = loo_EntityPath.GetAsString()
ls_ResponseText = loo_Rest.FullRequestNoBody("GET",ls_ResourcePath)
if loo_Rest.LastMethodSuccess <> 1 then
Write-Debug "Request did not complete; inspect the target before retrying a write."
destroy loo_TextCompare
destroy loo_Config
destroy loo_AccountText
destroy loo_AllowedAccountChars
destroy loo_Endpoint
destroy loo_Rest
destroy loo_Connection
destroy loo_Result
destroy loo_SasText
destroy loo_EncodedPk
destroy loo_EncodedRk
destroy loo_EntityPath
return
end if
if loo_Rest.ResponseStatusCode <> 200 then
Write-Debug "HTTP status: " + string(loo_Rest.ResponseStatusCode)
Write-Debug "Request ID: " + loo_Rest.ResponseHdrByName("x-ms-request-id")
// 404 is missing, 409 is conflict, and 412 is a stale ETag: none are success.
// Keep response bodies private. Reconcile uncertain writes before retrying.
destroy loo_TextCompare
destroy loo_Config
destroy loo_AccountText
destroy loo_AllowedAccountChars
destroy loo_Endpoint
destroy loo_Rest
destroy loo_Connection
destroy loo_Result
destroy loo_SasText
destroy loo_EncodedPk
destroy loo_EncodedRk
destroy loo_EntityPath
return
end if
li_Success = loo_Result.Load(ls_ResponseText)
if li_Success <> 1 then
Write-Debug "Expected well-formed JSON."
destroy loo_TextCompare
destroy loo_Config
destroy loo_AccountText
destroy loo_AllowedAccountChars
destroy loo_Endpoint
destroy loo_Rest
destroy loo_Connection
destroy loo_Result
destroy loo_SasText
destroy loo_EncodedPk
destroy loo_EncodedRk
destroy loo_EntityPath
return
end if
loo_TextCompare.Clear()
loo_TextCompare.SetString(loo_Result.StringOf("PartitionKey"))
li_SameText2 = loo_TextCompare.ContentsEqual("",1)
if (loo_Result.JsonTypeOf("PartitionKey") <> 1) OR (li_SameText2 = 1) then
Write-Debug "Missing string PartitionKey."
destroy loo_TextCompare
destroy loo_Config
destroy loo_AccountText
destroy loo_AllowedAccountChars
destroy loo_Endpoint
destroy loo_Rest
destroy loo_Connection
destroy loo_Result
destroy loo_SasText
destroy loo_EncodedPk
destroy loo_EncodedRk
destroy loo_EntityPath
return
end if
loo_TextCompare.Clear()
loo_TextCompare.SetString(loo_Result.StringOf("RowKey"))
li_SameText3 = loo_TextCompare.ContentsEqual("",1)
if (loo_Result.JsonTypeOf("RowKey") <> 1) OR (li_SameText3 = 1) then
Write-Debug "Missing string RowKey."
destroy loo_TextCompare
destroy loo_Config
destroy loo_AccountText
destroy loo_AllowedAccountChars
destroy loo_Endpoint
destroy loo_Rest
destroy loo_Connection
destroy loo_Result
destroy loo_SasText
destroy loo_EncodedPk
destroy loo_EncodedRk
destroy loo_EntityPath
return
end if
loo_TextCompare.Clear()
loo_TextCompare.SetString(loo_Result.StringOf("PartitionKey"))
li_SameText4 = loo_TextCompare.ContentsEqual(ls_PartitionKey,1)
loo_TextCompare.Clear()
loo_TextCompare.SetString(loo_Result.StringOf("RowKey"))
li_SameText5 = loo_TextCompare.ContentsEqual(ls_RowKey,1)
if (li_SameText4 <> 1) OR (li_SameText5 <> 1) then
Write-Debug "Returned entity keys do not match."
destroy loo_TextCompare
destroy loo_Config
destroy loo_AccountText
destroy loo_AllowedAccountChars
destroy loo_Endpoint
destroy loo_Rest
destroy loo_Connection
destroy loo_Result
destroy loo_SasText
destroy loo_EncodedPk
destroy loo_EncodedRk
destroy loo_EntityPath
return
end if
Write-Debug "Entity retrieved with the supplied SAS."
destroy loo_TextCompare
destroy loo_Config
destroy loo_AccountText
destroy loo_AllowedAccountChars
destroy loo_Endpoint
destroy loo_Rest
destroy loo_Connection
destroy loo_Result
destroy loo_SasText
destroy loo_EncodedPk
destroy loo_EncodedRk
destroy loo_EntityPath