Created
April 8, 2021 17:08
-
-
Save dugjason/228a3a5ea83f8d1f7defbf19aaf681b0 to your computer and use it in GitHub Desktop.
Front API: Basic PHP example of sending a message with an attachment using Front's API
This file contains hidden or 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
<?php | |
require './../vendor/autoload.php'; | |
use GuzzleHttp\Client; | |
$client = new Client([ | |
'base_uri' => 'https://api2.frontapp.com/', | |
'headers' => [ | |
'Authorization' => 'Bearer [FRONT_API_TOKEN]', | |
'Content-Type' => 'multipart/form-data', | |
'Accept' => 'application/json' | |
] | |
]); | |
// Uses Front's POST /channels/:channel_id/messages endpoint to send a message with an attachment | |
// https://dev.frontapp.com/reference/messages-1#post_channels-channel-id-messages | |
$res = $client->request('POST', 'channels/[FRONT_CHANNEL_ID]/messages', [ | |
'multipart' => [ | |
[ | |
'name' => 'attachments[0]', | |
'contents' => file_get_contents('image.png'), | |
'filename' => 'image.png' | |
], | |
[ | |
'name' => 'to[0]', | |
'contents' => '[email protected]' | |
], | |
[ | |
'name' => 'subject', | |
'contents' => 'Message subject' | |
], | |
[ | |
'name' => 'author_id', | |
'contents' => '[FRONT_TEAMMATE_ID]' | |
], | |
[ | |
'name' => 'body', | |
'contents' => 'Message body' | |
] | |
], | |
]); | |
print_r($res) | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment