MS Teams – Channels – Get Primary Channel
MS Teams – Channels – Get Primary Channel
Get the primary channel in a Team.
Action details
| Property | Value |
|---|---|
| Action label | MS Teams – Channels – Get Primary Channel |
| Category | CloudTools |
| Apex class and method | GetMSTeamsPrimaryChannel.getPrimaryChannel |
| Input type | GetMSTeamsPrimaryChannel.GetMSTeamsPrimaryChannelInput |
| Output type | List<MSTeamsChannel> |
| Authorization | Microsoft 365 connector; check endpoint support for delegated and application access. |
| Microsoft Graph request | GET /teams/{teamId}/primaryChannel |
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 | Channel.ReadBasic.All, ChannelSettings.Read.All, ChannelSettings.ReadWrite.All |
| Application | ChannelSettings.Read.Group, Channel.ReadBasic.All, ChannelSettings.Read.All, ChannelSettings.ReadWrite.All, ChannelSettings.ReadWrite.Group |
Endpoints: /teams/{teamId}/primaryChannel. 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 |
|---|---|---|---|---|
| Team Id | teamId | String | Yes | MS Teams team identifier |
| Filter | filterQuery | String | No | OData filter expression |
| Expand | expandQuery | String | No | Comma-separated related resources to expand |
| Select | selectQuery | String | No | Comma-separated properties to return (leave blank for default properties) |
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 MSTeamsChannel 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 channel |
| Display Name | displayName | String | Display name of the channel |
| Description | description | String | Description of the channel |
| Created Date Time | createdDateTime | String | Created date and time for the channel |
email | String | Email address of the channel | |
| Is Archived | isArchived | Boolean | Whether the channel is archived |
| Is Favorite By Default | isFavoriteByDefault | Boolean | Whether the channel is recommended by default |
| Membership Type | membershipType | String | Membership type of the channel |
| Tenant Id | tenantId | String | Tenant identifier for the channel |
| Web URL | webUrl | String | Web URL of the channel |
| Summary | summary | MSTeamsChannelSummary | Summary details for the channel |
| OData Type | odataType | String | OData type for the channel |
| OData ETag | odataEtag | String | OData ETag for the channel |
| Additional Properties | additionalProperties | List<DynamicObject> | Additional properties from user-defined query |
Behavior and limits
Nonblank query values are forwarded to Microsoft. Query support and syntax depend on the endpoint; the connector does not make unsupported OData options valid.
Use in Flow
Add MS Teams – Channels – Get Primary Channel 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.GetMSTeamsPrimaryChannel.GetMSTeamsPrimaryChannelInput request =
new Apptigent.GetMSTeamsPrimaryChannel.GetMSTeamsPrimaryChannelInput();
request.teamId = '893075dd-2487-4122-925f-022c42e20265';
request.filterQuery = 'membershipType eq \'standard\'';
request.expandQuery = 'members';
request.selectQuery = 'id,displayName,description,membershipType,isArchived,summary';
List<Apptigent.MSTeamsChannel> results =
Apptigent.GetMSTeamsPrimaryChannel.getPrimaryChannel(
new List<Apptigent.GetMSTeamsPrimaryChannel.GetMSTeamsPrimaryChannelInput>{ request }
);
System.debug(results);
Use in a Lightning Web Component
Use getMSTeamsPrimaryChannel 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 |
|---|---|
teamId | request.teamId |
filterQuery | request.filterQuery |
selectQuery | request.selectQuery |
The shared controller DTO does not expose these global inputs: expandQuery. 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 { getMSTeamsPrimaryChannel } 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.teamId = '893075dd-2487-4122-925f-022c42e20265';
request.filterQuery = 'membershipType eq \'standard\'';
request.selectQuery = 'id,displayName,description,membershipType,isArchived,summary';
this.result = await getMSTeamsPrimaryChannel(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. |