Azure REST API return 200 code with an empty response in Deployed azure function.
{
"value": []
}
I am trying to get all resources from Azure API, API return all resources when debugging from local, But getting empty response when calling from Deployed Azure function. In one of post I got answer, where should I add Azure function identity to get all the resources?
In your local machine, Azure Function is using DefaultAzureCredentials from Azure CLI or your local terminal log in thus you can get Azure Resources list when you call the API locally but not in Azure Function app.
In order to authenticate with your Function App in portal and get the results you can make use of ClientCredentials authentication with Azure service principal having Contributor role assigned at the Subscription level.
I used the below code from this SO answer by Vinny and John and this Rest API in my Function1.cs to get all the resources with ClientCredentials flow via Azure Function:-
Output:-
Local:-
I deployed the Function to my Azure Portal and received the same output:-