Search code examples
azureazure-api-management

How do i update a serviceUrl of the parent API set when creating an API operation using apiVersionSetId


I have this API Set created in BICEP code:

resource NamesApi 'Microsoft.ApiManagement/service/apis@2022-08-01' = {
  name: '${name}-api-transaction'
  parent: apimService
  properties: {
    displayName: 'Names APIs'
    apiRevision: '1'
    subscriptionRequired: true
    serviceUrl: nameSearchUrl
    path: 'internal/name'
    protocols: [
      'http'
      'https'
    ]
    authenticationSettings: {}
    subscriptionKeyParameterNames: {
      header: 'Ocp-Apim-Subscription-Key'
      query: 'subscription-key'
    }
    isCurrent: true    
  }
}

adding apiVersionSetId property to the above gives me a versioned API - all good.

Now how do I update the serviceUrl of the new api operation to the version that i have just created ?


Solution

  • As mentioned in the comments, you can use set-backend-service policy to update the serviceUrl of the new Api operation to the versioned API.

    <policies>
        <inbound>
            <choose>
                <when condition="@(context.Request.Url.Query.GetValueOrDefault("version") == "2023-05")">
                    <set-backend-service base-url="http://xxxx.com/api/8.2/" />
                </when>
                <when condition="@(context.Request.Url.Query.GetValueOrDefault("version") == "2023-03")">
                    <set-backend-service base-url="http://xxxx.com/api/9.1/" />
                </when>
            </choose>
            <base />
        </inbound>
        <outbound>
            <base />
        </outbound>
    </policies>
    

    enter image description here