1
votes

I can get a document response using HTTP trigger in FunctionsApp on Azure like a rest API However, I cannot delete the document.

I'm selecting the DELETE as Selected 'HTTP methods' but I am not clear what should I do for next step. In Input Parameters, when I write 'Delete from mydocument' in SQL Query (optional) textbox, it doesn't work. Probably I need to change the 'run.csx' code but how?

any clue?

enter image description hereenter image description hereenter image description here

1

1 Answers

2
votes

I believe the 'SQL Query' section is for the input binding for 'finding' the document that you wish to work with. This still may be useful depending how you want to proceed. You can still use a HTTP Delete trigger if you want, but merely 'saying' that its a DELETE verb doesn't automatically perform a delete. Instead, it means that you can 'invoke' the function only if you specify it as a DELETE action.

I've previous deleted documents by binding directly to the DocumentClient itself, and delete the Document programatically.

    [FunctionName("DeleteDocument")]
    public static async Task Run(
        [TimerTrigger("00:01", RunOnStartup = true)] TimerInfo timer,
        [DocumentDB] DocumentClient client,
        TraceWriter log)
    {
        var collectionUri = UriFactory.CreateDocumentCollectionUri("ItemDb", "ItemCollection");
        var documents = client.CreateDocumentQuery(collectionUri);

        foreach (Document d in documents)
        {
            await client.DeleteDocumentAsync(d.SelfLink);
        }
    }

See DocumentDBSamples