Posting messages to Salesforce’s Chatter

simple_salesforce allows us to do it

API simple_salesforce allows us to access Salesforce. And we can use it to post a message to Salesforce’s Chatter.

from simple_salesforce import Salesforce
import requests
import pandas as pd
import csv
import requests
from io import StringIO
import getpass
import json
import datetime

Then access to Salesforce is provided by username, password, and security token. (We can access Salesforce using username, password, and organizationId as well.)

sf0=Salesforce(username=USERNAME, password=PASSWORD, security_token=SECURITY_TOKEN)

Then, we use restful method and json to post a message to Chatter.

message_a="Awesome! A message was posted at " +'%Y-%m-%d %H:%M:%S')
body0 = { "body":
{"messageSegments": [
{"type": "Text", "text": message_a},
{"type": "Mention", "id": user_id}
"feedElementType": "FeedItem", "subjectId": "me"
zz_rest0=sf0.restful(r'chatter/feed-elements/', method='POST', data=json.dumps(body0))

Here user_id is the id of the user whom we send a message.