I am trying to migrate an apim instance programatically using azure powershell (I can't use Backup/restore in my case). I am succesfully getting apis, revisions, policies, schemas, etc... But when I try to create operations with requests, responses, etc, I keep getting this error :
Error Code: ValidationError
Error Message: One or more fields contain incorrect values:
Request Id: xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx
Error Details:
[Code= ValidationError, Message= Operation references schema that does not exist.,
Target= operation 'GET'-'/contract/{contract_id}' response '200' 'application/json'
representation schema xxxxxxxxxxxxxxxxxxxxxxxx]
Basically, I get operations and schema from the old apim and insert first the schema, then iterating over operations, recreate them 1by1.
$Operations = Get-AzApiManagementOperation -Context $apimSourceContext -ApiId $API.ApiId
$Schema = Get-AzApiManagementApiSchema -Context $apimSourceContext -ApiId $API.ApiId
if ($Schema) {
New-AzApiManagementApiSchema -Context $apimTargetContext -ApiId $FullApiId -SchemaDocumentContentType $Schema.SchemaDocumentContentType -SchemaDocument $Schema.SchemaDocument
}
foreach ($Operation in $Operations) {
New-AzApiManagementOperation -Context $apimTargetContext -ApiId $FullApiId -ApiRevision $API.ApiRevision -Name $Operation.Name -OperationId $Operation.Name -Method $Operation.Method -Description $Operation.Description -UrlTemplate $Operation.UrlTemplate -TemplateParameters $Operation.TemplateParameters -Responses $Operation.Responses -Request $Operation.Request -Verbose -Debug
}
From what I see in the portal, schema is created succesfully, and seems in every point identical than in the source APIM