Create a simple API with Flow to interact with CDS!

Home / Power Platform / Power Automate / Create a simple API with Flow to interact with CDS!
HTTP REQUEST TO CDS

In this article, we will highlight one of the Flow connectors that can be useful to solve “simple” external connection problems.

Whenever an information system is implemented, the question of interfaces arises. How many flows to create/maintain, what types of external systems must interact with the new application etc…

Although many solutions exist (ETL, ESB…) to answer these problems, I have not yet seen any interfaces made using Flow.

This solution does not allow to substitute the implementation of interfaces but may be sufficient if you just want to make a call from outside CDS.

Flow creation

In this scenario, we will have a CDS to store information from an external call that can be made from a client application, for example.

We start by creating a flow from a solution, it is always recommended creating to create a flow like this.

Creating Flow

You can now enter a name for this flow, for example: “FLOW – Create an Account from HTTP Request”

Naming the flow

Finally, we will select the trigger “When a HTTP request is received”.

Select HTTP trigger

As you can see, it says: ‘URL will be generated after save’. We will therefore focus on the method of this trigger and especially the definition of the JSON schema that will be received by the endpoint.


We will use this flow to create an account by giving the account name, phone number and website url.


This gives us the following schema:

JSON Schema

We will also indicate that it’s a POST request method.

Schema and method for the HTTP POST query

Now, we will add a new condition step:

Adding Condition Step

The objective is to check the data received, such as the length of a field, etc… To ensure that the information is as accurate as possible. This is only one example, it would obviously be necessary to add much more consistent conditions. For example, we could retrieve the header to check from which User Agent this request was issued.

Checking the field length

Finally, we will use the CDS connector to create an account record using information received.

Map fields to Account entity

We can finally save our flow and observe that the service url has been generated:

URL generated

Now we just need to make a POST request to this url to create an account!
To do this, we will use Postman. Make sure to add the following header:

Content-Type: application/json

And the URL of course 🙂
Now we will build the JSON body which will contain the information we want to send in order to create an account:

PostMan Request

Press Send and wait for the execution status to return.

Status of the request for success

You can check in CRM to see if the record has been created:

Account Created by Flow

Now if we want to make a request from an external application for example via a submit button we can use the code generated by Postman:

JavaScript code generated by PostMan

However, this solution is not the best in terms of security. There is no authentication to make this POST request, so if someone gets this URL, they can easily flood it and therefore consume “runs” but it could eventually generate bad data in your case!

 

Leave a Reply

Your email address will not be published.