How to query the Azure table storage entities with filters using REST API via Apex salesforce
Actually I'm trying to get the Azure table storage entities using query syntax that is..
- If we use with bellow query, we can get all table data(Entities)--->
String endpoint = 'https://' + storageAccountName + '.[table.core.windows.net/]' + tableName; 2.With this query I can't get the data if we add a filter conditions?
String endpoint1 = 'https://bigworks.table.core.windows.net/newtable()?$filter=PartitionKey%20eq%20'BIGWORKS'%20and%20RowKey%20eq%20'ROWBIGWORKS''
;
when I add a filter in the query, I'm getting this error...
Server failed to authenticate the request. Make sure the value of Authorization header is formed correctly including the signature for azure table storage
Can you help me on this issue,
Thanks in advance.
This is the entire code I'm using.... I'm using Apex language.
// Specify the Azure storage account details
String storageAccountName = 'bigworks';
String storageAccountKey = 'AvQaa3SyhLC5v8tXrTXTZNbVvdXalEOVmS71RUrqVR/GgfsRxdLm+Azq6AeYaaPwqqlQBCDvzT+AStLnN7uQ==';
String tableName = 'newtable';
String endpoint = 'https://' + storageAccountName + '.table.core.windows.net/' + tableName;
String oldString = 'BIGWORKS';
String newString = '\''+ oldString + '\'';
Double BIGWORKS = 25;
String ROWBIGWORKS = 'ROWBIGWORKS';
String endpoint1 = 'https://bigworks.table.core.windows.net/newtable()?%24$filter=PartitionKey%20eq%20'+newString;
system.debug('endpoint URL '+endpoint);
system.debug('endpoint URL 1 '+endpoint1);
// Sign the request with the storage account key
String sasToken = '';
String dateInRfc1123Format = Datetime.now().formatGMT('EEE, dd MMM yyyy HH:mm:ss z');
system.debug('dateInRfc1123Format '+dateInRfc1123Format);
String canonicalizedResource = '/' + storageAccountName + '/' + tableName;
String canonicalizedHeaders = 'x-ms-date:' + dateInRfc1123Format;
system.debug('canonicalizedResource '+canonicalizedResource);
//String stringToSign = 'GET' + '\n' +''+ '\n' +'application/json;odata=nometadata'+ '\n' + dateInRfc1123Format + '\n' + canonicalizedResource;
String stringToSign = dateInRfc1123Format + '\n' + canonicalizedResource;
system.debug('stringToSign stringToSign '+stringToSign);
Blob signature = Crypto.generateMac('HMACSHA256', Blob.valueOf(stringToSign), EncodingUtil.base64Decode(storageAccountKey));
sasToken = EncodingUtil.base64Encode(signature);
String authorizationHeader = 'SharedKeyLite ' + storageAccountName + ':' + sasToken;
system.debug('authorizationHeader '+authorizationHeader);
// Create a HTTP request to send the object record to Azure table
HttpRequest req = new HttpRequest();
req.setEndpoint(endpoint1);
req.setMethod('GET');
req.setHeader('Content-Type', 'application/json;odata=nometadata');
req.setHeader('Accept', 'application/json;odata=nometadata');
req.setHeader('Authorization', authorizationHeader);
req.setHeader('x-ms-date', dateInRfc1123Format);
req.setHeader('x-ms-version', '2022-11-02');
req.setHeader('Accept-Charset', 'UTF-8 ');
req.setHeader('MaxDataServiceVersion', '3.0;NetFx ');
req.setHeader('DataServiceVersion', ' 3.0;NetFx ');
system.debug('req Azur '+req);
// Send the request and get the response
Http http = new Http();
HttpResponse res = http.send(req);
system.debug(res.getStatusCode());
System.debug('RESSSS '+res.getBody());
// Process the response
System.debug('Response status ----->>> ' + res.getStatusCode());
System.debug('Response Status----->>> ' + res.getStatus());
System.debug('Response Body------->>> ' + res.getBody());
// Parse the response body to get the data
List