Azure Function to enable Microsoft Graph API webhook subscriptions to Azure Automation webhooks
Hem NYHETERTECH NEWS Azure Function to enable Microsoft Graph API webhook subscriptions to Azure Automation webhooks

Azure Function to enable Microsoft Graph API webhook subscriptions to Azure Automation webhooks

Publicerat av: Redaktionen

Azure Functions is a great new, cheap and easy way to publish simple web services.

Functions can be written in multiple languages such as C#, PowerShell or even Batch! You can read more about them here:

https://azure.microsoft.com/en-us/services/functions/fireworks-7
This Azure Function is based on PowerShell and I have used it in multiple session on conferences such as MMS 2016 (was in a C# version though) and System Center Universe Europe 2016

About the function:
When using subscriptions in Microsoft Graph API, you have to Validate your webhook by returning a verification code which Graph API sends to the webhook.
Unfortunately Azure automation webhooks does not include this functionality, therefore I created this Azure Function to help validating the webhook and enable graph api webhooks for runbooks.

To create the subcscription I am using a PowerShell module which I created and published myself. You can get it here:

https://www.powershellgallery.com/packages/MicrosoftGraphAPI

It is open source, therefore you can contribute to the module at my github repo here:
https://github.com/JakobGSvendsen/MicrosoftGraphAPI
NB! Please bear in mind that PowerShell in Azure Functions is in “experimental” status, which means this shouldn’t be used in production just yet.

Here is the code for the function it self:

$requestBody = Get-Content $req -Raw | ConvertFrom-Json

#Log Request inputs & Body content
(Get-Variable REQ_* | Out-String)
($requestBody.Value | Format-List * | Out-String)

#If a validation token is present, we need to respond within 5 seconds.
if ($req_query_validationToken -ne $null)
{
    [io.file]::WriteAllText($res, $req_query_validationToken)
    return
}

#Trigger Runbook in Azure Automation
$requestBodyRaw = Get-Content $req -Raw
$Uri = "https://s2events.azure-automation.net/webhooks?token=$req_query_token"
Invoke-WebRequest -Uri $Uri  -Method Post -Body $requestBodyRaw -ContentType "application/json" -UseBasicParsing


The URI that you need to provide to graphAPI will be similar to this:
https://graphhelper.azurewebsites.net/api/PSwebhooks?code=m6tk6w9fxhx6k5986m9dfdsfdsf&token=sdsdsdsdsdsaer3434
The code is part of the GUI in azure function editor
Azure Function to enable Microsoft Graph API webhook subscriptions to Azure Automation webhooks 2
The token is the token from your Azure Automation webhook URI

Relaterade Artiklar

Vi använder cookies och andra identifierare för att förbättra din upplevelse. Detta gör att vi kan säkerställa din åtkomst, analysera ditt besök på vår webbplats. Det hjälper oss att erbjuda dig ett personligt anpassat innehåll och smidig åtkomst till användbar information. Klicka på ”Jag godkänner” för att acceptera vår användning av cookies och andra identifierare eller klicka ”Mer information” för att justera dina val. Jag Godkänner Mer Information >>

-
00:00
00:00
Update Required Flash plugin
-
00:00
00:00