Azure Function for Webhook - Account ID Handling

Account ID Azure Function

Question

HOTSPOT -

You are developing an Azure Function that will be triggered using a webhook from an external application. The Azure Function will receive JSON data in the body of the request.

Calling applications send an account ID as part of the URL. The number at the end of the URL is an integer. The format for the URL resembles the following: /api/ account/1

The Azure Function must accept all incoming requests without requiring keys or tokens.

You need to complete the attributes for the Azure Function.

How should you complete the code? To answer, select the appropriate options in the answer area.

NOTE: Each correct selection is worth one point.

Hot Area:

Explanations

Explanation

To complete the attributes for the Azure Function to accept incoming requests without requiring keys or tokens, we need to define the function bindings and add the necessary attributes in the function.json file.

In this case, since the Azure Function will be triggered using a webhook from an external application and will receive JSON data in the body of the request, we need to define an HTTP trigger with a route parameter for the account ID.

To achieve this, we can add the following code to the function.json file:

json
{ "bindings": [ { "name": "req", "type": "httpTrigger", "direction": "in", "methods": [ "post" ], "route": "account/{accountId}" }, { "name": "res", "type": "http", "direction": "out" } ] }

This code defines an HTTP trigger named "req" that will accept POST requests and has a route parameter named "accountId". The route parameter will be extracted from the URL of the incoming request and passed as a parameter to the Azure Function.

The code also defines an HTTP output binding named "res" that will be used to return the response from the Azure Function.

To access the account ID parameter in the Azure Function code, we can add a parameter to the function definition with the same name as the route parameter:

csharp
public static async Task<IActionResult> Run(HttpRequest req, ILogger log, string accountId)

With this code, the accountId parameter will contain the value of the account ID passed in the URL of the incoming request.

Finally, to accept all incoming requests without requiring keys or tokens, we can remove the authorization level attribute from the function.json file:

json
{ "bindings": [ { "name": "req", "type": "httpTrigger", "direction": "in", "methods": [ "post" ], "route": "account/{accountId}" }, { "name": "res", "type": "http", "direction": "out" } ], "disabled": false }

This code sets the "disabled" attribute to false, which means that the Azure Function will accept all incoming requests without requiring any authentication.