0

Setting the API Definition URL and CORS value with ARM

Azure Resource Manager

When working with Azure services, you will combine services together. For one of mine integration cases I had to create a LogicApp where in I needed to use one of my own API’s in order to perform some actions.

In order for the Logic apps designer to parse your Swagger and notice your API as connector, it’s necessary that you enable CORS and set the APIDefinition properties of the web application you want to use. Using the portal this is very easy to set.

  • Open the settings blade of your Web App
  • Under the API section set the ‘API Definition’ to the URL of your swagger.json file (this is usually https://{name}.azurewebsites.net/swagger/docs/v1).
  • Add a CORS policy for ‘*’ to allow for requests from the Logic apps Designer.

These settings can also be set when you use a Azure Resource Management template to deploy your resources.

It’s very simple as well you need to add the “apiDefinition” “url” property and the “cors” property to the web config section.

{
  "name": "web",
  "type": "config",
  "apiVersion": "[variables('defaultApiVersion')]",
  "dependsOn": [
    "[concat('Microsoft.Web/sites/', parameters('api_Name'))]"
  ],
  "tags": {
    "displayName": "WebSettings"
  },
  "properties": {
    "cors": {
      "allowedOrigins": [
        "*"
      ]
    },
    "apiDefinition": {
      "url": "[concat('https://', reference(concat('Microsoft.Web/sites/', parameters('api_Name'))).defaultHostName, '/swagger/docs/v1')]"
    }
  }
}

In de code snippet above check the value of the “url” property of the “apiDefinition” it is a concatenation of parameters and created resources within my resource template making the URL property dynamic.

Related Posts

Azure DevOps Automation A couple of weeks ago the rename / rebranding of Visual Studio Team Services to Azure DevOps was announced. The rebranding is a great step forward int...
AKS (Kubernetes) and no connection could be made because the target machine acti... A client of my had an error while connecting to different resources within their Kubernetes cluster in Azure (AKS). Kubectl error On the kubectl com...
Kubernetes (AKS) attached to Azure Storage (Files) Kubernetes (AKS) can be used for many situations. For a client we needed to make files available trough a Kubernetes Pod. The files needed to be share...
Resource Group deployment via ARM templates When deploying an Azure Resource Manager (ARM) template you have to create a resource group within Azure. To deploy a template via script your script ...
Azure Managed Service Identity and Local Development Instead of storing user credentials of an external system in a configuration file, you should store them in the Azure Key Vault. Before MSI (Managed S...
The securitydata Azure resource group Most of the times companies have rules in place for managing their Azure environment. The main rules that should be in place are “Azure Policies” and ...

Leave a Reply

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

This site uses Akismet to reduce spam. Learn how your comment data is processed.