[FunctionName("DeleteQuestion")] public static async Task RunDelete([HttpTrigger(AuthorizationLevel.Anonymous, "put", Route = null)] HttpRequest req, ILogger log) { log.LogInformation("Editing Question:"); var content = await new StreamReader(req.Body).ReadToEndAsync(); var documentToDeleteId = JsonConvert.DeserializeObject(content); Uri collectionUri = UriFactory.CreateDocumentCollectionUri("QUIZDB", "QUIZContainer"); var feedOptions = new FeedOptions { EnableCrossPartitionQuery = true }; var docDbEndpoint = Environment.GetEnvironmentVariable("DocumentsDbEndpoint"); var docMasterKey = Environment.GetEnvironmentVariable("DocumentsKey"); using (var client = new DocumentClient(new Uri(docDbEndpoint), docMasterKey)) { var existingDocument = client.CreateDocumentQuery(collectionUri, feedOptions) if (existingDocument == null) { log.LogWarning($"Questions: {documentToDeleteId} not found."); return new BadRequestObjectResult($"Question not found."); } var documentUri = UriFactory.CreateDocumentUri("QUIZDB", "QUIZContainer", documentToDeleteId); await client.DeleteDocumentAsync(documentUri, new RequestOptions { PartitionKey = new PartitionKey(documentToDeleteId) }); } return new OkObjectResult(true); }