Close

Release versioned APIM Service via VSTS

I received an error when releasing a ARM template for a versioned API Management Service that I created via the APIManagementARMTemplateCreator. To be able to release a versioned API Management service, you will have to add a versionset resource to the ARM template. For example:

"resources": [
    {
      "type": "Microsoft.ApiManagement/service/api-version-sets",
      "name": "[concat(parameters('apimServiceName'), '/', parameters('versionset_name'))]",
      "apiVersion": "2018-06-01-preview",
      "properties": {
        "displayName": "[parameters('api_customerservicecrm_displayname')]",
        "description": "version set",
        "versioningScheme": "Segment",
        "versionQueryName": "api-version",
        "versionHeaderName": "api-version"
      }
    },

Note that the versionnumber is added to the URL path. In that case versioningScheme has to be set to Segment. Other options are Query (for query parameter) or Header. Because you set versioningScheme to Segment, settings versionQueryName and versionHeaderName are not used. Probably they can actually be removed. 

In the Versionset definition a few parameters are used that have to be added to the Parameters section. Note that you have to put square brackets around the parameters in the versionset definition:

"api_customerservicecrm_displayname": {
      "type": "string",
      "defaultValue": "CustomerServiceCRM” 
}

"versionset_name": {
      "type": "string",
      "defaultValue": "versionset" 
}

Finally you will have to add a DependsOn statement at the end of the ARM template. The service depends on the version set, so you will have to add a line.

"dependsOn": [
        //added line below
        "[resourceId('Microsoft.ApiManagement/service/api-version-sets', 
parameters('apimServiceName'), parameters('versionset_name'))]"
      ]
    }
  ],
  "outputs": {}
}