Logic Apps provide a way to simplify and implement scalable integrations and workflows in the cloud. Using Logic Apps, you can create an application to manage your service’s resources programmatically. But how to call the Azure Management API in Logic Aps?. In this article, we will demonstrate how to get the email address of the Azure subscription vai Azure Management REST API and send an email to in Logic Apps dynamically.
Create a management certificate
Please follow the steps in this document to create your management certificate:
Upload your management certificate through Azure classic portal
Then you need to upload your management certificate to your subscription (public certificate .cer file) so that it is authorized to perform management operations on your behalf. Please follow this documentation for step-by-step details:
Find the API you needed.
In this sample, we will use an Azure Management REST API to get the User Accounts information (https://msdn.microsoft.com/en-us/library/azure/dn469420.aspx):
Part A: Create a Logic App to get the email of Admin (Parent Logic App).
Create a request trigger.
We created a request trigger here to start our workflow. But you can use any other triggers.
More information you can find here: https://docs.microsoft.com/en-us/azure/logic-apps/logic-apps-http-endpoint
Create an HTTP action.
In this action, we will call Azure REST API using client certificate (pfx + password).
Note: You need to base64 encode the pfx file content and embed in the pfx textbox.
The format of the response body is a xml file as follows:
<?xml version="1.0" encoding="utf-8"?>
In Logic Apps, it is more convenient to pass the data as a JSON file between different actions or apps.
You can use @JSON() function to convert the XML content easily in Logic Apps as below:
In real word, you can define any actions after you got the response message.
Here we defined a child logic apps to parse the response and send email – sendEmail.
Part B: Create a Logic App to parse the response and send email to Admin (Child Logic Apps).
The sendEmail app takes an array of subscription admins and uses Send email action inside a ForEach loop
Create a request trigger to accept the response.
Here is a sample of the JSON format playload:
Put the above JSON data to http://jsonschema.net to get the its JSON schema.
Paste the schema definition in request trigger. With the help of JSON schema, Logic App could automatically tokenize all properties e.g. Principals, EmailId etc.
Create a ForEach action – Loop over all principals
a. Send Email action – Send email using Office 365 send email action.
b. Response action – Child workflows should have response action to be callable from another logic app use native child workflow action.
Now, when you run the application, you will get the email address of the Azure Subscription and send a customer email to him. Similarly, you can call any Azure Management API like this.
Thanks to Vinay Singh, Xiaodong Zhu.