Azure PowerShell: Querying Kudu WebJobs API

Here’s how you can query the Kudu WebJobs API to get the publishing credentials for an Azure App Service which in turn you can use to in a Basic authorization header of an HTTP request to get WebJob status etc. If you are using deployment slots in your App Service, note the comment for the slight resource URI change in the request for publishing credentials.

 
Login-AzureRmAccount
 
$AppName = "my-web-app"
$ResourceGroupName = "MyResourceGroup"
$ResourceType = "Microsoft.Web/sites/config" ## with slots -> "Microsoft.Web/sites/slots/config"
$ResourceName = "$AppName/publishingcredentials" ## with slot -> "$AppName/$SlotName/publishingcredentials"
 
## Get the creds
$PublishingCredentials = Invoke-AzureRmResourceAction -ResourceGroupName $ResourceGroupName -ResourceType $ResourceType -ResourceName $ResourceName -Action List -ApiVersion 2015-08-01 -Force
 
$Username = $PublishingCredentials.properties.publishingUserName
$Password = $PublishingCredentials.properties.publishingPassword
 
#Build a basic auth header for the API request
$BasicAuthHeader = "Basic $([Convert]::ToBase64String([Text.Encoding]::ASCII.GetBytes(("{0}:{1}" -f $Username, $Password))))"
 
# Make requests for triggered and continuous web job status:
Invoke-WebRequest -uri "https://my-web-app.scm.azurewebsites.net/api/triggeredwebjobs/MyTriggeredJob" -Headers @{ Authorization = $BasicAuthHeader }
Invoke-WebRequest -uri "https://my-web-app.scm.azurewebsites.net/api/continuouswebjobs/MyContinuousJob" -Headers @{ Authorization = $BasicAuthHeader }

Hope this helps!

This entry was posted in Azure, PowerShell. Bookmark the permalink.

Leave a Reply

Your email address will not be published. Required fields are marked *