In my previous post I showed how to get status of triggered Azure web job via web jobs REST API in PowerShell (see Get status of timer triggered Azure web job via REST API in PowerShell). In this post I will show how to trigger web job programmatically also via REST API.
For triggering web job via REST API we need to send HTTP POST request to the following endpoint:
https://{webAppName}.scm.azurewebsites.net/api/triggeredwebjobs/{webJobName}/run
PowerShell method which triggers web job looks like that:
function Run-Web-Job { param ( $webAppName, $webJobName ) $token = Get-AzAccessToken $headers = @{ "Authorization" = "Bearer $($token.Token)" } $userAgent = "powershell/1.0" Invoke-RestMethod -Uri "https://$($webAppName).scm.azurewebsites.net/api/triggeredwebjobs/$($webJobName)/run" -Headers $headers -UserAgent $userAgent -Method POST }
Here we first get access token via Get-AzAccessToken cmdlet and sent POST request with received bearer token. As result it will trigger specified web job to run now.
No comments:
Post a Comment