MS Teams – Chats – Add Chat Member
MS Teams – Chats – Add Chat Member
Add a member to a chat.
Action details
| Property | Value |
|---|---|
| Action label | MS Teams – Chats – Add Chat Member |
| Category | CloudTools |
| Apex class and method | AddMSTeamsChatMember.addChatMember |
| Input type | AddMSTeamsChatMember.AddMSTeamsChatMemberInput |
| Output type | List<MSTeamsConversationMember> |
| Authorization | Microsoft 365 connector; check endpoint support for delegated and application access. |
| Microsoft Graph request | POST /chats/{chatId}/members |
Prerequisites and permissions
Configure a CloudTools Connector with Connector Type set to Microsoft 365. Complete Microsoft sign-in for OAuth Delegated (Authorization Code). For endpoints supporting OAuth Application (Client Credentials), grant application permissions and administrator consent. The identity must have access to the selected resource. See Creating an Entra ID App and Integration Connectors for setup.
The action permission provider declares these alternatives. They are not cumulative requirements, and not all are least privileged. Confirm endpoint restrictions and any resource-specific consent requirements in the Microsoft reference.
| Permission type | Declared alternatives |
|---|---|
| Delegated | ChatMember.ReadWrite, Chat.ReadWrite |
| Application | Chat.Manage.Chat, Chat.ReadWrite.All, ChatMember.ReadWrite.All |
Endpoints: /chats/{chatId}/members. Resource-specific consent and installation requirements apply to resource-specific permissions.
See the Microsoft operation and permissions reference.
Inputs
| Input | Apex field | Type | Required | Description |
|---|---|---|---|---|
| Chat Id | chatId | String | Yes | MS Teams chat identifier |
| User Id or Principal Name | userIdOrPrincipalName | String | Yes | Microsoft Entra user id or principal name |
| Roles | rolesCsv | String | No | Comma-separated roles (for example: owner). Leave blank for member. |
| Visible History Start Date Time | visibleHistoryStartDateTime | String | No | Optional ISO timestamp indicating how much prior chat history to share |
| Tenant Id | tenantId | String | No | Optional tenant id for out-of-tenant members |
Supply a nonempty list with a non-null first request. This implementation processes only the first request and does not bulk-process Flow interviews. Global inputs do not expose connectorId; Flow and subscriber Apex use CloudTools connector selection. Use Microsoft Graph IDs, not Salesforce IDs or browser links. Resolve dynamic values before invoking this action.
Outputs
Returns one MSTeamsConversationMember inside a list, or an empty list if no resource is mapped. Check for an empty result before reading fields.
| Output | Apex field | Type | Description |
|---|---|---|---|
| Id | id | String | Unique identifier for the conversation member |
| Display Name | displayName | String | Display name of the member |
| Roles | roles | List<String> | Roles for the member in the conversation |
| Visible History Start Date Time | visibleHistoryStartDateTime | String | Time from which the member can see conversation history |
| User Id | userId | String | Microsoft Entra user identifier for the member |
email | String | Email address for the member | |
| Tenant Id | tenantId | String | Tenant identifier for the member |
| OData Type | odataType | String | OData type for the member |
| Additional Properties | additionalProperties | List<DynamicObject> | Additional properties from user-defined query |
Behavior and limits
Roles CSV accepts owner or blank. The connector adds the aadUserConversationMember type and user binding. Retain the returned membership id; it differs from the Microsoft user id.
Use in Flow
Add MS Teams – Chats – Add Chat Member where supported. Use a Microsoft 365 application connector configured as Set as default for Flow automations only if the endpoint supports the required application operation. Delegated connections are not supported for CloudTools Flow automation. Supply required values, retain outputs, and add fault handling.
Use in custom Apex
This subscriber-org example uses the Apptigent namespace. Replace example identifiers and values before use. Configure the connector, arrange authorization first, run in a context permitting callouts, and handle exceptions and empty results.
Apptigent.AddMSTeamsChatMember.AddMSTeamsChatMemberInput request =
new Apptigent.AddMSTeamsChatMember.AddMSTeamsChatMemberInput();
request.chatId = '19:cf66807577b149cca1b7af0c32eec122@thread.v2';
request.userIdOrPrincipalName = '8b081ef6-4792-4def-b2c9-c363a1bf41d5';
request.rolesCsv = 'owner';
request.visibleHistoryStartDateTime = '2019-04-18T23:51:43.255Z';
request.tenantId = '4dc1fe35-8ac6-4f0d-904a-7ebcd364bea1';
List<Apptigent.MSTeamsConversationMember> results =
Apptigent.AddMSTeamsChatMember.addChatMember(
new List<Apptigent.AddMSTeamsChatMember.AddMSTeamsChatMemberInput>{ request }
);
System.debug(results);
Use in a Lightning Web Component
Use addMSTeamsChatMember from msTeamsConnectorLib through MSTeamsConnectorController. Set request.connectorId to select a configured connector. These c/ imports apply in the same namespace. The controller uses a shared request DTO; its field names differ from the global invocable input.
| Global input | LWC request mapping |
|---|---|
chatId | request.chatId |
userIdOrPrincipalName | request.userId |
rolesCsv | request.rolesCsv |
The shared controller DTO does not expose these global inputs: visibleHistoryStartDateTime, tenantId. Adding them as arbitrary properties to request does not make them reach the action. Use global Apex/Flow for those inputs where authorization permits.
teamsActionExample.js
import { LightningElement } from 'lwc';
import { addMSTeamsChatMember } from 'c/msTeamsConnectorLib';
export default class TeamsActionExample extends LightningElement {
result = null;
errorMessage = '';
isRunning = false;
completed = false;
async handleRun() {
if (this.isRunning || this.completed) return;
this.isRunning = true;
this.errorMessage = '';
try {
const request = { connectorId: 'REPLACE_WITH_CONNECTOR_RECORD_ID' };
request.chatId = '19:cf66807577b149cca1b7af0c32eec122@thread.v2';
request.userId = '8b081ef6-4792-4def-b2c9-c363a1bf41d5';
request.rolesCsv = 'owner';
this.result = await addMSTeamsChatMember(request);
this.completed = true;
} catch (error) {
this.errorMessage = error.requiresInteractiveAuthorization
? 'Sign in to Microsoft for the connector, then try again.'
: error.message || 'The Teams action failed.';
} finally {
this.isRunning = false;
}
}
}
teamsActionExample.html
<template>
<lightning-button label="Run action" onclick={handleRun}
disabled={isRunning}></lightning-button>
<p role="alert">{errorMessage}</p>
</template>
The library resolves to one mapped object or null. rawJson serializes the mapped Apex model rather than the untouched Microsoft response. Message body, membership roles, and nested properties can be flattened or serialized in JavaScript DTOs.
Use getMSTeamsAuthorizationState, beginMSTeamsAuthorization, and createMSTeamsOAuthMessageHandler to arrange delegated sign-in. The library normalizes errors but does not automatically sign in or retry. Reset completed for a new deliberate operation. Inspect resource state before retrying a mutation with an uncertain outcome.
Error handling and troubleshooting
| Symptom | What to check |
|---|---|
| Required fields error | Supply a nonempty request list, a non-null first request, and required or conditionally required values. For LWC, check controller mappings. |
| Authorization or access denied | Check selected connector, delegated versus application support, consent, Teams app installation where required, and access to the resource. |
| Resource not found | Check team, channel, chat, message, membership, and app installation IDs; these are distinct identifiers. |
| Missing data | Check pagination, query support, empty-response behavior, and documented model mapping. |
| Operation rejected | Inspect the Microsoft error, endpoint restrictions, supported properties, message authorization limits, and notification configuration. |