# 在 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 定义。
* 您已将 API 定义的早期版本上传到 Azure API Management。
* 您已将上下文参数设置为变量。有关详细信息，请参阅上述过程。

1. 打开命令行并输入以下命令以上传文件：
   ```
   Import-AzApiManagementApi -Context $ApiMgmtContext -SpecificationFormat "{format}" -SpecificationPath "{yourfile}" -ApiId "{api-id}" -Path "{api-url-suffix}"
   ```
2. 添加正确的参数：
   | 参数 | 描述 |
   | --- | --- |
   | {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-id} | 要更新的 API 的 Azure API Management ID。 |
   | {api-url-suffix} | 要添加到 API 公共 URL 末尾的 Web API 路径。 |
3. 执行该命令。

您的 API 定义已导入，新文件将替换以前的版本。您可以在 Azure 门户上检查您的更新。

在此示例中，上传了名为 Contacts API 的 API 定义的第一个版本，其中包含五个操作。然后，它被替换为名为 Contacts API V2 的新定义，其中包含十个操作。

![更新后的 API 定义的屏幕截图。](https://help.qlik.com/zh-CN/cloud-services/Subsystems/Hub/Content/Resources/Images/ApiDesigner/az_update.png)

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