Skip to content

Instantly share code, notes, and snippets.

@gitfvb
Created December 6, 2022 14:54
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save gitfvb/c60aa0430071a0bbf8126f4b1352185e to your computer and use it in GitHub Desktop.
Save gitfvb/c60aa0430071a0bbf8126f4b1352185e to your computer and use it in GitHub Desktop.
Sending Push Notification through PowerShell and Google/Firebase Cloud messaging API
$params = [Hashtable]@{
"Uri" = "https://fcm.googleapis.com/fcm/send"
"Method" = "POST"
"ContentType" = "application/json"
"Headers" = [Hashtable]@{
"Authorization" = "key=AAAAWqJ3X..."
}
"Body" = (ConvertTo-Json -InputObject (
[PSCustomObject]@{
"data"=[PSCustomObject]@{
"title"="Hello"
"message"="World"
}
"notification" = [PSCustomObject]@{
"title" = "Breaking News"
"body" = "New news story available."
"click_action" = "HANDLE_BREAKING_NEWS"
}
"to"="f-X8-Bsg_UsNl0dxPX2dDN:..."
}))
}
#exit 0
Invoke-RestMethod @params
# For PSCore/Pwsh use the additional flag `-SkipHeaderValidation`
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment