Create a Chat Message
curl --request POST \
--url https://api.affinity.co/v2/chat-messages \
--header 'Authorization: Bearer <token>' \
--header 'Content-Type: application/json' \
--data '
{
"sentAt": "2023-01-01T00:00:00Z",
"direction": "sent",
"participants": [
{
"id": 1
},
{
"id": 2
}
]
}
'import requests
url = "https://api.affinity.co/v2/chat-messages"
payload = {
"sentAt": "2023-01-01T00:00:00Z",
"direction": "sent",
"participants": [{ "id": 1 }, { "id": 2 }]
}
headers = {
"Authorization": "Bearer <token>",
"Content-Type": "application/json"
}
response = requests.post(url, json=payload, headers=headers)
print(response.text)const options = {
method: 'POST',
headers: {Authorization: 'Bearer <token>', 'Content-Type': 'application/json'},
body: JSON.stringify({
sentAt: '2023-01-01T00:00:00Z',
direction: 'sent',
participants: [{id: 1}, {id: 2}]
})
};
fetch('https://api.affinity.co/v2/chat-messages', options)
.then(res => res.json())
.then(res => console.log(res))
.catch(err => console.error(err));<?php
$curl = curl_init();
curl_setopt_array($curl, [
CURLOPT_URL => "https://api.affinity.co/v2/chat-messages",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "POST",
CURLOPT_POSTFIELDS => json_encode([
'sentAt' => '2023-01-01T00:00:00Z',
'direction' => 'sent',
'participants' => [
[
'id' => 1
],
[
'id' => 2
]
]
]),
CURLOPT_HTTPHEADER => [
"Authorization: Bearer <token>",
"Content-Type: application/json"
],
]);
$response = curl_exec($curl);
$err = curl_error($curl);
curl_close($curl);
if ($err) {
echo "cURL Error #:" . $err;
} else {
echo $response;
}package main
import (
"fmt"
"strings"
"net/http"
"io"
)
func main() {
url := "https://api.affinity.co/v2/chat-messages"
payload := strings.NewReader("{\n \"sentAt\": \"2023-01-01T00:00:00Z\",\n \"direction\": \"sent\",\n \"participants\": [\n {\n \"id\": 1\n },\n {\n \"id\": 2\n }\n ]\n}")
req, _ := http.NewRequest("POST", url, payload)
req.Header.Add("Authorization", "Bearer <token>")
req.Header.Add("Content-Type", "application/json")
res, _ := http.DefaultClient.Do(req)
defer res.Body.Close()
body, _ := io.ReadAll(res.Body)
fmt.Println(string(body))
}HttpResponse<String> response = Unirest.post("https://api.affinity.co/v2/chat-messages")
.header("Authorization", "Bearer <token>")
.header("Content-Type", "application/json")
.body("{\n \"sentAt\": \"2023-01-01T00:00:00Z\",\n \"direction\": \"sent\",\n \"participants\": [\n {\n \"id\": 1\n },\n {\n \"id\": 2\n }\n ]\n}")
.asString();require 'uri'
require 'net/http'
url = URI("https://api.affinity.co/v2/chat-messages")
http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true
request = Net::HTTP::Post.new(url)
request["Authorization"] = 'Bearer <token>'
request["Content-Type"] = 'application/json'
request.body = "{\n \"sentAt\": \"2023-01-01T00:00:00Z\",\n \"direction\": \"sent\",\n \"participants\": [\n {\n \"id\": 1\n },\n {\n \"id\": 2\n }\n ]\n}"
response = http.request(request)
puts response.read_body{
"id": 1,
"sentAt": "2023-01-01T00:00:00Z",
"loggingType": "manual",
"direction": "sent",
"creator": {
"id": 1,
"firstName": "Jane",
"lastName": "Doe",
"primaryEmailAddress": "jane.smith@northpointvc.com",
"type": "internal"
},
"createdAt": "2022-01-01T00:00:00Z",
"updatedAt": "2023-01-01T00:00:00Z",
"participantsPreview": {
"data": [
{
"id": 1,
"firstName": "Jane",
"lastName": "Doe",
"primaryEmailAddress": "jane.smith@northpointvc.com",
"type": "internal"
}
],
"totalCount": 200
}
}{
"errors": [
{
"code": "bad-request",
"message": "<string>"
}
]
}{
"errors": [
{
"code": "not-found",
"message": "<string>"
}
]
}{
"errors": [
{
"code": "authentication",
"message": "<string>"
}
]
}Chat Messages
Create a Chat Message
| ⚠️ This endpoint is currently in BETA |
|---|
Creates a chat message logged as a manual interaction. The calling user is recorded as the message’s creator; this cannot be set explicitly.
participants must name at least one internal and one external Person, and must not name the
same Person twice. A Person that Affinity infers to be a colleague does not count as external.
A Person that anyone in your organization has hidden cannot be a participant, and returns 400.
sentAt cannot be in the future.
The chat message’s visibility follows your organization’s default sharing setting.
This endpoint does not take the message text. To add it, make a second call to
POST /v2/notes with the id returned by this endpoint:
{
"type": "interaction",
"interaction": { "type": "chat-message", "id": 24680 },
"content": { "html": "<p>Message text.</p>" }
}
POST
/
v2
/
chat-messages
Create a Chat Message
curl --request POST \
--url https://api.affinity.co/v2/chat-messages \
--header 'Authorization: Bearer <token>' \
--header 'Content-Type: application/json' \
--data '
{
"sentAt": "2023-01-01T00:00:00Z",
"direction": "sent",
"participants": [
{
"id": 1
},
{
"id": 2
}
]
}
'import requests
url = "https://api.affinity.co/v2/chat-messages"
payload = {
"sentAt": "2023-01-01T00:00:00Z",
"direction": "sent",
"participants": [{ "id": 1 }, { "id": 2 }]
}
headers = {
"Authorization": "Bearer <token>",
"Content-Type": "application/json"
}
response = requests.post(url, json=payload, headers=headers)
print(response.text)const options = {
method: 'POST',
headers: {Authorization: 'Bearer <token>', 'Content-Type': 'application/json'},
body: JSON.stringify({
sentAt: '2023-01-01T00:00:00Z',
direction: 'sent',
participants: [{id: 1}, {id: 2}]
})
};
fetch('https://api.affinity.co/v2/chat-messages', options)
.then(res => res.json())
.then(res => console.log(res))
.catch(err => console.error(err));<?php
$curl = curl_init();
curl_setopt_array($curl, [
CURLOPT_URL => "https://api.affinity.co/v2/chat-messages",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "POST",
CURLOPT_POSTFIELDS => json_encode([
'sentAt' => '2023-01-01T00:00:00Z',
'direction' => 'sent',
'participants' => [
[
'id' => 1
],
[
'id' => 2
]
]
]),
CURLOPT_HTTPHEADER => [
"Authorization: Bearer <token>",
"Content-Type: application/json"
],
]);
$response = curl_exec($curl);
$err = curl_error($curl);
curl_close($curl);
if ($err) {
echo "cURL Error #:" . $err;
} else {
echo $response;
}package main
import (
"fmt"
"strings"
"net/http"
"io"
)
func main() {
url := "https://api.affinity.co/v2/chat-messages"
payload := strings.NewReader("{\n \"sentAt\": \"2023-01-01T00:00:00Z\",\n \"direction\": \"sent\",\n \"participants\": [\n {\n \"id\": 1\n },\n {\n \"id\": 2\n }\n ]\n}")
req, _ := http.NewRequest("POST", url, payload)
req.Header.Add("Authorization", "Bearer <token>")
req.Header.Add("Content-Type", "application/json")
res, _ := http.DefaultClient.Do(req)
defer res.Body.Close()
body, _ := io.ReadAll(res.Body)
fmt.Println(string(body))
}HttpResponse<String> response = Unirest.post("https://api.affinity.co/v2/chat-messages")
.header("Authorization", "Bearer <token>")
.header("Content-Type", "application/json")
.body("{\n \"sentAt\": \"2023-01-01T00:00:00Z\",\n \"direction\": \"sent\",\n \"participants\": [\n {\n \"id\": 1\n },\n {\n \"id\": 2\n }\n ]\n}")
.asString();require 'uri'
require 'net/http'
url = URI("https://api.affinity.co/v2/chat-messages")
http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true
request = Net::HTTP::Post.new(url)
request["Authorization"] = 'Bearer <token>'
request["Content-Type"] = 'application/json'
request.body = "{\n \"sentAt\": \"2023-01-01T00:00:00Z\",\n \"direction\": \"sent\",\n \"participants\": [\n {\n \"id\": 1\n },\n {\n \"id\": 2\n }\n ]\n}"
response = http.request(request)
puts response.read_body{
"id": 1,
"sentAt": "2023-01-01T00:00:00Z",
"loggingType": "manual",
"direction": "sent",
"creator": {
"id": 1,
"firstName": "Jane",
"lastName": "Doe",
"primaryEmailAddress": "jane.smith@northpointvc.com",
"type": "internal"
},
"createdAt": "2022-01-01T00:00:00Z",
"updatedAt": "2023-01-01T00:00:00Z",
"participantsPreview": {
"data": [
{
"id": 1,
"firstName": "Jane",
"lastName": "Doe",
"primaryEmailAddress": "jane.smith@northpointvc.com",
"type": "internal"
}
],
"totalCount": 200
}
}{
"errors": [
{
"code": "bad-request",
"message": "<string>"
}
]
}{
"errors": [
{
"code": "not-found",
"message": "<string>"
}
]
}{
"errors": [
{
"code": "authentication",
"message": "<string>"
}
]
}Authorizations
Body
application/json
Request body for creating a chat message.
Response
Created
Was this page helpful?