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 (Cloud Version)? 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).
Does anyone any other solutions to automatically read a file and import the data into a BC journal with no user interaction?
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 := '<SharedKey>';
dateInRfc1123Format := GetUTCDateTimeText();
requestMethod := 'GET';
fileName := 'abc.xlsm';
urlPath := '<myshare>/<mydirectorypath>/<myfile>';
CanonicalizedResource := StrSubstNo('/%1/%2', '<myaccount>', '<myshare>/<mydirectorypath>/<myfile>');
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 <myaccount>:' + EncryptionManagement.GenerateBase64KeyedHashAsBase64String(stringToSign, SharedKey, 2);
uri := 'https://<myaccount>.file.core.windows.net/<myshare>/<mydirectorypath>/<myfile>';
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;