|
| 1 | +--- |
| 2 | +title: Enable Azure API Center data view - Visual Studio Code extension |
| 3 | +description: Enable developers to view API data including API definitions using the Visual Studio Code Extension for Azure API Center. |
| 4 | +author: dlepow |
| 5 | +ms.service: azure-api-center |
| 6 | +ms.topic: how-to |
| 7 | +ms.date: 09/10/2024 |
| 8 | +ms.author: danlep |
| 9 | +ms.custom: |
| 10 | +# Customer intent: As an API program manager, I want to enable an extension in Visual Studio Code so that developers in my organization to discover the APIs in my organization's API center without access to Azure to manage the API center. |
| 11 | +--- |
| 12 | + |
| 13 | +# Enable access to Azure API Center data - Visual Studio Code extension |
| 14 | + |
| 15 | +This article shows how to enable access to the API Center data view (preview) in the Visual Studio Code extension for [Azure API Center](overview.md). Using the data view, developers can discover APIs in your Azure API center, view API definitions, and optionally generate API clients when they don't have access to manage the API center itself. Access to the data view is managed using Microsoft Entra ID and Azure role-based access control. |
| 16 | + |
| 17 | +## Prerequisites |
| 18 | + |
| 19 | +* An API center in your Azure subscription. If you haven't created one already, see [Quickstart: Create your API center](set-up-api-center.md). |
| 20 | + |
| 21 | +* Permissions to create an app registration in a Microsoft Entra tenant associated with your Azure subscription, and permissions to grant access to data in your API center. |
| 22 | + |
| 23 | +* [Azure API Center extension for Visual Studio Code](https://marketplace.visualstudio.com/items?itemName=apidev.azure-api-center) |
| 24 | + |
| 25 | + > [!NOTE] |
| 26 | + > Currently, access to the API Center data view is available only in the extension's pre-release version. When installing the extension from the [Visual Studio Code Marketplace](https://marketplace.visualstudio.com/items?itemName=apidev.azure-api-center&ssr=false#overview), you can choose to install the release version or a pre-release version. Switch between the two versions at any time by using the extension's **Manage** button context menu in the Extensions view. |
| 27 | +
|
| 28 | +The following Visual Studio Code extension is optional: |
| 29 | + |
| 30 | +* [Microsoft Kiota extension](https://marketplace.visualstudio.com/items?itemName=ms-graph.kiota) - to generate API clients |
| 31 | + |
| 32 | +## Create Microsoft Entra app registration |
| 33 | + |
| 34 | +First, configure an app registration in your Microsoft Entra ID tenant. The app registration enables the Visual Studio Code extension for Azure API Center to access data from your API center on behalf of a signed-in user. |
| 35 | + |
| 36 | +1. In the [Azure portal](https://portal.azure.com), navigate to **Microsoft Entra ID** > **App registrations**. |
| 37 | +1. Select **+ New registration**. |
| 38 | +1. On the **Register an application** page, set the values as follows: |
| 39 | + |
| 40 | + * Set **Name** to a meaningful name such as *api-center-data* |
| 41 | + * Under **Supported account types**, select **Accounts in this organizational directory (Single tenant)**. |
| 42 | + * In **Redirect URI**, select **Single-page application (SPA)** and set the URI to the runtime URI of your API center. For example, `https://<service name>.data.<region>.azure-apicenter.ms`. |
| 43 | + * Select **Register**. |
| 44 | + |
| 45 | + > [!TIP] |
| 46 | + > You can use the same app registration for access to more API centers. In **Redirect URI**, continue to add redirect URIs for other API centers that you want to appear in the data view. |
| 47 | +1. On the **Overview** page, copy the **Application (client) ID** and the **Directory (tenant) ID**. You set these values later when you connect to the API center from the Visual Studio Code extension. |
| 48 | +1. In the left menu, under **Manage**, select **Authentication** > **+ Add a platform**. |
| 49 | +1. On the **Configure platforms** page, select **Mobile and desktop applications**. |
| 50 | +1. On the **Configure Desktop + devices** page, enter the following redirect URI and select **Configure**: |
| 51 | + |
| 52 | + `https://vscode.dev/redirect` |
| 53 | + |
| 54 | +1. In the left menu, under **Manage**, select **API permissions** > **+ Add a permission**. |
| 55 | +1. On the **Request API permissions** page, do the following: |
| 56 | + 1. Select the **APIs my organization uses** tab. |
| 57 | + 1. Search for and select **Azure API Center**. You can also search for and select application ID `c3ca1a77-7a87-4dba-b8f8-eea115ae4573`. |
| 58 | + 1. In **Select permissions** page, select **user_impersonation**. |
| 59 | + 1. Select **Add permissions**. |
| 60 | + |
| 61 | + The Azure API Center permissions appear under **Configured permissions**. |
| 62 | + |
| 63 | + :::image type="content" source="media/enable-data-view-vscode-extensions/configure-app-permissions.png" alt-text="Screenshot of required permissions in Microsoft Entra ID app registration in the portal." ::: |
| 64 | + |
| 65 | +## Enable sign-in to data view by Microsoft Entra users and groups |
| 66 | + |
| 67 | +Users must sign in to see the data view for your API center. To enable sign-in, assign the **Azure API Center Data Reader** role to users or groups in your organization, scoped to your API center. |
| 68 | + |
| 69 | +> [!IMPORTANT] |
| 70 | +> By default, you and other administrators of the API center don't have access to APIs in the API Center extension's data view. Be sure to assign the **Azure API Center Data Reader** role to yourself and other administrators. |
| 71 | +
|
| 72 | +For detailed prerequisites and steps to assign a role to users and groups, see [Assign Azure roles using the Azure portal](../role-based-access-control/role-assignments-portal.yml). Brief steps follow: |
| 73 | + |
| 74 | +1. In the [Azure portal](https://portal.azure.com), navigate to your API center. |
| 75 | +1. In the left menu, select **Access control (IAM)** > **+ Add role assignment**. |
| 76 | +1. In the **Add role assignment** pane, set the values as follows: |
| 77 | + * On the **Role** page, search for and select **Azure API Center Data Reader**. Select **Next**. |
| 78 | + * On the **Members** page, In **Assign access to**, select **User, group, or service principal** > **+ Select members**. |
| 79 | + * On the **Select members** page, search for and select the users or groups to assign the role to. Click **Select** and then **Next**. |
| 80 | + * Review the role assignment, and select **Review + assign**. |
| 81 | +1. Repeat the preceding steps to enable sign-in to the data view for more API centers. |
| 82 | + |
| 83 | +> [!NOTE] |
| 84 | +> To streamline access configuration for new users, we recommend that you assign the role to a Microsoft Entra group and configure a dynamic group membership rule. To learn more, see [Create or update a dynamic group in Microsoft Entra ID](/entra/identity/users/groups-create-rule). |
| 85 | +
|
| 86 | +## Connect to an API center |
| 87 | + |
| 88 | +Developers can follow these steps to connect to an API center from the Visual Studio code extension and sign in to view the APIs. |
| 89 | + |
| 90 | +1. In Visual Studio Code, in the Activity Bar on the left, select API Center. |
| 91 | +1. Use the **Ctrl+Shift+P** keyboard shortcut to open the Command Palette. Type **Azure API Center: Connect to an API Center** and hit **Enter**. |
| 92 | +1. Answer the prompts to input the following information: |
| 93 | + 1. The runtime URL of your API center. Example: `<service name>.data.<region>.azure-apicenter.ms` |
| 94 | + 1. The application (client) ID from the app registration configured in the previous section. |
| 95 | + 1. The directory (tenant) ID from the app registration configured in the previous section. |
| 96 | + |
| 97 | + > [!TIP] |
| 98 | + > An API center administrator needs to provide the connection settings to developers, or provide a direct link for developers to access an API center's data view. The link is in the following format: |
| 99 | + > `vscode://apidev.azure-api-center?clientId=<Client ID>&tenantId=<tenant ID>&runtimeUrl=<service-name>.data.<region>.azure-apicenter.ms` |
| 100 | +
|
| 101 | + After you connect to the API center, the API center appears in the API Center data view. |
| 102 | + |
| 103 | +1. To view the APIs in the API center, select **Sign in to Azure**. Sign in with a Microsoft account that is assigned the **Azure API Center Data Reader** role in the API center. |
| 104 | + |
| 105 | + :::image type="content" source="media/enable-data-view-vscode-extension/api-center-pane-initial.png" alt-text="Screenshot of API Center Data View in VS Code extension." ::: |
| 106 | + |
| 107 | +1. After signing in, select **APIs** to list the APIs in the API center. Expand an API to explore its versions and definitions. |
| 108 | + |
| 109 | + :::image type="content" source="media/enable-data-view-vscode-extension/api-center-pane-apis.png" alt-text="Screenshot of API Center Data View with APIs in VS Code extension." ::: |
| 110 | +1. Repeat the preceding steps to connect to more API centers for which you have access. |
| 111 | + |
| 112 | +## Discover and consume APIs |
| 113 | + |
| 114 | +The Azure API Center data view helps developers discover API details and start API client development. Right-click on an API definition in the data view to access these features: |
| 115 | + |
| 116 | +* **Export API specification document** - Export an API specification from a definition and then download it as a file |
| 117 | +* **Generate API client** - Use the Microsoft Kiota extension to generate an API client for their favorite language |
| 118 | +* **Generate Markdown** - Generate API documentation in Markdown format |
| 119 | +* **OpenAPI documentation** - View the documentation for an API definition and try operations in a Swagger UI (only available for OpenAPI definitions) |
| 120 | + |
| 121 | + |
| 122 | +## Troubleshooting |
| 123 | + |
| 124 | +### Error: Cannot read properties of undefined (reading 'nextLink') |
| 125 | + |
| 126 | +Under certain conditions, a user might encounter the following error message after signing into the API Center data view and expanding the APIs list for an API center: |
| 127 | + |
| 128 | +`Error: Cannot read properties of undefined (reading 'nextLink')` |
| 129 | +` |
| 130 | + |
| 131 | +Check that the user is assigned the **Azure API Center Data Reader** role in the API center. If necessary, reassign the role to the user. Then, refresh the API Center data view in the Visual Studio Code extension. |
| 132 | + |
| 133 | +### Unable to sign in to Azure |
| 134 | + |
| 135 | +If users who have been assigned the **Azure API Center Data Reader** role can't complete the sign-in flow after selecting **Sign in to Azure** in the data view, there might be a problem with the configuration of the connection. |
| 136 | + |
| 137 | +Check the settings in the app registration you configured in Microsoft Entra ID. Confirm the values of the application (client) ID and the directory (tenant) ID in the app registration and the runtime URL of the API center. Then, set up the connection to the API center again. |
| 138 | + |
| 139 | +### Unable to select Azure API Center permissions in Microsoft Entra ID app registration |
| 140 | + |
| 141 | +If you're unable to request API permissions to Azure API Center in your Microsoft Entra app registration for the API Center portal, check that you are searching for **Azure API Center** (or application ID `c3ca1a77-7a87-4dba-b8f8-eea115ae4573`). |
| 142 | + |
| 143 | +If the app isn't present, there might be a problem with the registration of the **Microsoft.ApiCenter** resource provider in your subscription. You might need to re-register the resource provider. To do this, run the following command in the Azure CLI: |
| 144 | + |
| 145 | +```azurecli |
| 146 | +az provider register --namespace Microsoft.ApiCenter |
| 147 | +``` |
| 148 | + |
| 149 | +After re-registering the resource provider, try again to request API permissions. |
| 150 | + |
| 151 | + |
| 152 | +## Related content |
| 153 | + |
| 154 | +* [Get started with the Azure API Center extension for Visual Studio Code](use-vscode-extension.md) |
| 155 | +* [Best practices for Azure RBAC](../role-based-access-control/best-practices.md) |
| 156 | +* [Register a resource provider](../azure-resource-manager/management/resource-providers-and-types.md#register-resource-provider) |
0 commit comments