Conversations
API for creating, accessing and updating user conversations.
A Conversation object looks like:
A ConversationParticipant object looks like:
GET /api/v1/conversations
GET /api/v1/conversations
Scope: url:GET|/api/v1/conversations
Returns the paginated list of conversations for the current user, most recent ones first.
Request Parameters:
Parameter | Type | Description |
---|---|---|
|
| When set, only return conversations of the specified type. For example, set to “unread” to return only conversations that haven’t been read. The default behavior is to return all non-archived conversations (i.e. read and unread). Allowed values: |
|
| When set, only return conversations for the specified courses, groups or users. The id should be prefixed with its type, e.g. “user_123” or “course_456”. Can be an array (by setting “filter[]”) or single value (by setting “filter”) |
|
| When filter[] contains multiple filters, combine them with this mode, filtering conversations that at have at least all of the contexts (“and”) or at least one of the contexts (“or”) Allowed values: |
|
| (Obsolete) Submissions are no longer linked to conversations. This parameter is ignored. |
|
| Default is false. If true, the top-level element of the response will be an object rather than an array, and will have the keys “conversations” which will contain the paged conversation data, and “conversation_ids” which will contain the ids of all conversations under this scope/filter in the same order. |
|
|
Allowed values: |
API response field:
id
The unique identifier for the conversation.
subject
The subject of the conversation.
workflow_state
The current state of the conversation (read, unread or archived)
last_message
A <=100 character preview from the most recent message
last_message_at
The timestamp of the latest message
message_count
The number of messages in this conversation
subscribed
Indicates whether the user is actively subscribed to the conversation
private
Indicates whether this is a private conversation (i.e. audience of one)
starred
Whether the conversation is starred
properties
Additional conversation flags (last_author, attachments, media_objects). Each listed property means the flag is set to true (i.e. the current user is the most recent author, there are attachments, or there are media objects)
audience
Array of user ids who are involved in the conversation, ordered by participation level, then alphabetical. Excludes current user, unless this is a monologue.
audience_contexts
Most relevant shared contexts (courses and groups) between current user and other participants. If there is only one participant, it will also include that user’s enrollment(s)/ membership type(s) in each course/group
avatar_url
URL to appropriate icon for this conversation (custom, individual or group avatar, depending on audience)
participants
Array of users (id, name, full_name) participating in the conversation. Includes current user. If ‘include[]=participant_avatars` was passed as an argument, each user in the array will also have an “avatar_url” field
visible
Boolean, indicates whether the conversation is visible under the current scope and filter. This attribute is always true in the index API response, and is primarily useful in create/update responses so that you can know if the record should be displayed in the UI. The default scope is assumed, unless a scope or filter is passed to the create/update API call.
Example Response:
Returns a list of Conversation objects.
ConversationsController#create
POST /api/v1/conversations
POST /api/v1/conversations
Scope: url:POST|/api/v1/conversations
Create a new conversation with one or more recipients. If there is already an existing private conversation with the given recipients, it will be reused.
Request Parameters:
Parameter | Type | Description |
---|---|---|
| Required | An array of recipient ids. These may be user ids or course/group ids prefixed with “course_” or “group_” respectively, e.g. recipients[]=1&recipients=2&recipients[]=course_3. If the course/group has over 100 enrollments, ‘bulk_message’ and ‘group_conversation’ must be set to true. |
|
| The subject of the conversation. This is ignored when reusing a conversation. Maximum length is 255 characters. |
| Required | The message to be sent |
|
| Forces a new message to be created, even if there is an existing private conversation. |
|
| Defaults to false. When false, individual private conversations will be created with each recipient. If true, this will be a group conversation (i.e. all recipients may see all messages and replies). Must be set true if the number of recipients is over the set maximum (default is 100). |
|
| An array of attachments ids. These must be files that have been previously uploaded to the sender’s “conversation attachments” folder. |
|
| Media comment id of an audio or video file to be associated with this message. |
|
| Type of the associated media file Allowed values: |
|
| Determines whether the messages will be created/sent synchronously or asynchronously. Defaults to sync, and this option is ignored if this is a group conversation or there is just one recipient (i.e. it must be a bulk private message). When sent async, the response will be an empty array (batch status can be queried via the batches API) Allowed values: |
|
| Used when generating “visible” in the API response. See the explanation under the index API action Allowed values: |
|
| Used when generating “visible” in the API response. See the explanation under the index API action |
|
| Used when generating “visible” in the API response. See the explanation under the index API action Allowed values: |
|
| The course or group that is the context for this conversation. Same format as courses or groups in the recipients argument. |
ConversationsController#batches
GET /api/v1/conversations/batches
GET /api/v1/conversations/batches
Scope: url:GET|/api/v1/conversations/batches
Returns any currently running conversation batches for the current user. Conversation batches are created when a bulk private message is sent asynchronously (see the mode argument to the create API action).
Example Response:
GET /api/v1/conversations/:id
GET /api/v1/conversations/:id
Scope: url:GET|/api/v1/conversations/:id
Returns information for a single conversation for the current user. Response includes all fields that are present in the list/index action as well as messages and extended participant information.
Request Parameters:
Parameter | Type | Description |
---|---|---|
|
| (Obsolete) Submissions are no longer linked to conversations. This parameter is ignored. |
|
| Used when generating “visible” in the API response. See the explanation under the index API action Allowed values: |
|
| Used when generating “visible” in the API response. See the explanation under the index API action |
|
| Used when generating “visible” in the API response. See the explanation under the index API action Allowed values: |
|
| Default true. If true, unread conversations will be automatically marked as read. This will default to false in a future API release, so clients should explicitly send true if that is the desired behavior. |
API response field:
participants
Array of relevant users. Includes current user. If there are forwarded messages in this conversation, the authors of those messages will also be included, even if they are not participating in this conversation. Fields include:
messages
Array of messages, newest first. Fields include:
id
The unique identifier for the message
created_at
The timestamp of the message
body
The actual message body
author_id
The id of the user who sent the message (see audience, participants)
generated
If true, indicates this is a system-generated message (e.g. “Bob added Alice to the conversation”)
media_comment
Audio/video comment data for this message (if applicable). Fields include: display_name, content-type, media_id, media_type, url
forwarded_messages
If this message contains forwarded messages, they will be included here (same format as this list). Note that those messages may have forwarded messages of their own, etc.
attachments
Array of attachments for this message. Fields include: display_name, content-type, filename, url
submissions
(Obsolete) Array of assignment submissions having comments relevant to this conversation. Submissions are no longer linked to conversations. This field will always be nil or empty.
Example Response:
ConversationsController#update
PUT /api/v1/conversations/:id
PUT /api/v1/conversations/:id
Scope: url:PUT|/api/v1/conversations/:id
Updates attributes for a single conversation.
Request Parameters:
Parameter | Type | Description |
---|---|---|
|
| Change the state of this conversation Allowed values: |
|
| Toggle the current user’s subscription to the conversation (only valid for group conversations). If unsubscribed, the user will still have access to the latest messages, but the conversation won’t be automatically flagged as unread, nor will it jump to the top of the inbox. |
|
| Toggle the starred state of the current user’s view of the conversation. |
|
| Used when generating “visible” in the API response. See the explanation under the index API action Allowed values: |
|
| Used when generating “visible” in the API response. See the explanation under the index API action |
|
| Used when generating “visible” in the API response. See the explanation under the index API action Allowed values: |
Example Response:
ConversationsController#mark_all_as_read
POST /api/v1/conversations/mark_all_as_read
POST /api/v1/conversations/mark_all_as_read
Scope: url:POST|/api/v1/conversations/mark_all_as_read
Mark all conversations as read.
ConversationsController#destroy
DELETE /api/v1/conversations/:id
DELETE /api/v1/conversations/:id
Scope: url:DELETE|/api/v1/conversations/:id
Delete this conversation and its messages. Note that this only deletes this user’s view of the conversation.
Response includes same fields as UPDATE action
Example Response:
ConversationsController#add_recipients
POST /api/v1/conversations/:id/add_recipients
POST /api/v1/conversations/:id/add_recipients
Scope: url:POST|/api/v1/conversations/:id/add_recipients
Add recipients to an existing group conversation. Response is similar to the GET/show action, except that only includes the latest message (e.g. “joe was added to the conversation by bob”)
Request Parameters:
Parameter | Type | Description |
---|---|---|
| Required | An array of recipient ids. These may be user ids or course/group ids prefixed with “course_” or “group_” respectively, e.g. recipients[]=1&recipients=2&recipients[]=course_3 |
Example Response:
ConversationsController#add_message
POST /api/v1/conversations/:id/add_message
POST /api/v1/conversations/:id/add_message
Scope: url:POST|/api/v1/conversations/:id/add_message
Add a message to an existing conversation. Response is similar to the GET/show action, except that only includes the latest message (i.e. what we just sent)
An array of user ids. Defaults to all of the current conversation recipients. To explicitly send a message to no other recipients, this array should consist of the logged-in user id.
An array of message ids from this conversation to send to recipients of the new message. Recipients who already had a copy of included messages will not be affected.
Request Parameters:
Parameter | Type | Description |
---|---|---|
| Required | The message to be sent. |
|
| An array of attachments ids. These must be files that have been previously uploaded to the sender’s “conversation attachments” folder. |
|
| Media comment id of an audio of video file to be associated with this message. |
|
| Type of the associated media file. Allowed values: |
|
| no description |
|
| no description |
Example Response:
ConversationsController#remove_messages
POST /api/v1/conversations/:id/remove_messages
POST /api/v1/conversations/:id/remove_messages
Scope: url:POST|/api/v1/conversations/:id/remove_messages
Delete messages from this conversation. Note that this only affects this user’s view of the conversation. If all messages are deleted, the conversation will be as well (equivalent to DELETE)
Request Parameters:
Parameter | Type | Description |
---|---|---|
| Required | Array of message ids to be deleted |
Example Response:
ConversationsController#batch_update
PUT /api/v1/conversations
PUT /api/v1/conversations
Scope: url:PUT|/api/v1/conversations
Perform a change on a set of conversations. Operates asynchronously; use the progress endpoint to query the status of an operation.
Request Parameters:
Parameter | Type | Description |
---|---|---|
| Required | List of conversations to update. Limited to 500 conversations. |
| Required | The action to take on each conversation. Allowed values: |
Example Request:
Returns a Progress object.
ConversationsController#find_recipients
GET /api/v1/conversations/find_recipients
GET /api/v1/conversations/find_recipients
Scope: url:GET|/api/v1/conversations/find_recipients
Deprecated, see the Find recipients endpoint in the Search API
ConversationsController#unread_count
GET /api/v1/conversations/unread_count
GET /api/v1/conversations/unread_count
Scope: url:GET|/api/v1/conversations/unread_count
Get the number of unread conversations for the current user
Example Response:
© Instructure, Inc. Generated on Wed Nov 6 14:20:06 2024 This documentation is generated directly from the Canvas LMS source code, available on Github.
Last updated