In my previous blog post I explained how to use Power Automate (previously known as Microsoft Flow) and set up an automated flow which triggers when an Account is created or a certain field is updated and then makes an HTTP request using OAuth 2.0 as authentication method and includes some data from the Account in the request. I also mentioned that you might want to do something with the response from the request, e.g. let the users know how it went. In this blog post I will let you in on an example of just that.
Here is a summary of the parts that were not included in the flow in my previous blog post, i.e. the parts that gets information from the HTTP response and then updates the record which triggered the flow.
Get hold of the information
Now I will let you in on how to get hold of information from the response. Let us assume that we have created an automated flow which triggers on an update in the CDS and makes an HTTP request. If you want to know how this is done, go to my previous blog post. Now let us say we want to give the users a chance to see some information that we got back from the request. Then the first step in our automated flow, after the HTTP request, would be to get hold of the information that we want to use. We will now look at how you can do that and then write it back to the record which triggered the flow.
We can run our flow and then take a look at the run flow. Expand the HTTP request action and you will see information under Inputs and Outputs. Here we are interested in the Outputs and its format. You will see the status, headers and body. If the body has a quite simple format you could go with the approach that I am about to explain. If the format e.g. is a more complex JSON, then you might want to consider using the Parse JSON action instead.
To give you some background – Power Automate uses the Logic Apps Workflow Definition Language, which means there are some useful functions we can use in our flows and there is certain syntaxes which follows with this concept. We can use the expression pane like in the picture below. If you know the expression you want to use you can type it directly were it says Inputs in the Compose action below as well.
Let us move on the exact examples. Let us say have a response body containing just a user-friendly message associated with a certain response status. Let us say we want to get hold on the status, the user-friendly message and the date located in the response header. I will go through each one of these examples. Then we will look at how to write that information back to the record which triggered the flow.
For each and one of these we will use a Compose action. Let us start with the header. Let us say as an example that we want to extract the Date from there and the Date is located as in the below picture.
In order to get hold on information located in the header, you can use a Compose action and type in the following:
Replace HTTP_Notify_About_New_or_Updated_Customer with what you have called your HTTP request, spaces replaced by underscores.
The ? comes from the syntax that I mentioned. It says in the documentation that “To reference null properties in an object without a runtime error, use the question mark operator.” In some cases you might need this if some values can be null then the flow would crash without the question marks.
Next, let us take a look at how to get hold on the information from the body. As already mentioned, this is a very simple example, let us assume that the body only contains a user-friendly message associated with the status code. For example, the message associated with the response code 200 might be:
If there would have been a more complex JSON in our body, then me might have wanted to use the Parse JSON action, which already mentioned. In this case we can get the message by adding a new Compose action and type in:
Now let us look at how to get the status code. Again, we use the same approach, we add a new Compose action. The status code can be extracted very easily as you will see, just use Dynamic content and choose Status code. You can see that we have Body and Headers there as well. However it is the entire body and all the headers. That is why we needed to some work with those in order to get the exact data that we wanted, which I have already gone through.
Update the record in the CDS
Now we have three Compose actions containing different information that we want to add to the record that triggered the flow. In order to update this record, add a new step to the flow and choose Common Data Service (Current Environment), choose Update a record. In my previous blog post I created a variable for the guid of the record which triggered the flow. We will use that here. Please note that we might as well have chosen “Account” under Dynamic content in order to get the unique identifier for this record.
Then we expand what is called Advanced settings and we find the fields that we want to update. In this example, let us assume that we have created three new fields “Data Synchronized”, “Integration Status Code” and “Integration Message”. Then it would look like below under Advanced settings (and there would also be a lot of other fields which we leave empty of course).
One downside with the Compose action is that once added to an action in our flow, you have to hoover over it in order to see which Compose action it comes from. I mentioned this in my previous blog post and I will mention it again. I have added an idea that we should be able to name Compose actions just as we can with variables. Please vote for it here.
Please note it might as well have been the case that we made an API call which got us some information about the record that we want to update on the Account. Then we could have used the same approach. Please also think about that you might not want to add related information for all your status codes, just the user-friendly once, so you might need to add a step for verifying the status code or at least think through the entire solution (e.g. what status codes can there be from the API and what related messages) before you start to use something like this.
Now you have the information needed in order to get hands on with HTTP requests with Power Automate and automated flows and you also have an example of what to do with the information you got back from the request.
Happy flow’ing with Power Automate!