top of page
Writer's pictureAlan Campbell

Python to Power Apps via Azure: Custom Connector - Part 2

Updated: Oct 30, 2023

Welcome back to the second installment in our series where we are developing a Power Platform custom connector that synergizes with the Python Script function app we created in the first part of this series. We are continually building on the foundations set in our initial guide, bringing you a step closer to unlocking robust functionalities that will integrate seamlessly with your Python scripts through Power Apps using Azure Function Apps.


In this blog, we delve deeper into the nitty-gritty of setting up a custom connector in PowerApps, a pivotal aspect in enabling a fluid integration with your Python Script function app. The process, albeit detailed, is streamlined to facilitate ease of setup, even for those venturing into this sphere for the first time.


We kick off this guide with a step-by-step walkthrough, guiding you meticulously through each phase, starting from navigating to the "Discover All" button in PowerApps to eventually updating your connector to mark it ready for use. The road to establishing a custom connector encompasses several stages, including:

  1. Laying the Groundwork in PowerApps – Get acquainted with the PowerApps interface and pinning essential options for easy reference.

  2. Setting the Stage with Custom Connectors – This is where we initiate the journey, naming your connector, and setting it up for the journey ahead.

  3. Defining the Details Under Various Tabs – We move ahead with detailing out the crucial information under the General, Security, and Definition tabs, ensuring airtight security and optimum functionality.

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

  5. The Response Section – Here, we transition from crafting the request to focusing on how to appropriately set up the response section, emphasizing the right method to import from a sample and edit content types to meet your specific needs.

  6. Testing the Waters – Before we deem the connector ready, we immerse ourselves in a testing phase, where we foster a new connection and witness firsthand the connector in action, allowing for any necessary tweaks based on real-time feedback.

  7. Fine-tuning and Final Steps – As we approach the culmination of this guide, we delve into the nuances of editing and updating the connector, paving the path for a connector that is now primed and ready to function seamlessly.

Remember, each step is illustrated with detailed instructions, setting a clear path even for those unfamiliar with the process. This blog is crafted to be your guiding light, leading you through every twist and turn in the creation process, assuring that you can confidently craft a connector that stands tall on the foundation built in part one of our series.


Join us as we continue to unravel the myriad possibilities that unlock when Python scripts meet Power Apps through Azure Function Apps. Stay tuned for the journey that awaits in the subsequent parts of this enlightening 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 Apps
Click on the Discover all button in Power Apps

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 Apps
Pin the Custom connectors to the Navigation Pane in Power Apps

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 Apps
Click on New custom connector in Power Apps

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 Apps which shows as the API Key
Enter the Authentication Type in Power Apps

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

Create a New Action in Definitions Section of Power Apps
Create a New Action in Definitions Section of Power Apps

General Section. Enter the following on the General section.


a. Under Summary enter: GetStatistics.

b. Under Description enter: This gets statistics from a Python script

c. Under Operation ID enter: GetStatistics.

Add the Operation ID to the General Tab of 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://appalan3-apim.azure-api.net/appAlan3/HttpTriggerAlan

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
Update the Content Parameter Settings in the Custom Connector

7. Click the Create connection button in the menu.

Click Create Connector in Power Apps
Click Create Connector in Power Apps

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:


{
	"slope": -96.64999999999999,
  		"intercept": 5002.616666666667,
  		"r": -0.3247983548185419,
  		"p": 0.2375335363376549,
  		"std_err": 78.05630651766381
}

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 wrap up the second installment of our series, we have successfully navigated the detailed pathway of crafting a custom connector in the Power Platform, one that impeccably integrates with the Python Script function app we initiated in our first blog. This deep dive has seen us traverse from laying the primary groundwork in PowerApps to meticulously defining, crafting, and fine-tuning both request and response sections, punctuated by a crucial testing phase to ensure seamless functionality.


You now have at your disposal a fully functional custom connector, a robust tool forged with precision and tailored to foster a seamless interaction with the Python scripts via Power Apps using Azure Function Apps. By following the steps outlined in this guide, you have 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, equipped with a custom connector ready to be deployed, you are prepared to unlock a world rich with data-driven insights, where Python scripts harmoniously sync with Power Apps, 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 exciting. Stay tuned for our next installment where we will further enhance our custom connector, adding layers of functionalities, and demonstrating the limitless potential that this integration offers.


Thank you for being a part of this journey with us. We are eager to see the heights you will reach with this newly acquired knowledge. Until our next guide, happy exploring!

1,977 views0 comments

Recent Posts

See All

© 2023 Bluedialog LLC. All rights reserved.

bottom of page