Creating a custom Azure Logic Apps connector

Objective

Drop-down dialog allowing selecting, scrolling through and searching for available connectors.
Visual Studio

To create, deploy and use a custom Connector that can be used in Azure Logic Apps. We also want to be able to publish this connector in the gallery (so that it shows up in the list with other connectors). For now the latter appears to be primarily available as invite-only for Microsoft partners.

Disclaimer

During my research it became clear that Azure and the Microsoft Flow services are constantly changing, both in terms of functionality and user interface. What follows are based on my experience at the time of this writing. By the time you read this there have likely been additional changes.

What you need to know first

Drop-down dialog allowing selecting, scrolling through and searching for available connectors.
Azure web UI
  1. Custom connectors are just ASP.NET Web API applications.
  2. An action (the functionality provided by a connector) in Microsoft Flow and Logic Apps relates directly to an operation in your Web API – The connector/action executes the configured operation from your Web API.
  3. While it’s technically not required, you’re going to want your Web API to be described using Swagger (aka OpenAPI Specification). Microsoft uses an extended Swagger spec to provide additional information and functionality to the connector.
  4. Logic Apps will timeout an HTTP request after 1 minute (the documentation for Flow says 90 seconds). If the call to your Web API might take longer you will need to implement the async pattern.

Microsoft Flow / Azure Logic Apps

Logic Apps are an outgrowth of BizTalk and various workflow platforms from Microsoft. They are a way to build workflows that can integrate with a variety of external services. Think IFTTT with the ability to provide more logic, or Yahoo! Pipes.

Flow is kind of a “lite” version of Logic Apps. Flows use the same connectors as Logic Apps, but expose less of their functionality and have fewer options for linking connectors. Microsoft Flow is a direct competitor to IFTTT.

Workflows in both consist of actions. These actions come in two flavors:

  • Triggers – Every workflow must start with a trigger action. Triggers are executed in response to some event. There are two types of triggers:
    • Polling triggers periodically check status (e.g. by calling a Web API) and only take action when the status conditions are met.
    • Push triggers, sometimes called webhooks, provide a special endpoint for the Logic App. When that endpoint is called from an external process with the appropriate values the workflow starts.
  • “Normal” actions – This encompasses all non-trigger actions. These respond to the previous action and may pass their data on to the next action.

There are already several good tutorials on-line that cover the basics of creating Flows and Logic Apps, so I’m not going to go into that here. These are a few that I recommend:

Because Microsoft Flow and Logic Apps both allow the user to select the same connector/actions from the gallery, we will start by adding our Custom API to Flow. Once there it can be rolled out for Logic Apps.

The built-in HTTP connectors

If you don’t need your custom API to be in the gallery where other users can select it to include in their own Flows the easiest way to access it is with one of the built-in connectors:

HTTP Connectors

Custom APIs

Options menu

What we’re looking to do, however, is provide our own branded connector that customers can choose from the gallery instead of one of the built-in HTTP connectors. In Microsoft Flow, this is referred to as a Custom API. In Logic Apps this is referred to as a connector.

To register a Custom API for use in your flows click the gear icon in the top right and select Custom APIs.

On the next page click the Create custom API button:

  1. Upload the Swagger file that describes your API. (As of this writing the process will only accept an uploaded file. It will not accept a URL.)
  2. Upload an icon that represents your service. While the icon is required, it is already pre-populated with a generic image.
  3. Provide a description if you like.
  4. The Host and Base URL should be filled in from the contents of the Swagger file.
  5. Click Continue.
  6. Select the authentication method required by our API. You may be prompted for additional information.
  7. Click the Definition tab. This page shows the operations, parameters, entities, etc. that Flow found in your Swagger file. You may fine-tune names, descriptions, etc. here.

When done click Create API in the top right. If successful, your API should be listed on the Custom API page. From here you can create Connections, edit or remove the API.

T-Rex = Swagger + MS extensions

You may have noticed near the end of the steps in the previous section that a lot of cleanup was needed on the Definition screen. Maybe you needed to provide friendlier names, descriptions or set visibility.

Microsoft has provided the following extensions to the Swagger specification which covers some of these situations:

  • x-ms-summary provides a display name.
  • x-ms-visibility allows an element to be hidden from the UI or behind an “advanced” dialog.
  • x-ms-trigger denotes a trigger as well as what type.
  • x-ms-dynamic-values indicates that the values come from some other process (e.g. the result of another operation).
  • x-ms-dynamic-schema indicates that the format of the values is dynamic.

For more details see Customize your Swagger definition for Microsoft Flow.

Maintaining these extensions in your API’s Swagger by hand could become a real headache, so a Microsoft MVP by the name of Nick Hauenstein has created a library for that. T-Rex extends the Swashbuckle library, which generates Swagger for ASP.NET WebAPI applications, with additional attributes to generate the Microsoft extensions listed above.

Here is an example from the T-Rex documentation:

NOTE: At the time of this writing the stable release of T-Rex only includes support for the summary, visibility and trigger extensions.

Creating a connection

After the Custom API has been registered you will need to create a connection to it before it can be used in a Flow.

image

From the Custom API page, click the plus (+) icon for the API you want to connect to. Enter the connection information when prompted then click the Create Connection button.

That’s it! You can now select your Custom API from the list of actions in a Flow.

image

Getting into the public gallery

Following the previous steps, your Custom API will only be available to you, your team and others you share it with – using the same connection (including credentials) you created. It will not be available to all Flow users. Nor will it be available to Logic Apps.

To get your Custom API into the public gallery, where it can be used by anybody, you will need to contact Microsoft. They will review and test the Custom API and, if approved, make the necessary changes to require each user to set up their own connection. Only then will they make it available to all users.

Once your Custom API is in the Flow gallery Microsoft will incrementally roll it out across data centers for use in Azure Logic Apps.

Additional references

Comments 1

Leave a Reply to Nick Hauenstein Cancel reply

Your email address will not be published. Required fields are marked *

%d bloggers like this: