Share via

APIM Standard v2 – Bicep deployment fails with BadGateway when adding APIs to Product (service/products/apis)

D C 0 Reputation points
2026-04-23T23:56:18.7166667+00:00

I’m deploying resources to Azure API Management (Standard v2) using Bicep, and consistently hitting a failure when associating APIs to a product.

The deployment hangs on the following example bicep resource and eventually fails with a generic BadGateway error:

var apisToAdd = [ 'some-api'
  'another-api'
]

resource apimResource 'Microsoft.ApiManagement/service@2022-08-01' existing = {
  name: apiManagementName
}

resource apimDefaultProductResource 'Microsoft.ApiManagement/service/products@2022-08-01' = {
  name: productName
  parent: apimResource
  properties: {
    displayName: productName
    subscriptionRequired: true
    state: 'published'
  }
}

resource apimApiProductResource 'Microsoft.ApiManagement/service/products/apis@2022-08-01' = [for api in apisToAdd: {
  name: api
  parent: apimDefaultProductResource
}]

Azure Portal shows multiple failed operations of type:

Microsoft.ApiManagement/service/products/apis Status: BadGateway

Example image attached.

This started occuring today - it has worked for weeks prior on APIM v2. It still works on my APIM v1 instances. Is this a known issue? Or has there been a change someplace regarding the bicep or resource?

Let me know if I can provide any further information! I'll provide some info below that may help you:

  • Deployment Correlation ID of failed deployment - it technically timesout as the pipeline will cancel it after 1 hour, normally it's a step that takes ~1 second: [REDACTED]
  • Timestamp: 24/04/2026, 00:43:34
  • Deployment Correlation ID of same resource, but last successful deploy: [REDACTED]
  • Timestamp: 23/04/2026, 10:28:12

For further context here is the status message when it fails:

{
"status": "Failed",
"error": {
    "code": "InternalServerError",
    "message": "<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Strict//EN\" \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd\">\r\n<html xmlns=\"http://www.w3.org/1999/xhtml\">\r\n<head>\r\n<meta http-equiv=\"Content-Type\" content=\"text/html; charset=iso-8859-1\"/>\r\n<title>502 - Web server received an invalid response while acting as a gateway or proxy server.</title>\r\n<style type=\"text/css\">\r\n<!--\r\nbody{margin:0;font-size:.7em;font-family:Verdana, Arial, Helvetica, sans-serif;background:#EEEEEE;}\r\nfieldset{padding:0 15px 10px 15px;} \r\nh1{font-size:2.4em;margin:0;color:#FFF;}\r\nh2{font-size:1.7em;margin:0;color:#CC0000;} \r\nh3{font-size:1.2em;margin:10px 0 0 0;color:#000000;} \r\n#header{width:96%;margin:0 0 0 0;padding:6px 2% 6px 2%;font-family:\"trebuchet MS\", Verdana, sans-serif;color:#FFF;\r\nbackground-color:#555555;}\r\n#content{margin:0 0 0 2%;position:relative;}\r\n.content-container{background:#FFF;width:96%;margin-top:8px;padding:10px;position:relative;}\r\n-->\r\n</style>\r\n</head>\r\n<body>\r\n<div id=\"header\"><h1>Server Error</h1></div>\r\n<div id=\"content\">\r\n <div class=\"content-container\"><fieldset>\r\n  <h2>502 - Web server received an invalid response while acting as a gateway or proxy server.</h2>\r\n  <h3>There is a problem with the page you are looking for, and it cannot be displayed. When the Web server (while acting as a gateway or proxy) contacted the upstream content server, it received an invalid response from the content server.</h3>\r\n </fieldset></div>\r\n</div>\r\n</body>\r\n</html>\r\n"
}
Azure API Management
Azure API Management

An Azure service that provides a hybrid, multi-cloud management platform for APIs.


1 answer

Sort by: Most helpful
  1. Rakesh Mishra 8,420 Reputation points Microsoft External Staff Moderator
    2026-04-24T00:11:36.6033333+00:00

    Hello D C!

    Thank you for providing the detailed error payload. Please find the summary of our discussion and resolution over emails.

    You tried below troubleshooting steps, but it did not work.

    1. Update your Bicep API version (Highly Recommended) In your Bicep snippet, you are using the API version 2022-08-01. The Standard v2 pricing tier did not exist when the 2022-08-01 API specification was released. While ARM attempts backwards compatibility, sending a payload with an older API version against a newly introduced v2 tier can sometimes cause control-plane translation failures on the backend—which often result in the exact 502 HTML proxy error you are seeing.

    • Action: Try updating the API version for all your APIM resources in this template (including the parent existing resource) to a newer version that natively understands the v2 tiers, such as 2023-09-01-preview or 2024-03-01.

    2. Avoid Bicep Race Conditions (dependsOn) Even though Bicep infers parent-child dependencies implicitly, array loops ([for api in apisToAdd]) creating mappings can sometimes fire an API request to the control plane just milliseconds before the actual API definitions (some-api, another-api) are fully committed across the APIM distributed backend. This race condition can sometimes cause the backend management plane to crash or hang, returning a 502.

    • Action: Ensure you have an explicit dependsOn property referencing the Bicep block that creates the APIs themselves, so the association loop doesn't jump the gun.

    3. Test Manual/REST Association To instantly confirm if this is an Azure-side bug rather than a Bicep syntax issue, go into the Azure Portal for this Standard v2 instance and try manually associating some-api to the product. If the portal hangs or throws an error, you have confirmed the backend management plane for your instance is temporarily degraded.

    Resolution: There was an outage on April 22, 2026 in v2 SKU of various APIM resources. The issue was resolved by the backend team, and you confirmed that issue is resolved.


Your answer

Answers can be marked as 'Accepted' by the question author and 'Recommended' by moderators, which helps users know the answer solved the author's problem.