top of page
Writer's pictureAlan Campbell

Building a Python-Linked Custom Connector - Part 2

Updated: Oct 30, 2023

Welcome back to part two of our series where we are evolving a Power Automate custom connector to synergize with the Python Function App we fashioned in the prior part of this series. We continue to build upon the foundations established in our preceding guides, inching you closer to unlocking robust functionalities that will meld seamlessly with your Python scripts via Power Automate utilizing Azure Function Apps and Microsoft Dynamics 365 Business Central.


In this segment, we delve into the core of setting up a custom connector in Power Automate, a pivotal stepping stone towards facilitating fluid integration with your Python Function App. Though the process is detailed, it's streamlined to ensure a smooth setup, even for those navigating this realm for the first time.


We initiate this guide with a meticulous step-by-step walkthrough, escorting you through each phase, from navigating to the "Discover All" button in Power Automate to eventually updating your connector marking it ready for deployment. The journey towards establishing a custom connector unfolds through several stages, including:

  1. Laying the Groundwork in Power Automate – Familiarize yourself with the Power Automate interface and pinning essential options for effortless reference.

  2. Setting the Stage with Custom Connectors – Here we commence our endeavor, naming your connector, and prepping it for the journey ahead.

  3. Detailing Under Various Tabs – We advance by outlining crucial information under the General, Security, and Definition tabs, ensuring robust security and optimal functionality.

  4. Crafting the Request – A pivotal phase where we meticulously define the request structure, ensuring the right settings are in place for the parameters to operate correctly.

  5. The Response Section – Transitioning from crafting the request to setting up the response section, focusing on the correct method to import from a sample and edit content types to cater to your specific needs.

  6. Testing the Waters – Before declaring the connector ready, we delve into a testing phase, creating a new connection and observing the connector in action, allowing for any necessary adjustments based on real-time feedback.

  7. Fine-tuning and Final Steps – Nearing the end of this guide, we delve into the subtleties of editing and updating the connector, paving the way for a connector now primed and ready for seamless operation.

Each step is elucidated with detailed instructions, ensuring a clear pathway even for those new to the process. This blog aims to be your beacon, guiding you through every twist and turn in the creation process, ensuring you can confidently craft a connector that resonates with the foundation laid in the initial part of our series.


Join us as we continue to unravel the myriad possibilities that unfold when Python scripts rendezvous with Power Automate through Azure Function Apps. Stay tuned for the enthralling journey that awaits in the subsequent parts of this illuminating series.


Create the Connector


1. In PowerApps, click on the ... More button in the left navigation pane followed by the Discover All button.

Click on the Discover all button in Power Automate to start the process of adding a custom connector to be consumed in power automate
Click on the Discover all button in Power Automate

2. Look for the Data section and then pin the Custom connections option to the navigation pane on the left as you will be referencing the option often.

Pin the Custom connectors to the Navigation Pane in Power Automate so that we can reference it quicker in the future
Pin the Custom connectors to the Navigation Pane in Power Automate

3. Click on Custom connectors in the left navigation pane and then click on New custom connector in the upper right corner and select the Create from blank option. Provide a name for the connector. I called mine ChatGPT.

Click on New custom connector in Power Automate to start the process of creating a new connector that will call a Python Function App in Azure
Click on New custom connector in Power Automate

4. General Tab. Enter the following under the General tab.


a. Enter your API Host and Base URL from Azure

Enter the Host Name in the Custom Connector from your Azure API
Enter the Host Name from you Azure API in the Custom Connector

5. Security Tab. Enter the following under the Security tab.


a. Select the API key under the authentication type.

b. Under the Parameter label enter: API Key.

c. Under the Parameter name enter: Authorization.

Enter the Authentication Type in Power Automate which shows as the API Key which we setup in Azure
Enter the Authentication Type in Power Automate

6. Definition Tab. Click on New action in the left action pane.

Create a New Action in Definitions Section of Power Automate. This could be one of many actions that we setup in the future.
Create a New Action in Definitions Section of Power Automate

General Section. Enter the following on the General section.


a. Under Summary enter: GetGraphics.

b. Under Description enter: Gt Graphics

c. Under Operation ID enter: GetGraphics.

Add the Operation ID to the General Tab of the Custom Connector. this is the name we will reference when calling the custom connector.
Add the Operation ID to the General Tab of the Custom Connector

Request Section. Under the Request section click on the Import from sample button.


a. Select Post under the Verb section.

b. Under the URL enter your URL: https://appalan-apim.azure-api.net/appAlan3/HttpTriggerAlan3

b. Under the Headers enter: Content-Type: application/json

c. Under the Body paste the code below.

d. Then click Import.


{
  "x": "0,1,2,3,4,5,6,7,8,9,10,11,12,13,14",
  "y": "4535,3887,6477,4534,6477,3239,5182,5182,2592,3888,1944,3239,5829,3886,4000"
}

Content -type. Edit the Content Type under the Headers in the Request section.


a. Under Default Type enter: application/json

b. Set the Is required? to true.

b. Change Visibility to Internal.

c. Click the back button.

Add the Content Type Parameter to the Custom Connector
Add the Content Type Parameter to the Custom Connector

Body. Edit the body under Body in the Request section.


a. Set the Is required? to true.


X and Y Parameters. Edit both the X and Y parameters.


a. Set the Is required? to true.

b. Set the Visibility to Important.

c. Click the Back button.

Update the X and Y Content Parameter Settings in the Custom Connector for Power Apps connecting to Python Scripts.  x and y will represent the months and associated sales from Business Central
Update the Content Parameter Settings in the Custom Connector

7. Click the Create connection button in the menu.

Click Create Connector in Power Automate.
Click Create Connector in Power Automate

Test and Complete the Response Section for the Connector


8. You will need an API key from your API in Azure to test the connector.


9. Click on Test in the menu and then on New connection. Enter in the API Key field your API Key that you created for your API in Azure.


10. Click Edit on the ChatGPT connector in the Custom connector list in the left navigation pane. Then, click on Test in the menu. You now see a date and time stamp in the Connections box. Enter the first line of data below for X and the second line of data for Y and click Test operation. You should see a 200 status in the results.


0,1,2,3,4,5,6,7,8,9,10,11,12,13,14
4535,3887,6477,4534,6477,3239,5182,5182,2592,3888,1944,3239,5829,3886,4000

11. Copy the results from the Body section under the response tab. My response was the following. Take note that the image tag contains the trend chart that we will be using later in the blog series.


{
  "slope": -96.64999999999999,
  "intercept": 5002.616666666667,
  "r_value": -0.3247983548185419,
  "p_value": 0.2375335363376549,
  "std_err": 78.05630651766381,
  "image": "iVBORw0KGgoAAAANSU...............
}

12. Definitions Tab. Click on the Definitions tab in the menu and then enter the following.


a. Under the Response section click on the Default button.

b. Click on the Import from sample button.

c. Enter in the headers Content-Type application/json

d. Paste your results from the Body section in the previous step into the Body Field.

e. Click the Import button.

Importing the Body results from the prior Test step when creating the custom connector in power apps when connecting to Python Function Apps in Azure
Import the Body result from the Test

13. Click on Update connector in the menu. The connector is now ready!


Conclusion


As we conclude this segment of our series, we've successfully navigated through the intricate process of crafting a custom connector in Power Automate, one that impeccably integrates with the Python Function App we initiated in our first blog. This deep dive has seen us traverse from laying the primary groundwork in Power Automate to meticulously defining, crafting, and fine-tuning both request and response sections, punctuated by a crucial testing phase to ensure seamless functionality.


You now possess a fully functional custom connector, a robust tool precisely forged to foster a seamless interaction with the Python scripts via Power Automate using Azure Function Apps. By following the steps outlined in this guide, you've not only created a connection but have opened a gateway to a realm of expansive possibilities, laying a concrete foundation for sophisticated, predictive analytics in your business ecosystem.


As you stand at this juncture, armed with a custom connector ready for deployment, you're prepared to unlock a world rich with data-driven insights, where Python scripts harmoniously sync with Power Automate, promising a streamlined business process driven by informed decisions.


Looking forward, we encourage you to explore this powerful tool, to delve deeper, and to innovate, leveraging the comprehensive capabilities that have now been unlocked. The journey doesn't end here; it only gets more thrilling. Stay tuned for our next installment where we will further enhance our custom connector, adding layers of functionalities, and showcasing the boundless potential that this integration offers.


Thank you for embarking on this journey with us. We're eager to witness the heights you'll reach with this newly acquired knowledge. Until our next guide, happy exploring!

29 views0 comments

Comments


bottom of page