Jump to content

Performing simple Azure Table Storage REST API operations using curl command.


Recommended Posts

Guest ShraddhaSwadi
Posted

The blog provides guidance to perform simple Table Storage REST API operations such as Create table, Delete Table, Insert entity, Delete entity, Merge entity, Get Table properties, Get Table Storage Stats, Query Table, Query Entities and Update entities operations using curl command.

 

 

 

Let us look at some of the command syntax to perform REST API operations and we will be making use of SAS token as the authentication mechanism. We need to take care of the pointers below while performing the operations via curl command:

 

  • Ensure the URL is formed correctly as per the operation you are trying to perform.
  • The mandatory header needs to be passed along with correct values for it.
  • Ensure you are appending/removing extra ‘?’ to the SAS token in the URLs accordingly.
  • Http verb can be GET, PUT or DELETE as provided by the REST API specifications.

 

So let's began:

 

 

  1. Get Table Storage Properties:

 

This Rest API gets the properties of an Azure Table Storage account. Reference link for Rest API is:

 

Get Table Service Properties (REST API) - Azure Storage | Microsoft Learn

 

Syntax URL:

 

 

 

[iCODE]curl -X GET "https://<storageacccountname>.table.core.windows.net/?restype=service&comp=properties<SAS_token>" -H "x-ms-date:2024-02-23T03:24Z" -H "x-ms-version:2020-04-08"[/iCODE]

 

 

 

 

Output:

 

[ATTACH type=full" alt="ShraddhaSwadi_0-1724391575801.png]63668[/ATTACH]

 

 

 

  1. Get Table Storage Stats:

 

This Rest API retrieves statistics that are related to replication for Azure Table Storage. This operation works only on the secondary location endpoint when we have RAGRS replication enabled for the storage account. Reference link: Get Table Service Stats (REST API) - Azure Storage | Microsoft Learn

 

Syntax URL:

 

 

 

[iCODE]curl -X GET "https://storageaccount-secondary.table.core.windows.net/?restype=service&comp=stats&<SAS_token>” -H "x-ms-date:2024-02-23T03:24Z" -H "x-ms-version:2020-04-08"[/iCODE]

 

 

 

 

 

Output:

 

[ATTACH type=full" alt="ShraddhaSwadi_1-1724391575806.png]63669[/ATTACH]

 

 

 

  1. Query tables:
    This Rest API returns a list of tables under the specified account. Reference link: Query Tables (REST API) - Azure Storage | Microsoft Learn

 

Syntax URL:

 

 

 

[iCODE]curl -X GET "https://storageaccount.table.core.windows.net/Tables?<SAS_token>" -H "x-ms-date:2024-02-23T18:16:35Z" -H "x-ms-version:2020-04-08"[/iCODE]

 

 

 

 

 

Output:

 

[ATTACH type=full" alt="ShraddhaSwadi_2-1724391575829.png]63670[/ATTACH]

 

  1. Create table:

 

This Rest API creates a new table in a storage account. Reference link: Create Table (REST API) - Azure Storage | Microsoft Learn

 

 

Syntax URL:

 

 

 

[iCODE]curl -X POST "https://storageaccount.table.core.windows.net/Tables?<SAS_token> " -H "x-ms-date:2024-02-23T18:16:35Z" -H "x-ms-version:2020-04-08" -H "Content-Length: 27" -H "Content-Type: application/json" -d "{\"TableName\":\"sampletable\"}[/iCODE]

 

 

 

 

Output:

 

[ATTACH type=full" alt="ShraddhaSwadi_3-1724391575842.png]63671[/ATTACH]

 

 

 

[ATTACH type=full" alt="ShraddhaSwadi_4-1724391575847.png]63672[/ATTACH]

 

 

 

 

 

  1. Delete table:
    This Rest API deletes a table in a storage account. Reference link: Delete Table (REST API) - Azure Storage | Microsoft Learn
     

 

Syntax URL:

 

 

 

[iCODE]curl -X DELETE "https://storageaccount.table.core.windows.net/Tables('sampletable')?<SAS_token> " -H "x-ms-date:2024-02-23T18:16:35Z" -H "x-ms-version:2020-04-08" -H "Content-Type: application/json"[/iCODE]

 

 

 

 

Output:

 

[ATTACH type=full" alt="ShraddhaSwadi_5-1724391575849.png]63673[/ATTACH]

 

 

 

[ATTACH type=full" alt="ShraddhaSwadi_6-1724391575853.png]63674[/ATTACH]

 

 

 

  1. Query Entities:
    This Rest API queries entities in a table and includes the $filter and $select options. Reference link: Query Entities (REST API) - Azure Storage | Microsoft Learn

 

Syntax URL:

 

 

 

[iCODE]curl -X GET "https://storageaccount.table.core.windows.net/shswadsampletable1(PartitionKey='B',RowKey='1')?<SAS_token> " -H "x-ms-date:2024-02-24T10:14:50.2646880Z" -H "x-ms-version:2020-04-08"[/iCODE]

 

 

 

 

Output:

 

[ATTACH type=full" alt="ShraddhaSwadi_7-1724391575858.png]63675[/ATTACH]

 

 

 

[ATTACH type=full" alt="ShraddhaSwadi_8-1724391575863.png]63676[/ATTACH]

 

 

 

  1. Delete Entity Operation:
    This Rest API deletes an existing entity in a table. Reference link: Delete Entity (REST API) - Azure Storage | Microsoft Learn
     

 

Syntax URL:

 

 

 

[iCODE]curl -X DELETE "https://storageaccount.table.core.windows.net/shswadsampletable1(PartitionKey%3D'B'%2C%20RowKey%3D'1')?<SAS_token> " -H "x-ms-date:2024-02-24T11:14:50.2646880Z" -H "x-ms-version:2020-04-08" -H "If-Match:*"[/iCODE]

 

 

 

 

Output:

 

[ATTACH type=full" alt="ShraddhaSwadi_9-1724391575864.png]63677[/ATTACH]

 

 

 

[ATTACH type=full" alt="ShraddhaSwadi_10-1724391575868.png]63678[/ATTACH]

 

 

 

  1. Insert Operation:

 

This Rest API inserts a new entity into a table. Reference link: Insert Entity (REST API) - Azure Storage | Microsoft Learn

 

 

Syntax URL:

 

 

 

[iCODE]curl -X POST "https://storageaccount.table.core.windows.net/test?<SAS_token> " -H "x-ms-date: 2024-02-25T10:39:50.2646880Z" -H "x-ms-version: 2020-04-08" -H "Accept: application/json;odata=nometadata" -H "Content-Type: application/json" -d "{\"RowKey\":\"bbb\",\"PartitionKey\":\"ssss\",\"Name\":\"aaa\",\"PhoneNumber\":\"111\"}"[/iCODE]

 

 

 

 

Output:

 

[ATTACH type=full" alt="ShraddhaSwadi_11-1724391575871.png]63679[/ATTACH]

 

 

 

[ATTACH type=full" alt="ShraddhaSwadi_12-1724391575875.png]63680[/ATTACH]

 

 

 

  1. Update operation:

 

This Rest API updates the existing entity in the Table Storage. Reference link: Update Entity (REST API) - Azure Storage | Microsoft Learn

 

 

 

Syntax URL:

 

 

 

[iCODE]curl -X PUT "https://storageaccount.table.core.windows.net/test(PartitionKey%3D'ss'%2C%20RowKey%3D'bbb')?<SAS_token> " -H "x-ms-date: 2024-02-25T10:39:50.2646880Z" -H "x-ms-version: 2020-04-08" -H "Accept: application/json;odata=nometadata" -H "Content-Type: application/json" -H "If-Match=*" -d "{\"RowKey\":\"bbb\",\"PartitionKey\":\"ssss\",\"Name\":\"aaa\",\"PhoneNumber\":\"111\"}[/iCODE]

 

 

 

 

Output

 

[ATTACH type=full" alt="ShraddhaSwadi_13-1724391575877.png]63681[/ATTACH]

 

 

 

[ATTACH type=full" alt="ShraddhaSwadi_14-1724391575884.png]63682[/ATTACH]

 

 

 

Merge operation:

This Rest API operation updates an existing entity by updating the entity's properties and does not replace the existing entity, Reference link: Merge Entity (REST API) - Azure Storage | Microsoft Learn

 

 

 

Syntax URL:

 

 

 

[iCODE]curl -X PUT "https://storageaccount.table.core.windows.net/test(PartitionKey%3D'ssss'%2C%20RowKey%3D'bbb')?<SAS_token> " -H "x-ms-version: 2020-04-08" -H "Accept: application/json;odata=nometadata" -H "Content-Type: application/json" -H "If-Match=*" -d "{\"RowKey\":\"bbb\",\"PartitionKey\":\"ssss\",\"Name\":\"aaa\",\"PhoneNumber\":\"11231\"}"[/iCODE]

 

 

 

 

Output:

 

[ATTACH type=full" alt="ShraddhaSwadi_15-1724391575886.png]63683[/ATTACH]

 

 

 

[ATTACH type=full" alt="ShraddhaSwadi_16-1724391575890.png]63684[/ATTACH]

 

 

 

Hope this article helps you in performing the Table Storage operations by making use of curl command.

 

 

 

Happy Learning!

 

Continue reading...

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...