Working with custom connectors – a few observations

By | December 18, 2019

For some reason, I got hooked up on the custom connectors for the time being. It’s a bit of a learning curve for somebody who has not been doing a lot of development outside of the plugins/scripts/occasional .NET  for a while, so, if nothing else, it’s a good exercise in re-building at least some of those development skills.

Interestingly, the learning here is not focused on the development only. Custom connectors are closely tied to PowerPlatform, and, besides, my Web API has to be hosted somewhere, so this involves building a Web API, but this also involves figuring out how to host it in Azure (in my case), and how to set up a connector in PowerPlatform.

Hence, in no particular order, here are some of the observations so far.

1. Creating a web API in the Visual Studio is very straightforward

image

Once you have a project, you may want to remove everything other than the Post method, and you may also want to update the route:

image

Then you just need to publish it somewhere, and, of course, publishing to Azure is easy:

image

You may want to look at the more detailed tutorial here, though:

https://docs.microsoft.com/en-us/aspnet/core/tutorials/first-web-api?view=aspnetcore-3.1&tabs=visual-studio

2. Creating a swagger file (or OpenAPI file) is more involved

That file is, really, just a description of your API. While creating a custom connector in PowerAutomate/PowerApps, you can feed that file to the custom connector “wizard”, it will parse it, and you won’t have to do a thing manually at that point.

But, of course, you may actually want to create that file AFTER you have an API. Or you may even want to generate it automatically.

This is where a couple of tools might help.

a) The post below provides instructions on how to generate swagger files for your web api projects

https://www.talkingdotnet.com/add-swagger-to-asp-net-core-2-0-web-api/

However, once the file was generated, I still could not use it to create a custom connector since some of the information was missing from the file

b) Swagger editor might help at that point

http://editor.swagger.io/

I added a few tags to my files (“host”, “basePath”, “schemes”, “consumes”, “produces”). Not sure all of them would be required, but pretty sure PowerPlatform expects at least the “host” information to be there (since that’s where I was getting an error).

3. Enabling authentication for your web api (in Azure)

This turned out to be a more complicated story for some reason, and I’m still trying to figure it out. Web API would be hosted as an app service, and it was not that complicated to enable authentication there. What has proven to be more challenging is setting it up so that users from other Azure tenants could use my web api.

Firsrt of all, that requires a custom domain. And, if there is a custom domain, it needs an SSL. And, if there is an SSL, I need a more expensive app service hosting plan. But, even once I had done all of that, I was still getting an error when trying to utilize my Web API with an account from another tenant, since, somehow, I was still required to add that user as a guest first. Anyway, that’s the bulk of it, and, it seems I’ll need to get back to the authentication part.

For now, there is no authentication on my web api.

4. It’s the second time when I’m observing errors in make.powerapps.com while flows.powerapps.com is working fine

It happened with the UI Flows before: https://www.itaintboring.com/power-platform/ui-flow-in-power-automate-former-microsoft-flow/

And it also happened this time when I was trying to update my custom connector. Turned out there is a related recent community thread, so, it seems, it’s just my luck that I’ve started working with custom connectors just about the same time when this problem was reported: https://powerusers.microsoft.com/t5/Building-Power-Apps-Formerly/Can-t-update-or-create-a-custom-connector/td-p/428162

Anyway, in my case switching to canada.flow.microsoft.com has helped in both situations.

5. While in the “test” mode, custom connectors don’t seem to recognize arrays

There is an array parameter in my connector. It works fine when using “raw body” option to adjust json:

image

However, once in the “regular” mode, there seem to be no way to turn that parameter into an array – it would only accept one element no matter what:

image

Still, when using that connector in the actual Flow, I can set up an array:

image

And I can pass that array through the action parameter:

image

Either way, so far web api source code is on github:

https://github.com/ashlega/ItAintBoring.PowerPlatformWithCode/tree/master/ItAintBoring.SimpleWebApi

There is a related swagger file you can use to create a custom connector in PowerPlatform:

https://github.com/ashlega/ItAintBoring.PowerPlatformWithCode/blob/master/ItAintBoring.SimpleWebApi/swagger.json

The API is hosted in Azure on a shared plan – you can try it, but don’t expect much in terms of uptime/reliability:

https://itaintboringsimplewebapi.azurewebsites.net/v1/addbusinessdays

https://itaintboringsimplewebapi.azurewebsites.net/v1/regex

Both methods will expect a post request.

Regex is, well, regex. More details here: https://www.itaintboring.com/dynamics-crm/custom-connector-where-powerautomate-finds-peace-with-logic-apps/

The other one (addbusinessdays) will take the starting date, an array of holidays (see screenshots above), and the number of business days to add to the starting date. It will, then, add those days to the starting date having accounted for Saturdays, Sundays, and all the holidays on the list.

Leave a Reply

Your email address will not be published.