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

Azure Table: Read an Entity with Entra Client Credentials

See more Azure Table Service Examples

Supply tenant_id (directory GUID), client_id and client_secret in private storage.json. This confidential-client flow requests the Storage .default scope; it has no refresh token. Assign Storage Table Data Reader or an appropriate Table data role. A management-plane Contributor role alone is not sufficient. Acquires a Storage-audience token and actually uses it to retrieve an entity, without an account key.

Saves only access_token, expires_at and resource to private table-token.json, replacing the prior cache. Uses request-start time for expiry. Reacquire before expiry; do not print the token or embed a client secret in a public client. This sample stops on identity errors rather than applying a generic retry policy.

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.

Microsoft reference.

Chilkat AutoIt Downloads

AutoIt
Local $bSuccess = False

;  StringBuilder compares text by value in every generated language.
$oTextCompare = ObjCreate("Chilkat.StringBuilder")
;  Assumes Chilkat is unlocked. See Global Unlock Sample.
$bSuccess = False
$oConfig = ObjCreate("Chilkat.JsonObject")
$oConfig.Strict = True
$bSuccess = $oConfig.LoadFile("qa_data/azure/storage.json")
If ($bSuccess <> True) Then
    ConsoleWrite("Could not load private Azure configuration." & @CRLF)
    Exit
EndIf

$oTextCompare.Clear 
$oTextCompare.SetString($oConfig.StringOf("account"))
Local $bSameText1 = $oTextCompare.ContentsEqual("",True)
If (($oConfig.JsonTypeOf("account") <> 1) Or ($bSameText1 = True)) Then
    ConsoleWrite("Supply the storage account name." & @CRLF)
    Exit
EndIf

$oIdentity = ObjCreate("Chilkat.Rest")
$oIdentity.ConnectTimeoutMs = 5000
$oIdentity.IdleTimeoutMs = 30000
$oExpires = ObjCreate("Chilkat.CkDateTime")
$bSuccess = $oExpires.SetFromCurrentSystemTime()
If ($bSuccess <> True) Then
    ConsoleWrite("Could not prepare the request." & @CRLF)
    Exit
EndIf

$oTextCompare.Clear 
$oTextCompare.SetString($oConfig.StringOf("tenant_id"))
Local $bSameText2 = $oTextCompare.ContentsEqual("",True)
If (($oConfig.JsonTypeOf("tenant_id") <> 1) Or ($bSameText2 = True)) Then
    ConsoleWrite("Missing string tenant_id." & @CRLF)
    Exit
EndIf

$oTextCompare.Clear 
$oTextCompare.SetString($oConfig.StringOf("client_id"))
Local $bSameText3 = $oTextCompare.ContentsEqual("",True)
If (($oConfig.JsonTypeOf("client_id") <> 1) Or ($bSameText3 = True)) Then
    ConsoleWrite("Missing string client_id." & @CRLF)
    Exit
EndIf

$oTextCompare.Clear 
$oTextCompare.SetString($oConfig.StringOf("client_secret"))
Local $bSameText4 = $oTextCompare.ContentsEqual("",True)
If (($oConfig.JsonTypeOf("client_secret") <> 1) Or ($bSameText4 = True)) Then
    ConsoleWrite("Missing string client_secret." & @CRLF)
    Exit
EndIf

$oValidate1 = ObjCreate("Chilkat.StringBuilder")
$oAlphabet1 = ObjCreate("Chilkat.StringBuilder")
$bSuccess = $oValidate1.Append($oConfig.StringOf("tenant_id"))
If ($bSuccess <> True) Then
    ConsoleWrite("Could not prepare the request." & @CRLF)
    Exit
EndIf

$bSuccess = $oAlphabet1.Append("0123456789abcdefABCDEF-")
If ($bSuccess <> True) Then
    ConsoleWrite("Could not prepare the request." & @CRLF)
    Exit
EndIf

If (($oValidate1.Length < 36) Or ($oValidate1.Length > 36)) Then
    ConsoleWrite("Invalid tenant GUID length." & @CRLF)
    Exit
EndIf

Local $index1 = 0
While ($index1 < $oValidate1.Length)
    If ($oAlphabet1.Contains($oValidate1.GetRange($index1,1,False),True) <> True) Then
        ConsoleWrite("Invalid tenant GUID." & @CRLF)
        Exit
    EndIf

    $index1 = $index1 + 1
Wend
$oIdentityTls = ObjCreate("Chilkat.Socket")
$oIdentityTls.RequireSslCertVerify = True
$oIdentityTls.MaxReadIdleMs = 30000
$oIdentityTls.MaxSendIdleMs = 30000
$bSuccess = $oIdentityTls.Connect("login.microsoftonline.com",443,True,20000)
If ($bSuccess <> True) Then
    ConsoleWrite("Identity TLS connection failed." & @CRLF)
    Exit
EndIf

$bSuccess = $oIdentity.UseConnection($oIdentityTls,False)
If ($bSuccess <> True) Then
    ConsoleWrite("Could not prepare the request." & @CRLF)
    Exit
EndIf

$oTokenPath = ObjCreate("Chilkat.StringBuilder")
$bSuccess = $oTokenPath.Append("/")
If ($bSuccess <> True) Then
    ConsoleWrite("Could not prepare the request." & @CRLF)
    Exit
EndIf

$bSuccess = $oTokenPath.Append($oConfig.StringOf("tenant_id"))
If ($bSuccess <> True) Then
    ConsoleWrite("Could not prepare the request." & @CRLF)
    Exit
EndIf

$bSuccess = $oTokenPath.Append("/oauth2/v2.0/token")
If ($bSuccess <> True) Then
    ConsoleWrite("Could not prepare the request." & @CRLF)
    Exit
EndIf

$bSuccess = $oIdentity.AddQueryParam("grant_type","client_credentials")
If ($bSuccess <> True) Then
    ConsoleWrite("Could not prepare the request." & @CRLF)
    Exit
EndIf

$bSuccess = $oIdentity.AddQueryParam("scope","https://storage.azure.com/.default")
If ($bSuccess <> True) Then
    ConsoleWrite("Could not prepare the request." & @CRLF)
    Exit
EndIf

$bSuccess = $oIdentity.AddQueryParam("client_id",$oConfig.StringOf("client_id"))
If ($bSuccess <> True) Then
    ConsoleWrite("Could not prepare the request." & @CRLF)
    Exit
EndIf

$bSuccess = $oIdentity.AddQueryParam("client_secret",$oConfig.StringOf("client_secret"))
If ($bSuccess <> True) Then
    ConsoleWrite("Could not prepare the request." & @CRLF)
    Exit
EndIf

;  FullRequestFormUrlEncoded places the parameters in the POST body, not the URL.
Local $sTokenText = $oIdentity.FullRequestFormUrlEncoded("POST",$oTokenPath.GetAsString())
If ($oIdentity.LastMethodSuccess <> True) Then
    ConsoleWrite("Token request did not complete." & @CRLF)
    Exit
EndIf

If ($oIdentity.ResponseStatusCode <> 200) Then
    ConsoleWrite("Token request failed; keep its body and diagnostics private." & @CRLF)
    Exit
EndIf

$oToken = ObjCreate("Chilkat.JsonObject")
$oToken.Strict = True
$bSuccess = $oToken.Load($sTokenText)
If ($bSuccess <> True) Then
    ConsoleWrite("Expected token JSON." & @CRLF)
    Exit
EndIf

$oTextCompare.Clear 
$oTextCompare.SetString($oToken.StringOf("access_token"))
Local $bSameText5 = $oTextCompare.ContentsEqual("",True)
If (($oToken.JsonTypeOf("access_token") <> 1) Or ($bSameText5 = True)) Then
    ConsoleWrite("Missing string access_token." & @CRLF)
    Exit
EndIf

$oTextCompare.Clear 
$oTextCompare.SetString($oToken.StringOf("token_type"))
Local $bSameText6 = $oTextCompare.ContentsEqual("Bearer",True)
If ($bSameText6 <> True) Then
    ConsoleWrite("Expected a bearer token." & @CRLF)
    Exit
EndIf

If (($oToken.JsonTypeOf("expires_in") <> 2)) Then
    ConsoleWrite("Invalid token lifetime type." & @CRLF)
    Exit
EndIf

$oValidate2 = ObjCreate("Chilkat.StringBuilder")
$oAlphabet2 = ObjCreate("Chilkat.StringBuilder")
$bSuccess = $oValidate2.Append($oToken.StringOf("expires_in"))
If ($bSuccess <> True) Then
    ConsoleWrite("Could not prepare the request." & @CRLF)
    Exit
EndIf

$bSuccess = $oAlphabet2.Append("0123456789")
If ($bSuccess <> True) Then
    ConsoleWrite("Could not prepare the request." & @CRLF)
    Exit
EndIf

If (($oValidate2.Length < 1) Or ($oValidate2.Length > 6)) Then
    ConsoleWrite("Invalid token lifetime length." & @CRLF)
    Exit
EndIf

Local $index2 = 0
While ($index2 < $oValidate2.Length)
    If ($oAlphabet2.Contains($oValidate2.GetRange($index2,1,False),True) <> True) Then
        ConsoleWrite("Invalid token lifetime." & @CRLF)
        Exit
    EndIf

    $index2 = $index2 + 1
Wend
Local $iSeconds = $oToken.IntOf("expires_in")
If (($iSeconds < 120) Or ($iSeconds > 86400)) Then
    ConsoleWrite("Unexpected token lifetime." & @CRLF)
    Exit
EndIf

$bSuccess = $oExpires.AddSeconds($iSeconds)
If ($bSuccess <> True) Then
    ConsoleWrite("Could not prepare the request." & @CRLF)
    Exit
EndIf

$oNow = ObjCreate("Chilkat.CkDateTime")
$bSuccess = $oNow.SetFromCurrentSystemTime()
If ($bSuccess <> True) Then
    ConsoleWrite("Could not prepare the request." & @CRLF)
    Exit
EndIf

If ($oExpires.DiffSeconds($oNow) <= 60) Then
    ConsoleWrite("Token expired while the request was in progress." & @CRLF)
    Exit
EndIf

$oSaved = ObjCreate("Chilkat.JsonObject")
$bSuccess = $oSaved.UpdateString("access_token",$oToken.StringOf("access_token"))
If ($bSuccess <> True) Then
    ConsoleWrite("Could not prepare the request." & @CRLF)
    Exit
EndIf

$bSuccess = $oSaved.UpdateString("expires_at",$oExpires.GetAsTimestamp(False))
If ($bSuccess <> True) Then
    ConsoleWrite("Could not prepare the request." & @CRLF)
    Exit
EndIf

$bSuccess = $oSaved.UpdateString("resource","https://storage.azure.com/")
If ($bSuccess <> True) Then
    ConsoleWrite("Could not prepare the request." & @CRLF)
    Exit
EndIf

$bSuccess = $oSaved.WriteFile("qa_data/azure/table-token.json")
If ($bSuccess <> True) Then
    ConsoleWrite("Could not save the private token file." & @CRLF)
    Exit
EndIf

$oAccountText = ObjCreate("Chilkat.StringBuilder")
$bSuccess = $oAccountText.Append($oConfig.StringOf("account"))
If ($bSuccess <> True) Then
    ConsoleWrite("Could not prepare the request." & @CRLF)
    Exit
EndIf

If (($oAccountText.Length < 3) Or ($oAccountText.Length > 24)) Then
    ConsoleWrite("Storage account names need 3-24 lowercase letters or digits." & @CRLF)
    Exit
EndIf

$oAllowedAccountChars = ObjCreate("Chilkat.StringBuilder")
$bSuccess = $oAllowedAccountChars.Append("abcdefghijklmnopqrstuvwxyz0123456789")
If ($bSuccess <> True) Then
    ConsoleWrite("Could not prepare the request." & @CRLF)
    Exit
EndIf

Local $iCharIndex = 0
While ($iCharIndex < $oAccountText.Length)
    If ($oAllowedAccountChars.Contains($oAccountText.GetRange($iCharIndex,1,False),True) <> True) Then
        ConsoleWrite("Storage account names need lowercase letters or digits." & @CRLF)
        Exit
    EndIf

    $iCharIndex = $iCharIndex + 1
Wend
$oEndpoint = ObjCreate("Chilkat.StringBuilder")
$bSuccess = $oEndpoint.Append($oConfig.StringOf("account"))
If ($bSuccess <> True) Then
    ConsoleWrite("Could not prepare the request." & @CRLF)
    Exit
EndIf

$bSuccess = $oEndpoint.Append(".table.core.windows.net")
If ($bSuccess <> True) Then
    ConsoleWrite("Could not prepare the request." & @CRLF)
    Exit
EndIf

;  Table names contain only letters and digits and are case-insensitive.
;  Entity PartitionKey and RowKey values are case-sensitive.
Local $sResourcePath = "/ExampleCustomers()"
$oRest = ObjCreate("Chilkat.Rest")
$oRest.ConnectTimeoutMs = 20000
$oRest.IdleTimeoutMs = 60000
$oConnection = ObjCreate("Chilkat.Socket")
$oConnection.RequireSslCertVerify = True
$oConnection.MaxReadIdleMs = 60000
$oConnection.MaxSendIdleMs = 60000
$bSuccess = $oConnection.Connect($oEndpoint.GetAsString(),443,True,20000)
If ($bSuccess <> True) Then
    ConsoleWrite("TLS connection failed; inspect diagnostics privately." & @CRLF)
    Exit
EndIf

;  Do not replay a write automatically after losing its response.
$bSuccess = $oRest.UseConnection($oConnection,False)
If ($bSuccess <> True) Then
    ConsoleWrite("Could not prepare the request." & @CRLF)
    Exit
EndIf

Local $sResponseText
$oResult = ObjCreate("Chilkat.JsonObject")
$oResult.Strict = True
$bSuccess = $oRest.AddHeader("DataServiceVersion","3.0;NetFx")
If ($bSuccess <> True) Then
    ConsoleWrite("Could not prepare the request." & @CRLF)
    Exit
EndIf

$bSuccess = $oRest.AddHeader("MaxDataServiceVersion","3.0;NetFx")
If ($bSuccess <> True) Then
    ConsoleWrite("Could not prepare the request." & @CRLF)
    Exit
EndIf

$bSuccess = $oRest.AddHeader("Content-Type","application/json")
If ($bSuccess <> True) Then
    ConsoleWrite("Could not prepare the request." & @CRLF)
    Exit
EndIf

$bSuccess = $oRest.AddHeader("Accept","application/json;odata=minimalmetadata")
If ($bSuccess <> True) Then
    ConsoleWrite("Could not prepare the request." & @CRLF)
    Exit
EndIf

$bSuccess = $oRest.AddHeader("x-ms-version","2026-04-06")
If ($bSuccess <> True) Then
    ConsoleWrite("Could not prepare the request." & @CRLF)
    Exit
EndIf

$oAuthorization = ObjCreate("Chilkat.StringBuilder")
$bSuccess = $oAuthorization.Append("Bearer ")
If ($bSuccess <> True) Then
    ConsoleWrite("Could not prepare the request." & @CRLF)
    Exit
EndIf

$bSuccess = $oAuthorization.Append($oToken.StringOf("access_token"))
If ($bSuccess <> True) Then
    ConsoleWrite("Could not prepare the request." & @CRLF)
    Exit
EndIf

$bSuccess = $oRest.AddHeader("Authorization",$oAuthorization.GetAsString())
If ($bSuccess <> True) Then
    ConsoleWrite("Could not prepare the request." & @CRLF)
    Exit
EndIf

Local $sPartitionKey = "customers-west"
Local $sRowKey = "customer-001"
$oEncodedPk = ObjCreate("Chilkat.StringBuilder")
$bSuccess = $oEncodedPk.Append($sPartitionKey)
If ($bSuccess <> True) Then
    ConsoleWrite("Could not prepare the request." & @CRLF)
    Exit
EndIf

Local $iEscapedencodedPk = $oEncodedPk.Replace("'","''")
$bSuccess = $oEncodedPk.Encode("url_rfc3986","utf-8")
If ($bSuccess <> True) Then
    ConsoleWrite("Could not prepare the request." & @CRLF)
    Exit
EndIf

$oEncodedRk = ObjCreate("Chilkat.StringBuilder")
$bSuccess = $oEncodedRk.Append($sRowKey)
If ($bSuccess <> True) Then
    ConsoleWrite("Could not prepare the request." & @CRLF)
    Exit
EndIf

Local $iEscapedencodedRk = $oEncodedRk.Replace("'","''")
$bSuccess = $oEncodedRk.Encode("url_rfc3986","utf-8")
If ($bSuccess <> True) Then
    ConsoleWrite("Could not prepare the request." & @CRLF)
    Exit
EndIf

;  Escape apostrophes for OData first, then percent-encode each key once.
$oEntityPath = ObjCreate("Chilkat.StringBuilder")
$bSuccess = $oEntityPath.Append("/ExampleCustomers(PartitionKey='")
If ($bSuccess <> True) Then
    ConsoleWrite("Could not prepare the request." & @CRLF)
    Exit
EndIf

$bSuccess = $oEntityPath.Append($oEncodedPk.GetAsString())
If ($bSuccess <> True) Then
    ConsoleWrite("Could not prepare the request." & @CRLF)
    Exit
EndIf

$bSuccess = $oEntityPath.Append("',RowKey='")
If ($bSuccess <> True) Then
    ConsoleWrite("Could not prepare the request." & @CRLF)
    Exit
EndIf

$bSuccess = $oEntityPath.Append($oEncodedRk.GetAsString())
If ($bSuccess <> True) Then
    ConsoleWrite("Could not prepare the request." & @CRLF)
    Exit
EndIf

$bSuccess = $oEntityPath.Append("')")
If ($bSuccess <> True) Then
    ConsoleWrite("Could not prepare the request." & @CRLF)
    Exit
EndIf

$sResourcePath = $oEntityPath.GetAsString()
$bSuccess = $oNow.SetFromCurrentSystemTime()
If ($bSuccess <> True) Then
    ConsoleWrite("Could not prepare the request." & @CRLF)
    Exit
EndIf

If ($oExpires.DiffSeconds($oNow) <= 60) Then
    ConsoleWrite("Reacquire a token before the Table request." & @CRLF)
    Exit
EndIf

$sResponseText = $oRest.FullRequestNoBody("GET",$sResourcePath)
If ($oRest.LastMethodSuccess <> True) Then
    ConsoleWrite("Request did not complete; inspect the target before retrying a write." & @CRLF)
    Exit
EndIf

If ($oRest.ResponseStatusCode <> 200) Then
    ConsoleWrite("HTTP status: " & $oRest.ResponseStatusCode & @CRLF)
    ConsoleWrite("Request ID: " & $oRest.ResponseHdrByName("x-ms-request-id") & @CRLF)
    ;  404 is missing, 409 is conflict, and 412 is a stale ETag: none are success.
    ;  Keep response bodies private. Reconcile uncertain writes before retrying.
    Exit
EndIf

$bSuccess = $oResult.Load($sResponseText)
If ($bSuccess <> True) Then
    ConsoleWrite("Expected well-formed JSON." & @CRLF)
    Exit
EndIf

$oTextCompare.Clear 
$oTextCompare.SetString($oResult.StringOf("PartitionKey"))
Local $bSameText7 = $oTextCompare.ContentsEqual("",True)
If (($oResult.JsonTypeOf("PartitionKey") <> 1) Or ($bSameText7 = True)) Then
    ConsoleWrite("Missing string PartitionKey." & @CRLF)
    Exit
EndIf

$oTextCompare.Clear 
$oTextCompare.SetString($oResult.StringOf("RowKey"))
Local $bSameText8 = $oTextCompare.ContentsEqual("",True)
If (($oResult.JsonTypeOf("RowKey") <> 1) Or ($bSameText8 = True)) Then
    ConsoleWrite("Missing string RowKey." & @CRLF)
    Exit
EndIf

$oTextCompare.Clear 
$oTextCompare.SetString($oResult.StringOf("PartitionKey"))
Local $bSameText9 = $oTextCompare.ContentsEqual($sPartitionKey,True)
$oTextCompare.Clear 
$oTextCompare.SetString($oResult.StringOf("RowKey"))
Local $bSameText10 = $oTextCompare.ContentsEqual($sRowKey,True)
If (($bSameText9 <> True) Or ($bSameText10 <> True)) Then
    ConsoleWrite("Returned entity keys do not match." & @CRLF)
    Exit
EndIf

ConsoleWrite("Storage token obtained and Table entity retrieved." & @CRLF)