Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save dugjason/5e1bce770385fae71468ad3a097b1cfb to your computer and use it in GitHub Desktop.
Save dugjason/5e1bce770385fae71468ad3a097b1cfb to your computer and use it in GitHub Desktop.
Import a message with attachment to a channel in Front.
# Type: Python3
# Description: Import a message including an attachment to a channel in Front.
# API Endpoint Documentation: https://dev.frontapp.com/reference/post_channels-channel-id-incoming-messages
import requests
url = "https://api2.frontapp.com/channels/cha_123/incoming_messages"
# Note we need to specify nested attributes as `{parent[child]: value}` rather than `{parent: {child: value}}`
payload = {
"subject": "My message subject",
"body": "My message body",
"sender[handle]": "sender@example.com",
"sender[name]": "Sender Name",
}
file = open("image.png", "rb")
res = requests.post(url, data=payload,
headers={"Authorization": "Bearer YOUR_API_TOKEN"},
files = {"attachments": file})
if res.ok:
print("Upload completed successfully!")
print(res.text)
else:
print("Something went wrong!")
print(res.text)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment