Sending messages to Facebook Workplace group through API

Create API key
Create Group
# https://gist.github.com/gislig/5dc6029447a973470fa5fcc892efe955# Here is the API key from the custom integration
$apiKey = "THE CUSTOM INTEGRATION API KEY SHOULD BE SET HERE"
# Define the header with the API key with Bearer authorization
$headers = @{"Authorization" = "Bearer " + $apiKey}
# Define the path where you can search for groups
$apiGetPath = "https://graph.facebook.com/v2.11/community/groups"
# Find the id of the Monitoring Group
$GroupName = "MonitoringGroup"
$GroupID = ((Invoke-RestMethod -Method Get -Uri $apiGetPath -Headers $headers).data | ? { $_.Name -eq $GroupName }).id# Create the message
$Message = "Greetings people of earth."
# Build the post method link with the groupid and the message
$apiPostPath = "https://graph.facebook.com/$GroupID/feed?message=$Message"
# Send the message
Invoke-RestMethod -Method Post -Uri $apiPostPath -Headers $headers
Running test on pushing data to API
# Getting event 4729, at least within the last 5 minutes, get the message(Get-EventLog -LogName Security -After (Get-Date).AddMinutes(-5) -InstanceId 4728 -ErrorAction SilentlyContinue).Message
Testing to get event from the server
Sending an event to API from the OS
# https://gist.github.com/gislig/1aa3ef669eae4a99877b3e91e1bd1bde# Here is the API key from the custom integration
$apiKey = "THE CUSTOM INTEGRATION API KEY SHOULD BE SET HERE"
# Define the header with the API key with Bearer authorization
$headers = @{"Authorization" = "Bearer " + $apiKey}
# Define the path where you can search for groups
$apiGetPath = "https://graph.facebook.com/v2.11/community/groups"
# Find the id of the Monitoring Group
$GroupName = "MonitoringGroup"
$GroupID = ((Invoke-RestMethod -Method Get -Uri $apiGetPath -Headers $headers).data | ? { $_.Name -eq $GroupName }).id# Getting event 4729, at least within the last 5 minutes, get the message
$Message = (Get-EventLog -LogName Security -After (Get-Date).AddMinutes(-5) -InstanceId 4728 -ErrorAction SilentlyContinue).Message
# Build the post method link with the groupid and the message
$apiPostPath = "https://graph.facebook.com/$GroupID/feed?message=$Message"
# Check if there is any data within the message; we don't want to send empty data.
if($Message){
# Send the message
Invoke-RestMethod -Method Post -Uri $apiPostPath -Headers $headers
}

--

--

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store