private string CreateOrUpdateApi(string apiName, string route, string serviceUrl)
        {
            var existingApi = GetApiByName(apiName);
            var apiId       = (existingApi != null) ? existingApi.Id : Guid.NewGuid().ToString();

            if (existingApi != null)
            {
                Log.Info($"Updating existing Api {existingApi.Id}");
            }

            var apiCreateOrUpdateParams = new ApiCreateOrUpdateParameters
            {
                ApiContract = new ApiContract
                {
                    Name        = apiName,
                    Description = $"Description: {apiName}",
                    Path        = route,
                    ServiceUrl  = serviceUrl,
                    Type        = ApiTypeContract.Http,
                    Protocols   = new List <ApiProtocolContract>
                    {
                        ApiProtocolContract.Https
                    }
                }
            };

            using (var mc = new ApiManagementClient(SubscriptionCloudCredentials))
            {
                mc.Apis.CreateOrUpdate(ApiManagementResGrpName, ApiManagementName, apiId, apiCreateOrUpdateParams, string.Empty);
            }

            Log.Info($"Successfully Created or Updated Api {apiName} Id: {apiId}");
            return(apiId);
        }
Example #2
0
 /// <summary>
 /// Creates new or updates existing specific API of the Api Management
 /// service instance.
 /// </summary>
 /// <param name='operations'>
 /// Reference to the
 /// Microsoft.Azure.Management.ApiManagement.IApisOperations.
 /// </param>
 /// <param name='resourceGroupName'>
 /// Required. The name of the resource group.
 /// </param>
 /// <param name='serviceName'>
 /// Required. The name of the Api Management service.
 /// </param>
 /// <param name='aid'>
 /// Required. Identifier of the API.
 /// </param>
 /// <param name='parameters'>
 /// Required. Create or update parameters.
 /// </param>
 /// <param name='etag'>
 /// Optional. ETag.
 /// </param>
 /// <returns>
 /// A standard service response including an HTTP status code and
 /// request ID.
 /// </returns>
 public static AzureOperationResponse CreateOrUpdate(this IApisOperations operations, string resourceGroupName, string serviceName, string aid, ApiCreateOrUpdateParameters parameters, string etag)
 {
     return(Task.Factory.StartNew((object s) =>
     {
         return ((IApisOperations)s).CreateOrUpdateAsync(resourceGroupName, serviceName, aid, parameters, etag);
     }
                                  , operations, CancellationToken.None, TaskCreationOptions.None, TaskScheduler.Default).Unwrap().GetAwaiter().GetResult());
 }
Example #3
0
 /// <summary>
 /// Creates new or updates existing specific API of the Api Management
 /// service instance.
 /// </summary>
 /// <param name='operations'>
 /// Reference to the
 /// Microsoft.Azure.Management.ApiManagement.IApisOperations.
 /// </param>
 /// <param name='resourceGroupName'>
 /// Required. The name of the resource group.
 /// </param>
 /// <param name='serviceName'>
 /// Required. The name of the Api Management service.
 /// </param>
 /// <param name='aid'>
 /// Required. Identifier of the API.
 /// </param>
 /// <param name='parameters'>
 /// Required. Create or update parameters.
 /// </param>
 /// <param name='etag'>
 /// Optional. ETag.
 /// </param>
 /// <returns>
 /// A standard service response including an HTTP status code and
 /// request ID.
 /// </returns>
 public static Task <AzureOperationResponse> CreateOrUpdateAsync(this IApisOperations operations, string resourceGroupName, string serviceName, string aid, ApiCreateOrUpdateParameters parameters, string etag)
 {
     return(operations.CreateOrUpdateAsync(resourceGroupName, serviceName, aid, parameters, etag, CancellationToken.None));
 }