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
}

--

--

--

IT tech geek, developer etc.

Love podcasts or audiobooks? Learn on the go with our new app.

Recommended from Medium

Kruskal’s Algorithm

Getting Started With Mobile Development

The Truth On Trumps Recent Firing Of My Father

Weekly Digest #51

In-depth Java Course: The Ultimate Java Engineering Class

Codility Algorithm Practice Lesson 12: Euclidean Algorithm, Task 2: Common Prime Divisors — a…

Pyramid

How to publish your blog posts from Strapi to Multiple Platforms — Dev.to, Hashnode, and Medium

Cinemachine: Security Camera using Blend List Camera

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
Gisli Gudmundsson

Gisli Gudmundsson

IT tech geek, developer etc.

More from Medium

IaaS, PaaS, SaaS: Cloud Computing Models for E-commerce with Examples

NetSuite Map/Reduce Scripts in Retail Practices

Amazon Style, Amazon’s new venture into retail stores

Gain a ‘helicopter’ view of enterprise risk with risk management software