Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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