Sourav Karmakar
Sourav Karmakar

Reputation: 95

Can I list all items of an Azure table(Azure Table Storage) just by PartitionKey?

I tried to use the below uri for REST call, but getting error(403 Forbidden)

https://$storageAccount.table.core.windows.net/$tableName()?$filter=PartitionKey%20eq%20'Key1'

Is there other way? Please help.

Upvotes: 0

Views: 69

Answers (1)

Jim Xu
Jim Xu

Reputation: 23111

According to my test, we can use share key to call the Azure table rest api


$accesskey="<storage account key>"
    $storageAccount = "<account name>"
    $version = "2017-04-17"
    $resource = "table name"
    $key="Jim"
   
    $table_url = "https://$storageAccount.table.core.windows.net/$($resource)?`$filter=PartitionKey%20eq%20'$($key)'"
    # create share key
    $GMTTime = (Get-Date).ToUniversalTime().AddYears(1).toString('R')
    $stringToSign = "$GMTTime`n/$storageAccount/$resource"
    $hmacsha = New-Object System.Security.Cryptography.HMACSHA256
    $hmacsha.key = [Convert]::FromBase64String($accesskey)
    $signature = $hmacsha.ComputeHash([Text.Encoding]::UTF8.GetBytes($stringToSign))
    $signature = [Convert]::ToBase64String($signature)
    $headers = @{
        'x-ms-date'    = $GMTTime
        "Authorization"  = "SharedKeyLite " + $storageAccount + ":" + $signature
        "x-ms-version" = $version
        "Accept"         = "application/json"
    }
    $item = Invoke-RestMethod -Method GET -Uri $table_url -Headers $headers -ContentType application/json
    $item.value

enter image description here

Update

Regarding how to create sas token via Azure Portal, please refer to the following steps

  1. Create sas token enter image description here

  2. Test

 GET https://myaccount.table.core.windows.net/mytable()
?$filter=<>
&sv=2019-02-02&ss=t&srt=o&sp=r&se=2020-03-27T13:01:24Z&st=2020-03-27T05:01:24Z&spr=https&sig=OFUNXShu6kTojIp3SU...TkG%2BXAVZXJ8sqc%3D

Upvotes: 1

Related Questions