I am trying to run Azure HTTP Trigger Azure Function and I am receiving a 401 Unauthorized
. It was working fine for me earlier.
When I created the new function under the same Function App and copied the same code then also it is running fine but when I am trying to run my created function then I am getting the same error that I mentioned.
I'm seeing the following logs in the streaming service.
2018-07-02T07:09:41 Welcome, you are now connected to log-streaming service.
2018-07-02T07:09:48.893 [Info] Executing HTTP request: { "requestId": "53e54698-c46b-4cb6-9ed0-d042eaf9ec71", "method": "POST", "uri": "/api/Source/MPAA/false" }
2018-07-02T07:09:48.893 [Info] Executed HTTP request: { "requestId": "53e54698-c46b-4cb6-9ed0-d042eaf9ec71", "method": "POST", "uri": "/api/Source/MPAA/false", "authorizationLevel": "Anonymous", "status": "Unauthorized" }
The most common cause for Azure Functions not getting triggered is that triggers are not synced properly. You can sync triggers in one of three ways: Restart your function app in the Azure portal.
The HTTP trigger lets you invoke a function with an HTTP request. You can use an HTTP trigger to build serverless APIs and respond to webhooks. The default return value for an HTTP-triggered function is: HTTP 204 No Content with an empty body in Functions 2.
Navigate to your function app in the Azure portal, select App Keys, and then the _master key. In the Edit key section, copy the key value to your clipboard, and then select OK. After copying the _master key, select Code + Test, and then select Logs.
This is how I solved the problem based on the cause correctly provided by Nick above. Do this if you don't want to have to open the Azure Function's GUI every time you push your code.
In the source code of the function:
[FunctionName("YourFunctionName")] public static async Task<IActionResult> Run( [HttpTrigger(AuthorizationLevel.Function, "get", "post", Route = null)] HttpRequest req, ILogger log){
What I had to do was to change the default setting AuthorizationLevel.Function
into AuthorizationLevel.Anonymous
. The former only allows triggering from other Function apps, the later will let you trigger from the browser.
If you are managing your code via the azure portal, then simply navigate to "Integrate" and change the "Authorization Level" drop-down to "Anonymous".
If you are managing your code with source control integration (e.g. via git), add this to your function.json
:
"authLevel": "anonymous"
Full snippet of function.json
:
{ "bindings": [ { "name": "req", "type": "httpTrigger", "direction": "in", "methods": [ "post" ], "route": "Source/MPAA", "authLevel": "anonymous" }, { "type": "http", "name": "res", "direction": "out" } ], "disabled": false }
Note: the above is just an example, you may have to tweak the route. Note: the /api is the default prefix, and can be modified in the host.json
file.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With