Getting my Swagger On with Custom Connectors

One of the topics I love to explore with audiences is custom connectors. Custom connectors allow us to create an API wrapper for our services or for services which aren't covered by the other 300+ connectors available to the Power Platform.

Without diving too much into too much detail about they're created, they can be created in a number of ways. Either by providing an existing OpenAPI file (swagger file) from a file, or from a URL, from a Postman collection, by directly connecting to an Azure service, or through the built in connector creation wizard.

Regardless of which way you choose to create your connector, you will end up viewing and working with it in the edit connector screens of the Power Platform.
Where the difficulties have been in the past is if we want to make changes to the swagger file beyond the realms of what is possible through the wizard UI. We would need to download the swagger file, modify it using whatever tool we decide to use, and the upload it back to the Power Platform.

In order to reduce the development time in this area, a nice new addition has been made, whereby there is now a swagger editor directly within the Custom Connector editor.

Using the Swagger Editor

If I'm honest, I have no idea when this change was rolled out, I suddenly spotted it one day but thought it was an extremely welcome modification. Now, when I look at the top menu bar for the connector editor, I have a switch which allows me to turn on the "Swagger editor".
When I flick the switch, it brings up a split window where I can view and edit the code directly, and then observe the changes on the right, or I can use the configuration items on the right and watch the updates to the code on the left. Or, as I normally do, I use a hybrid approach, I use the config as much as possible and then tweak the code.
The nice thing with the editor is that it is constantly validating your work, so you can identify and rectify issues before you even start testing. As you can see from the above screenshot, the more you have defined your connector, the more this editor will work for you.
As we work on our swagger files, we should be testing as we go too.

Testing using the Swagger Editor

As I define my actions within my custom connector, I need to test to ensure that my updates are working the way that I want them to. Previously, you could configure your connector and then test at the end, but this would require you to create the connector first of all, and also create a new connection in order to test it.
When we test using the swagger editor, we effectively test the web service call within the context of the editor, therefore I won't end up with multiple connections, which I think is a really nice touch. As I expand out the connector, and then the individual actions, I can provide the query string parameters, the body JSON and then ultimately execute the service call.
Once the request has been made, I can then validate the response to make sure that I'm getting the response that I wanted, so that when I finally create the connector and do my final test, I know that everything is going to work.

Finally...

Custom connectors allow you exploit either your own services or services which are not currently provided by the huge array of connectors available within the Power Platform.

We can create a Custom Connector in a number of different ways including the ability to connector directly to an Azure service, or by creating a connector from scratch using the built in wizard. Regardless of which way I choose to create the connector, I will end up using the Custom Connector editor to modify the swagger (OpenAPI) file. If I wanted to update this later, particularly if I wanted to make a change beyond what is possible through the user interface, I would need to download, modify, and then re-upload the swagger file.

The Swagger editor which is now present in the custom connector screen allows me to modify the code contained within the swagger file directly within the browser. Ultimately I can test the connector from within the editor without the need to create a connection, which means that I can simply test my calls within the context of the session rather than writing anything back to the platform.

All in all, this is a great addition to the custom connector editor and one which will save a lot of development time in the future.

I hope you found this blog useful, and as always feedback is welcome.



Comments