Skip to content

Instantly share code, notes, and snippets.

@pratapprashant
Created October 15, 2017 23:07
Show Gist options
  • Save pratapprashant/4540d9b2dd26fdfb323b72ebca92da3c to your computer and use it in GitHub Desktop.
Save pratapprashant/4540d9b2dd26fdfb323b72ebca92da3c to your computer and use it in GitHub Desktop.
Calling AI APIs from Azure FunctionApp (PowerShell)
# POST method: $req
$requestBody = Get-Content $req -Raw | ConvertFrom-Json
$name = $requestBody.name
$instrumentationKey = "<ai key>"
$aiClient = New-Object "Microsoft.ApplicationInsights.TelemetryClient"
$aiClient.InstrumentationKey = $instrumentationKey
$aiClient.TrackPageView("my pageview")
#$aiClient.TrackEvent("my event")
$aiClient.TrackTrace("my trace")
$aiClient.TrackMetric("my metric", 20.0)
$now = Get-Date
$aiClient.TrackDependency("my dependency", "my call", $now, 10, 1)
$aiClient.Flush()
# GET method: each querystring parameter is its own variable
if ($req_query_name)
{
$name = $req_query_name
}
Out-File -Encoding Ascii -FilePath $res -inputObject "Hello $name"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment