Created
August 9, 2023 15:50
-
-
Save dugjason/5e1bce770385fae71468ad3a097b1cfb to your computer and use it in GitHub Desktop.
Import a message with attachment to a channel in Front.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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