Skip to content

Instantly share code, notes, and snippets.

@dugjason
Created April 8, 2021 17:08
Show Gist options
  • Save dugjason/228a3a5ea83f8d1f7defbf19aaf681b0 to your computer and use it in GitHub Desktop.
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
<?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