Search This Blog

Showing posts with label Azure. Show all posts
Showing posts with label Azure. Show all posts

Friday, August 5, 2022

How to connect Postman with Dynamics 365 Finance and Operation

Connect postman with Dynamics 365 finance and operation


Azure application registration

First we need to register application on the azure portal Go to portal.azure.com and click on the respective subscription. in the Search bar type application registration and click on new application registration




















Specify the below detail as per your requirement 












































Please make a copy of the client id and Tenant id because we will use it further. Click on the Add a certificate or secret 

















Please make a copy of the client secret id and secret value. you will not be able to see the client secret value after closing the dialog. 

Add user in F&O

In the finance and Operation , Navigate to the System administration --> Setup --> Azure active directory application and create the record as per below. Client id should be used over here. 




















Setting in Postman 

First we need to get the token and after we will be using this token to do operation with F&O.

To do the setup in the postman, we need the below values 

   
Key Value
client_id     Application id copied from Azure portal
grant_type     client_credentials
Scope     F&OHomepageURL/.default
client_secret     secret id copied from azure portal
Resource         F&O Home page URL

As per below 






















You will receive the access_token by running above script and you can copy that token or can use environment variable in the postman to store the access_token
as per below 




























TTo test that everything is working fine or not. you can use the token generated above and can get the few customer record as per below



Friday, July 1, 2022

How to download file from Azure Blob using x++ in D365 FO

Create the storage account on the azure as per below and copy the keys to connect to this storage account. 


Create a container inside this storage account named with dynamicsfocontainer. We can upload the files from our local directory. To download the files from blob container we can use the below code in the x++. Below is the runnable class that I have developed. 

You can use the exception as per your requirement and loop as well. 


using Microsoft.WindowsAzure.Storage;

using Microsoft.WindowsAzure.Storage.Blob;

 

internal final class CreateReadWriteBlobStorage

{

    /// <summary>

    /// Class entry point. The system will call this method when a designated menu

    /// is selected or when execution starts and this class is set as the startup class.

    /// </summary>

    /// <param name = "_args">The specified arguments.</param>

    public static void main(Args _args)

    {

        CloudStorageAccount  storageAccount;

        CloudBlobContainer   blobContainer;

        CloudBlobClient      blobClient;

 

        storageAccount = CloudStorageAccount::Parse("DefaultEndpointsProtocol=https;AccountName=dynamicsfinanceoperation;AccountKey=I1IFZ7bdzX61466bAxbNChJVN3PbtUgPfNH5WbXbnc8sTIXS/ffZmN0EDo+zbS+AStn3n0Pw==;EndpointSuffix=core.windows.net");

        blobClient = storageAccount.CreateCloudBlobClient();

       

        blobContainer = blobClient.GetContainerReference("dynamicsfocontainer");

 

        System.Collections.IEnumerable listEnumerable =  blobContainer.ListBlobs(null,true,0,null,null);

        System.Collections.IEnumerator listEnumerator = listEnumerable.GetEnumerator();

       

        while (listEnumerator.MoveNext())

        {

            IListBlobItem item = listEnumerator.Current;

 

            if (item is CloudBlockBlob)

            {

                CloudBlockBlob  blockBlob = item;

                System.IO.FileStream  localFile = System.IO.File::Create(@"C:\Temp\Blob\" + blockBlob.Name);

                blockBlob.DownloadToStreamAsync(localFile);

                Info(strFmt("%1",blockBlob.Name));

            }          

        }

    }

}