Is it possible to connect to Azure File Share through AL code and import data from a file on the file share into a journal in BC? I have tried to use the Rest APIs with no luck (https://docs.microsoft.com/en-us/rest/api/storageservices/file-service-rest-api). The particular issue I keep running into is authorization. I'm doing authorization with a Shared Key and following the authorization guidelines based on MS documentation (https://docs.microsoft.com/en-us/rest/api/storageservices/authorize-with-shared-key).
Code Sample:
trigger OnRun()
var
requestMethod: Text;
request: HttpRequestMessage;
RequestHeader: HttpHeaders;
hhtpres: HttpResponseMessage;
canonicalizedResource: Text;
canonicalizedHeaders: Text;
urlPath: Text;
client: HttpClient;
content: HttpContent;
authorizationHeader: Text;
stringToSign: Text;
msVersion: Text;
cha: Char;
contenttype: Text;
contentLength: Integer;
SharedKey: Text;
dateInRfc1123Format: Text;
EncryptionManagement: Codeunit "Cryptography Management";
uri: Text;
fileName: Text;
begin
cha := 10;
msVersion := '2019-12-12';
SharedKey := '';
dateInRfc1123Format := GetUTCDateTimeText();
requestMethod := 'GET';
fileName := 'abc.xlsm';
urlPath := '//';
CanonicalizedResource := StrSubstNo('/%1/%2', '', '//');
canonicalizedHeaders := 'x-ms-date:' dateInRfc1123Format Format(cha)
'x-ms-version:' msVersion;
stringToSign := (requestMethod Format(cha)
Format(cha)
Format(cha)
Format(cha)
Format(cha)
Format(cha)
Format(cha)
Format(cha)
Format(cha)
Format(cha)
Format(cha)
Format(cha)
canonicalizedHeaders Format(cha)
canonicalizedResource);
authorizationHeader := 'SharedKey :' EncryptionManagement.GenerateBase64KeyedHashAsBase64String(stringToSign, SharedKey, 2);
uri := 'https://.file.core.windows.net///';
request.SetRequestUri(uri);
request.Method := requestMethod;
RequestHeader.Clear();
request.GetHeaders(RequestHeader);
RequestHeader.Add('Authorization', authorizationHeader);
RequestHeader.Add('x-ms-date', dateInRfc1123Format);
RequestHeader.Add('x-ms-version', msVersion);
client.Send(request, hhtpres);
if not hhtpres.IsSuccessStatusCode then
Error(FORMAT(hhtpres.HttpStatusCode) ': ' hhtpres.ReasonPhrase)
else
Message(FORMAT(hhtpres.HttpStatusCode) ': ' hhtpres.ReasonPhrase);
end;