Hi amir.dadon,
Thanks for reaching out to Microsoft Q&A.
The 401 error indicates an authorization issue.
Steps to resolve the 401 error:
- Check Authentication Method: The URL
https://{function_name}.azurewebsites.net/admin/vfs/home/site/wwwroot/
is part of the Azure Kudu API (also known as SCM API), which requires either:- Basic auth: Using the Function Apps Kudu credentials (same as your App Service credentials).
- Bearer Token: You can obtain a token through Azure AD and pass it in the header as
Authorization: Bearer <token>
.
- Getting the Bearer Token: If you're using Azure AD for authentication, you can follow these steps:
- Obtain an access token for the ARM API by authenticating your app using a service principal.
- Use this token to make calls to the Kudu API.
- Ensure API Permissions: Make sure that the service principal or the managed identity has the Contributor or Function App Contributor role assigned on both the Function App and the Kudu endpoint.
Clarification on Storage Account:
Azure Functions may use a storage account for triggers or bindings (like queue, blob, or table storage), but the function code itself is typically stored within the App Service environment (accessible via the Kudu endpoint), not directly in a blob storage unless you explicitly configured it.
If you still face issues, ensure that:
- Kudu access is enabled on your Function App.
- Function App settings allow external access if required.
This should enable you to retrieve and download the files via the API.
Ensure API Permissions:
Make sure that the service principal or the managed identity has the Contributor or Function App Contributor role assigned on both the Function App and the Kudu endpoint.
This should enable you to retrieve and download the files via the API.
Please 'Upvote'(Thumbs-up) and 'Accept' as an answer if the reply was helpful. This will benefit other community members who face the same issue.