https://pulumi.com logo
Title
b

billions-carpet-89629

09/20/2021, 7:22 AM
Hi to everyone. This chat is the last resort I expect to find help. After spending 2 days I cannot make work creating an API operation. When I create it using
using ApiManagement = Pulumi.AzureNative.ApiManagement.V20210101Preview;
...
var operation2 = new ApiManagement.ApiOperation($"{apiName}/send",
    new ApiManagement.ApiOperationArgs
    {
        ApiId = api.Id,
        ResourceGroupName = resourceGroup.Name,
        ServiceName = apiManagementService.Name,
        DisplayName = "send",
        Method = "GET",
        OperationId = Output.Format($"{apiManagementService.Name}/PushNotificationApi/send"),
        UrlTemplate = "/send",
        TemplateParameters = new InputList<ParameterContractArgs>(),
        Responses = new InputList<ApiManagement.Inputs.ResponseContractArgs>()
    });
It fails with an error: error: autorest/azure: error response cannot be parsed: "" error: EOF I could deploy it only via ARM Template deployment:
var operation = CreateApiOperation($"{apiName}/push",
    new ApiManagement.ApiOperationArgs
    {
        ApiId = api.Id,
        ResourceGroupName = resourceGroup.Name,
        ServiceName = apiManagementService.Name,
        DisplayName = "Push",
        Method = "GET",
        //OperationId = Output.Format($"{apiManagementService.Name}/PushNotificationApi/push"),
        UrlTemplate = "/push",
        TemplateParameters = new InputList<ParameterContractArgs>(),
        Responses = new InputList<ApiManagement.Inputs.ResponseContractArgs>()
    });

...
private Output<string> CreateApiOperation(string name, ApiManagement.ApiOperationArgs args)
{
    var deployment = new AzureNative.Resources.Deployment($"deployment",
        new AzureNative.Resources.DeploymentArgs
        {
            DeploymentName = Output.Format($"deployment_operation_{args.DisplayName}"),
            Properties = new AzureNative.Resources.Inputs.DeploymentPropertiesArgs
            {
                Mode = DeploymentMode.Incremental,
                Template = new Dictionary<string, object>()
                {
                    {
                        "$schema",
                        "<http://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#>"
                    },
                    {"contentVersion", "1.0.0.0"},
                    {"parameters", new Dictionary<string, object>()},
                    {
                        "resources", new[]
                        {
                            new Dictionary<string, object>()
                            {
                                {"type", "Microsoft.ApiManagement/service/apis/operations"},
                                {"apiVersion", "2021-01-01-preview"},
                                {"name", Output.Format($"{args.ServiceName}/{name}")},
                                {
                                    "properties", new Dictionary<string, object>()
                                    {
                                        {"displayName", args.DisplayName},
                                        {"method", args.Method},
                                        {"urlTemplate", args.UrlTemplate},
                                        {"templateParameters", args.TemplateParameters},
                                        {"responses", args.Responses}
                                    }
                                }
                            }
                        }
                    }
                },
            },
            ResourceGroupName = args.ResourceGroupName,
        });

    return null;
}
I suspect the problem is in OperationId. I tried all possible combinations. I appreciate any help. Thanks a lot.
Found the solution. The problem was in "ApiId = api.Id,". I tried "ApiId = api.Name," and that didn't work too. Eventually, I used 'ApiId = "Notificaiton"', which is an logical name of ApiManagement.Api. And this helped.
🎉 1