Calling a D365FO Web Service from a Flow

 Here is a guide on how to call a custom Web Service in D365FO from a Flow. To call a Web Service you need to gain access by retrieving an access token and pass that token in the header of your call.

If you do not have a web service or you want to follow this example, you can download this file and import into your development environment, also you can view this post to see how a web service is made.

Create your flow

Begin by creating your Flow by selecting a template, since I make this flow in relation to my PowerApp post, I will choose the Power Apps button template. 



Basic Flow steps

These are the basic steps that you need to call a web service, you can of course do it a whole set of different ways, like use Azure Keyvault or passing parameters instead of hard coding [like I've done here].

Quick explanation:

*Variable, I just hardcoded this, you might choose different approach.

  1. Called by a power app. 

  2. initialize variables:
    1. TenantID*
    2. ClientID*
    3. Web service URL*
    4. ProductID, (input parameter from PowerApp), choose the Ask in PowerApps to create input parameter.


    5. Scope*
    6. Secret*. 

  3. Retrieve access token


  4. Compose the result (fetch the token variable from JSON)


  5. Initialize variable AccessToken, setting the value to the token 
  6. POST run web service. My web service needs JSON, the parameter name is "_data" (underscore included) and the exact parameter  name is needed when passing it in the body.

    PS! a common mistake here is to not include a whitespace in the Authorization parameter value, there must be a whitespace between the text Bearer and the access token variable.

  7. Compose response

  8. Initialize variable Response

  9. Respond to PowerApp, here you add the return parameters you'd like. You can have several, which is a very nice feature.


When finished setting up your flow test it by pressing the test button in the top rightmost corner. You will be presented with input boxes for your input parameters.



Comments

Popular posts from this blog

Call a simple Logic app from X++

SysOperationFramework with use of Query

Retail Attributes on sales lines