0

I am trying to insert values into Azure Table PartitionKey Column. These values is of type String and have spaces between them. Example

$p = "VMWARE-42 3B"
        $r = "VMWARE"
        $entity = @{
            "[email protected]" = "Edm.String";
           "PartitionKey"         = $p;
            "[email protected]" = "Edm.String";
            "RowKey"                = $r;           
 }
        Set-TableEntity -TableName $tableName -StorageAccountName $storageAccountName -StorageAccessKey $storageAccessKey -Entity $entity  -Verbose 

I am getting the below error:

Set-TableEntity - Attempt #0 VERBOSE: PUT https://table_url/tableName(PartitionKey='VMWARE-42 3B',RowKey='VMWARE') with -1-byte payload Error: Failed to update device entry Exception occurred: System.Net.WebException: The remote server returned an error: (403) Forbidden. at Microsoft.PowerShell.Commands.WebRequestPSCmdlet.GetResponse(WebRequest request) at Microsoft.PowerShell.Commands.WebRequestPSCmdlet.ProcessRecord()

Please any idea on how to solve this? Please note that when the values are inputed manually, there is no error. Does Azure Table accept spaces in String values? Please Note also that: without the space in the string value everything works as expected. the required table is updated.

7
  • You don't show us how you do the actual call... Because of the spaces, do you quote those string values? Commented Mar 18, 2022 at 11:24
  • @Theo, thank you. The string is in quote. Commented Mar 18, 2022 at 11:30
  • Then please show us the code you use to insert those values. Not in a comment, but as formatted text in your question. Just click the edit link underneath. Since the server returns Forbidden, are you using the correct credentials to that call? Commented Mar 18, 2022 at 11:32
  • yes, I am using the right credential. Without the space in the string value everything works fine. @Theo, I have updated my question. Thank you. Commented Mar 18, 2022 at 11:58
  • Can you 'escape' the space character? for example, replace all spaces with %20 or x0020 using p = p.replace(/ /g, 'x0020'). Commented Apr 15, 2022 at 14:29

1 Answer 1

0

You need to convert your partitionKey and rowKey part in the URL to escaped representation.

$Resource = "$TableName(ParitionKey='$PartitionKey',RowKey='$RowKey')"
$Resource = [URI]::EscapeUriString($Resource)
$TableUrl = "https://tableUrl/$($Resource)

You must use the same $Resource variable in making a hash signature.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.