1

I am using powershell and trying to access Azure functions Administration using api. I am trying to get list of all functions created under $appName

Certainly i am changing $appName with actual Azure Function name before call

I also got valid $authToken before this call.

Below URL:

$Functions = Invoke-RestMethod -Method GET -Headers @{Authorization = ("Bearer {0}" -f $authToken)} -Uri "https://$appName.azurewebsites.net/admin/functions"

and the error in my powershell execution is :

Invoke-RestMethod :

The underlying connection was closed: An unexpected error occurred on a send.
At KeyFA.ps1:36 char:18
+ ... Functions = Invoke-RestMethod -Method GET -Headers @{Authorization =  ...
+                 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : InvalidOperation: (System.Net.HttpWebRequest:HttpWebRequest) [Invoke-RestMethod], WebException
    + FullyQualifiedErrorId : WebCmdletWebResponseException,Microsoft.PowerShell.Commands.InvokeRestMethodCommand

I tried make it POST instead of GET but same error.

I tried access this url in broswer and the error in my broswer is :

http 401 means unauthorized.

Then i also tried access this URL from postman with Bearer auth correctly set but get below errors:

Could not get any response
There was an error connecting to 
https://appname_comes_here.azurewebsites.net/admin/functions/

What am i not doing correctly?

Not able to fix this error. Is the url discontinued by Azure function site now?

Daniel Mann
  • 57,011
  • 13
  • 100
  • 120
knowdotnet
  • 839
  • 1
  • 15
  • 29
  • have a look at https://learn.microsoft.com/en-us/rest/api/appservice/webapps/listfunctions for List Functions – Roman Kiss Feb 23 '19 at 17:19
  • @Roman Kiss: same error as before "The underlying connection was closed: An unexpected error ......" as mentioned above also.. – knowdotnet Feb 23 '19 at 18:38
  • Go to the https://learn.microsoft.com/en-us/rest/api/appservice/webapps/get, click on the Try it button and type your resource group name and name of the FunctionApp. You should get the details of your FunctionApp. – Roman Kiss Feb 24 '19 at 07:12
  • or you can check the List of all FunctionApps, see https://learn.microsoft.com/en-us/rest/api/appservice/webapps/list, click button Try it and then Run. If you have no problem with a connectivity, than the response is list of all your FucntionApps for a specific subscriptionId. – Roman Kiss Feb 24 '19 at 07:22

1 Answers1

1

Due to you just post the partial PowerShell code and the error information seems to be a network issue, I don't know what real issue you got is and how to fix it.

So I just post my work PowerShell script at here, you can refer to my code to fix your issue.

$appName = "<your app name>"
$userName='<your app credential user name>'
$userPWD='<your app credential user password>'

$apiBaseUrl = "https://$($appName).scm.azurewebsites.net/api"
$appBaseUrl = "https://$($appName).azurewebsites.net"

$base64AuthInfo = [Convert]::ToBase64String([Text.Encoding]::ASCII.GetBytes(("{0}:{1}" -f $userName,$userPWD)))

$jwt = Invoke-RestMethod -Uri "$apiBaseUrl/functions/admin/token" -Headers @{Authorization=("Basic {0}" -f $base64AuthInfo)} -Method GET

$Functions = Invoke-RestMethod -Method GET -Headers @{Authorization = ("Bearer {0}" -f $jwt)} -Uri "$appBaseUrl/admin/functions"

Note: you can follow the figures below to get the $userName and $userPWD values.

Fig 1. On Azure portal, open the Platform features tab of your Function App and click the Deployment Center link

enter image description here

Fig 2. Select the FTP option in the first step of SOURCE CONTROL and click the Dashboard button to copy the values of Username and Password, but just use the part of Username with $ prefix as $userName in my script

enter image description here

Peter Pan
  • 23,476
  • 4
  • 25
  • 43
  • @knowdotnet Any update or concern? If it helps, may you mark it? – Peter Pan Mar 11 '19 at 05:42
  • 1
    Cross-linking similar issues https://stackoverflow.com/questions/50246239/how-to-create-a-azure-function-function-key-when-your-functions-are-set-to-read – Jari Turkia Apr 05 '19 at 11:57