Azure Websites Kudu REST API - Authentication Azure Websites Kudu REST API - Authentication powershell powershell

Azure Websites Kudu REST API - Authentication


You can first get the website via Powershell and then use the publish credentials from the website to call the Kudu REST API. The example below will get the Kudu version.

$website = Get-AzureWebsite -Name "WebsiteName"$username = $website.PublishingUsername$password = $website.PublishingPassword$base64AuthInfo = [Convert]::ToBase64String([Text.Encoding]::ASCII.GetBytes(("{0}:{1}" -f $username,$password)))$apiBaseUrl = "https://$($website.Name).scm.azurewebsites.net/api"$kuduVersion = Invoke-RestMethod -Uri "$apiBaseUrl/environment" -Headers @{Authorization=("Basic {0}" -f $base64AuthInfo)} -Method GET


In the new ARM world and with the latest PowerShell, you'll need to make some adjustments to @Seth's answer.

Specifically, the way you obtain the publishing creds is different, which is the first 3 lines. The rest I shamelessly copied from @Seth to complete the snippet.

Make sure to replace YourResourceGroup/YourWebApp as appropriate:

$creds = Invoke-AzureRmResourceAction -ResourceGroupName YourResourceGroup -ResourceType Microsoft.Web/sites/config -ResourceName YourWebApp/publishingcredentials -Action list -ApiVersion 2015-08-01 -Force$username = $creds.Properties.PublishingUserName$password = $creds.Properties.PublishingPassword$base64AuthInfo = [Convert]::ToBase64String([Text.Encoding]::ASCII.GetBytes(("{0}:{1}" -f $username,$password)))$apiBaseUrl = "https://$($website.Name).scm.azurewebsites.net/api"$kuduVersion = Invoke-RestMethod -Uri "$apiBaseUrl/environment" -Headers @{Authorization=("Basic {0}" -f $base64AuthInfo)} -Method GET