Setting the API Definition URL and CORS value with ARM

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

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 ...
Point to Site VPN Client won’t install To connect an Azure App Service to a on-premise database you can make use of different solutions. Two of those solutions are: Hybrid Connection ...
Invoke Azure Function in your Visual Studio Team Services CI/CD pipeline A utility task is available for Visual Studio Team Services (VSTS) to invoke an http triggered Azure function. The ability to invoke a Function from y...
VSTS Extension for Azure Role Based Access Control Today I published an extension for Visual Studio Team Services (VSTS) that gives you the ability to add and remove role based access assignments in Az...
Listing Azure Services within a CSV file In some situations you will look into a current Azure Environment and the setup/governance of it and need to migrate or move resources around. The ...
Azure Event Grid with Custom Events As of yesterday (16-8-2017) the public preview of Azure Event Grid is live. Azure Event Grid is a fully managed event routing service. Azure Event Gri...

Leave a Reply

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