Failed to fetch swagger – API Apps

Failed to fetch swagger – API Apps

Today I was running into this Failed to fetch swagger issue while publishing API Apps using Visual Studio and therefore decided to devote a blog post to it. Hopefully this post will save some others some time.

Failed to fetch swagger – Configuration

When testing API Apps, I typically use the Publish web option instead of the preferred way of working with Azure Resource Manager templates. Due to this, I often forget to configure the API Definition and CORS settings for the Web App containing my API App. This results in the following error message:

Error: Failed to fetch swagger. Ensure you have CORS enabled on the endpoint and are calling an HTTPS endpoint.

Failed-to-fetch-swagger-1

Solution

Fortunately, it’s straightforward to fix this issue manually by following the steps below:

  • 1: Locate the Web App hosting your API App within the Azure Management Portal.
  • 2: Click on Settings, and within the Settings blade, locate the section called API.
  • 3: For the API Definition, make sure to provide the link as configured within your API App. The default is https://{your-webapp}.azurewebsites.net/swagger/docs/v1
  • 4: Open the CORS options and add * , which is required for the Logic Apps designer to work properly
  • 5: Restart the Web App

Failed-to-fetch-swagger-2

Resources

Custom API Apps – https://azure.microsoft.com/en-us/documentation/articles/app-service-logic-custom-hosted-api/
Details on CORS in Azure Web Apps- https://azure.microsoft.com/en-gb/documentation/articles/app-service-api-cors-consume-javascript/

Post Navigation