# 将 API 定义导入到 Azure API Management

将您的 API 定义导入到 Azure API Management。

* 您具有对 Azure API Management 的访问权限。
* 您已安装 Microsoft PowerShell。有关详细信息，请参阅 [Microsoft PowerShell 文档](https://docs.microsoft.com/en-us/powershell/scripting/install/installing-powershell?view=powershell-6)。
* 您已安装 Azure PowerShell 模块。有关详细信息，请参阅 [Microsoft Azure 文档](https://docs.microsoft.com/en-us/powershell/azure/install-az-ps?view=azps-2.4.0)。
* 您已导出您的 API 定义。

1. 打开命令行。
2. 为了避免在每个命令中设置上下文，您可以通过执行以下命令将其添加为变量：
   ```
   $ApiMgmtContext = New-AzApiManagementContext -ResourceGroupName "{ResourceGroupName}" -ServiceName "{ServiceName}"
   ```
   | 参数 | 描述 |
   | --- | --- |
   | {ResourceGroupName} | 与服务关联的资源组。可以在 Microsoft Azure 门户上找到它。 |
   | {ServiceName} | 服务的名称。可以在 Microsoft Azure 门户上找到它。 |
3. 输入以下命令以上传文件：
   ```
   Import-AzApiManagementApi -Context $ApiMgmtContext -SpecificationFormat "{format}" -SpecificationPath "{yourfile}" -Path "{api-url-suffix}" 
   ```
4. 添加正确的参数：
   | 参数 | 描述 |
   | --- | --- |
   | {format} | 要导入的 API 定义的格式。该值可以是：<br><br><ul><li><span>Swagger</span> （推荐）</li><li><span>Wadl</span></li><li><span>Wsdl</span></li><li><span>OpenApi</span></li></ul> |
   | {yourfile} | 您导出的 API 定义的路径和文件名。 |
   | {api-url-suffix} | 要添加到 API 公共 URL 末尾的 Web API 路径。 |

您的 API 已导入，命令行将返回有关您的 API 的信息（例如其 ID），该信息可用于更新它。您可以在 Azure 门户上检查您的 API 定义。

![Azure 门户中的 API 定义。](https://help.qlik.com/zh-CN/cloud-services/Subsystems/Hub/Content/Resources/Images/ApiDesigner/az_import.png)

有关 Import-AzApiManagementApi 命令的详细信息，请参阅 [Azure 文档](https://docs.microsoft.com/en-us/powershell/module/az.apimanagement/Import-AzApiManagementApi?view=azps-2.4.0)。