Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Publishing Azure function app with Api Management service -- Failed to update your API in Azure (Status code: BadRequest)

I have an Azure function app that uses api management service running locally. I created it with Visual Studio 2022. But when I try to publish it, everything looks good until this error appears.

========== Build: 1 succeeded, 0 failed, 0 up-to-date, 0 skipped ==========
========== Publish: 1 succeeded, 0 failed, 0 skipped ==========
Waiting for function app to be ready...
Finished waiting for function app to be ready
Starting to update your API
Failed to update your API in Azure (Status code: BadRequest).

The app is created under the resource group, but not the api management service. And analysis file was generated.

Microsoft.WebTools.Shared.Exceptions.WebToolsException: Failed to update your API in Azure (Status code: BadRequest).

   at Microsoft.WebTools.Azure.Publish.ApiMApi.BaseApiMApiUpdater.EmitTerminatingError(String bucketName, String displayedErrorMessage, String loggedErrorMessage)
   at Microsoft.WebTools.Azure.Publish.ApiMApi.BaseApiMApiUpdater.<UpdateApiMApiInAzureAsync>d__10.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at Microsoft.WebTools.Azure.Publish.ApiMApi.FunctionAppApiMApiPublishHandler.FunctionApiMApiUpdater.<ImportSwaggerLinkToApiMAppAsync>d__8.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at Microsoft.WebTools.Azure.Publish.ApiMApi.FunctionAppApiMApiPublishHandler.FunctionApiMApiUpdater.<RunUpdateAsync>d__6.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at Microsoft.WebTools.Azure.Publish.ApiMApi.BaseApiMApiUpdater.<RunUpdateWithTelemetryAsync>d__9.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at Microsoft.WebTools.Azure.Publish.ApiMApi.FunctionAppApiMApiPublishHandler.<UpdateApiMApiAsync>d__7.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at Microsoft.WebTools.Azure.Functions.PublishProviders.AzureFunctionProfileVisual.<FunctionsAfterPostPublishAsync>d__42.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at Microsoft.Publish.Framework.Nexus.PublishProfilesServiceImpl.ServerProjectProfilesManager.
<RunPublishTaskAsync>d__56.MoveNext()

=================== 

I also tried deleting everything and retrying, this time creating the api management service when I did the publish. The app was created as before, but the api management service was not created.

like image 449
BenW Avatar asked Oct 25 '25 17:10

BenW


2 Answers

If you are using the Azure Function OpenAPI template you'll need to make sure that each Function has a unique operationId in the OpenApiOperation attribute.

By default for a new function the operationId is set as "Run", changing this to a unique value fixed the Bad Request when publishing

[OpenApiOperation(operationId: "UniqueOperationId", tags: new[] { "name" })]

You can verify what is causing the Bad Request by looking into the logs in the Azure Portal

Navigate to the Resource Group --> Activity Log. From here you should be able to see the Failed attempt at Create API or Update API.

Resource Group Activity Log

Select the failed attempt and look into the JSON tab in the Panel that opens, and near the bottom should be the reasoning for the Bad Request

Ex:

BadRequest OpenApi operationId

like image 86
Ryan Bates Avatar answered Oct 27 '25 17:10

Ryan Bates


Here is the workaround I did to publish the Azure Function - .Net Stack - Http Trigger with Open API.

  • Created the Azure Functions (.Net 3.1 Stack - Http Trigger with Open API) and got the boilerplate code which takes the name as Query Parameter and sends the result.
  • Published it by creating the Azure Functions App Instance and Azure APIM Instance from Visual Studio Publish Window and it is successful.

enter image description here

  • Modified the boilerplate code by removing the name parameter and displaying the custom response message.
  • Published the updated function code to the Azure APIM and updated the API Successfully.

enter image description here

Note:

Microsoft.WebTools.Shared.Exceptions.WebToolsException: Failed to update your API in Azure (Status code: BadRequest).

This error happens when there have been current updates to Visual Studio at least to my knowledge.

And this error is related to build problem or Run time error I guess.

To resolve this error, follow the steps below:

  1. Stop or Cancel Building the application if the build is stuck.
  2. Make sure you save your changes
  3. Close Visual Studio and open your project again.
  4. When the project loads into Visual Studio, Clean the Solution
  5. Then build the solution
  6. After building the solution, go ahead and publish if you need to.