Connecting to Azure File Share (Not Blob Storage) through AL Code

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;

Hi,

I have no clue abut this, never tried to use a shared key and much less azure. Howver, I used REST WS in AL.

Maybe the best thing you could start with is try to reproduce it in postman tool. Also, report what error are you getting, if someone can help.

Br,

There is another way you could explore, have a look into Power Automate. It has built in connectors for both Azure File Storage and Business Central.

Do you have a link to the Connector or its name? I was not able to find it under the Business Central Connector.

hi… do you have any luck to do this thing?

https://docs.microsoft.com/en-us/connectors/azurefile/ and https://docs.microsoft.com/en-us/connectors/dynamicssmbsaas/

I know you wrote it’s for Azure File Share, but did you check out this repo on Github: https://github.com/cosmoconsult/D365BC-Blob-Storage-API

In the codeunits folder you find two codeunits for handling authentication tokens. I have not tried it myself, but I would be surprised if the same authentication could not be used with File Share also.