public async Task <HttpResponseMessage> Run([HttpTrigger(AuthorizationLevel.Anonymous, "post", Route = "Customers/{customerId}/Subscriptions")] HttpRequest req, ILogger log, string customerId) { var touchpointId = _httpRequestHelper.GetDssTouchpointId(req); if (string.IsNullOrEmpty(touchpointId)) { log.LogInformation("Unable to locate 'TouchpointId' in request header"); return(_httpResponseMessageHelper.BadRequest()); } log.LogInformation("C# HTTP trigger function processed a request. By Touchpoint " + touchpointId); if (!Guid.TryParse(customerId, out var customerGuid)) { return(_httpResponseMessageHelper.BadRequest(customerGuid)); } Models.Subscriptions subscriptionsRequest; try { subscriptionsRequest = await _httpRequestHelper.GetResourceFromRequest <Models.Subscriptions>(req); } catch (JsonSerializationException ex) { return(_httpResponseMessageHelper.UnprocessableEntity(ex)); } if (subscriptionsRequest == null) { return(_httpResponseMessageHelper.UnprocessableEntity(req)); } subscriptionsRequest.SetIds(customerGuid, touchpointId); var errors = _validate.ValidateResource(subscriptionsRequest); if (errors != null && errors.Any()) { return(_httpResponseMessageHelper.UnprocessableEntity(errors)); } var doesCustomerExist = await _resourceHelper.DoesCustomerExist(customerGuid); if (!doesCustomerExist) { return(_httpResponseMessageHelper.NoContent(customerGuid)); } var doesSubscriptionExist = await _resourceHelper.DoesSubscriptionExist(customerGuid, touchpointId); if (doesSubscriptionExist.HasValue) { var duplicateError = _validate.ValidateResultForDuplicateSubscriptionId(doesSubscriptionExist.GetValueOrDefault()); return(_httpResponseMessageHelper.Conflict()); } var subscriptions = await _subscriptionsPostService.CreateAsync(subscriptionsRequest); return(subscriptions == null ? _httpResponseMessageHelper.BadRequest(customerGuid) : _httpResponseMessageHelper.Created(JsonHelper.SerializeObject(subscriptions))); }