Share via

Deploying APIM Workspace via Bicep script

Laurens van de Venn 260 Reputation points
2025-10-22T18:33:48.92+00:00

Hello,

I'm trying to deploy APIM Workspace via Bicep script but getting error.
Bicep script:
param apimServiceName string
param workspaceName string
param location string
param workspaceDescription string

// Create APIM Workspace

resource apimWorkspace 'Microsoft.ApiManagement/service/workspaces@2023-03-01-preview' = {

name: '${apimServiceName}/${workspaceName}'

location: location

properties: {

description: workspaceDescription

}

}

Error:

The template resource '/ws-lv-apim-a-icoe' for type 'Microsoft.ApiManagement/service/workspaces' at line '35' and column '58' has incorrect segment lengths. A nested resource type must have identical number of segments as its resource name. A root resource type must have segment length one greater than its resource name
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. Pravallika KV 17,025 Reputation points Microsoft External Staff Moderator
    2025-11-03T15:23:54.49+00:00

    Hi Laurens van de Venn,

    Thanks for reaching out to Microsoft Q&A.

    Use below bicep template to deploy APIM workspace:

    @description('Name of the existing API Management service')
    param apimServiceName string
    
    @description('Name of the workspace to create')
    param workspaceName string
    
    @description('Display name for the workspace')
    param workspaceDisplayName string = workspaceName
    
    @description('Description for the workspace')
    param workspaceDescription string = 'Sample APIM workspace created via Bicep'
    
    resource apimService 'Microsoft.ApiManagement/service@2024-10-01-preview' existing = {
      name: apimServiceName
    }
    
    resource apimWorkspace 'Microsoft.ApiManagement/service/workspaces@2024-10-01-preview' = {
      name: workspaceName
      parent: apimService
      properties: {
        displayName: workspaceDisplayName
        description: workspaceDescription
      }
    }
    
    output workspaceId string = apimWorkspace.id
    output workspaceNameOut string = apimWorkspace.name
    
    
    

    Az cli Command to deploy:

    az deployment group create --resource-group kprg --template-file main.bicep --parameters apimServiceName='APIM_Name' workspaceName='Workspace_Name'  workspaceDescription='Workspace for my APIs'
    
    • I could deploy the workspace using above Bicep template:
    az deployment group create --resource-group kprg --template-file main.bicep --parameters apimServiceName='kp-apim-service11' workspaceName='kp-workspace2'  workspaceDescription='Workspace for my APIs'
    
    {
      "id": "/subscriptions/5f33XX3d2b55/resourceGroups/kprg/providers/Microsoft.Resources/deployments/main",
      "location": null,
      "name": "main",
      "properties": {
        "correlationId": "5cbba8dd-10XX0-ad6e92a185d9",
        "debugSetting": null,
        "dependencies": [],
        "diagnostics": null,
        "duration": "PT4.4776633S",
        "error": null,
        "extensions": null,
        "mode": "Incremental",
        "onErrorDeployment": null,
        "outputResources": [
          {
            "apiVersion": null,
            "extension": null,
            "id": "/subscriptions/5f3XXb55/resourceGroups/kprg/providers/Microsoft.ApiManagement/service/kp-apim-service11/workspaces/kp-workspace2",
            "identifiers": null,
            "resourceGroup": "kprg",
            "resourceType": null
          }
        ],
        "outputs": {
          "workspaceId": {
            "type": "String",
            "value": "/subscriptions/5f33XXd2b55/resourceGroups/kprg/providers/Microsoft.ApiManagement/service/kp-apim-service11/workspaces/kp-workspace2"
          },
          "workspaceNameOut": {
            "type": "String",
            "value": "kp-workspace2"
          }
        },
        "parameters": {
          "apimServiceName": {
            "type": "String",
            "value": "kp-apim-service11"
          },
          "workspaceDescription": {
            "type": "String",
            "value": "Workspace for my APIs"
          },
          "workspaceDisplayName": {
            "type": "String",
            "value": "kp-workspace2"
          },
          "workspaceName": {
            "type": "String",
            "value": "kp-workspace2"
          }
        },
        "parametersLink": null,
        "providers": [
          {
            "id": null,
            "namespace": "Microsoft.ApiManagement",
            "providerAuthorizationConsentState": null,
            "registrationPolicy": null,
            "registrationState": null,
            "resourceTypes": [
              {
                "aliases": null,
                "apiProfiles": null,
                "apiVersions": null,
                "capabilities": null,
                "defaultApiVersion": null,
                "locationMappings": null,
                "locations": [
                  null
                ],
                "properties": null,
                "resourceType": "service/workspaces",
                "zoneMappings": null
              }
            ]
          }
        ],
        "provisioningState": "Succeeded",
        "templateHash": "695XX49075224066",
        "templateLink": null,
        "timestamp": "2025-11-03T15:14:01.927651+00:00",
        "validatedResources": null,
        "validationLevel": null
      },
      "resourceGroup": "kprg",
      "tags": null,
      "type": "Microsoft.Resources/deployments"
    }
    

    Deployed Workspace in Portal:image

    Hope it helps!


    Please do not forget to click "Accept the answer” and Yes, this can be beneficial to other community members.

    User's image

    If you have any other questions, let me know in the "comments" and I would be happy to help you.


    Was this answer helpful?

    0 comments No comments

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.