Execute using Power Apps

◷ Reading Time: 11 minutes

Custom connectors can be created in Power Apps which allow you to authenticate and then execute services hosted in FlexRule Server.

This guide shows you steps specific to Power Apps. Because custom connectors can use REST API calls, the methods outlined here are similar to the guides to Authenticate your Command and Execute using REST API.

Authenticate using a Custom Connector

Navigate to Data > Custom Connectors.

Click on New custom connector > Create from blank.

Give your custom connector a name and click Continue.

General Information Section

Set the Scheme to HTTP.

Set the Host to your FlexRule Server Master API address.

Click on Security to go to the next section.

Click on Definition to go to the next section.

Definition Section

Click on New action.

In the General panel, give your action an Operation ID.
Leave the Visibility as none.
The Summary and Description fields are optional.

In the Request section, click on Import from sample.

Choose POST as the Verb.

Enter the URL to your Master API followed by /oauth2/token .

In the Headers field enter Content-Type application/x-www-form-urlencoded .

In the Body field enter two double quotes.

Click on Import to close the import options. Your request should be added.

In the Request > Body section, click the menu button and click on Edit.

Mark Is required? as Yes. Click on Back.

Click on Create Connector.

Once the connector has been saved, click on Test.

Test Section

In the Connections panel, click on New connection.

Click on Create.

Navigate to Data > Custom Connectors and click to open the custom connector you created. Then click on Edit.

Click on Test.

In the Connections panel, ensure you have a selected connection.

In the Content-Type field enter application/x-www-form-urlencoded .

In the body field enter client_id=[username]&client_secret=[password]&grant_type=password
where [username] is the username for the account you are using and [password] is the password for the account (don’t add the square brackets).

Click on Test operation once you have completed the fields.

If authentication was successful your response should have Status 200 and the Body should have your access token.

Now you can use the authentication token to authenticate service execution.

Access tokens expire so you will need to ensure your flow obtains a new access token if it has expired.
The default expiration time is 30 minutes.

Execute Service with a Custom Connector

Navigate to Data > Custom Connectors.

Click on New custom connector > Create from blank.

Give your custom connector a name and click Continue.

General Information Section

Set the Scheme to HTTP.

Set the Host to your FlexRule Server Master API address.

Click on Security to go to the next section.

Security Section

In the Authentication type field, choose API Key.

In Parameter label enter API Key.

In Parameter name enter Authorization.

In Parameter location choose Header.

Click on Definition to go to the next section.


Definition Section

Click on New action.

This image has an empty alt attribute; its file name is image-12.png

In the General panel, give your action an Operation ID.
Leave the Visibility as none.
The Summary and Description fields are optional.

In the Request section, click on Import from sample.

This image has an empty alt attribute; its file name is image-14.png

Choose POST as the Verb.

Enter the URL to your service.

In the Headers field enter Content-Type .

In the Body field enter sample JSON for your inputs.
The body structure for the request will be created from this sample.

Click on Import.

Click on the menu for Content-Type and click on Edit.

In the Default value field enterapplication/json .

In the Is required? field choose Yes.

Click on Back to go back to the definition.

Click on the menu for body and click on Edit.

Mark Is required? as Yes.

Ensure that your input parameters have been added to the body.
If they have not been added correctly, you’ll need to try to import again with valid JSON input parameters.

Click on Back to go back to the definition.

Click on Create Connector.

Once the connector has been saved, click on Test.

Test Section

In the Connections panel, click on New connection.

Click on Create.

Enter the access token you have obtained earlier in this guide as the API Key and click Create.

Navigate to Data > Custom Connectors and click to open the custom connector you created. Then click on Edit.

Click on Test.

In the Connections panel, ensure you have a selected connection.

In the Content-Type field enter application/json if it’s not already there.

Enter the rest of your inputs as per your service and click on Test Operation.

If successful, the response status should be 200 and you should be able to see the outputs from the service in the body of the response.

Create the service in a flow

After successfully creating the connectors to get the token and service, we can create a flow to put them together.

  1. Add the connection you created to get the token TokenAuth)
  2. Assign the retrieved access token to a variable
  3. Create the service connection (ExecutePetAge) using the token

Once you tested the flow, you will be able to see the created connection under connections.

Updated on October 27, 2023

Was this article helpful?

Related Articles