MS Entra – Groups – Add Library Item
MS Entra – Groups – Add Library Item
Upload a file to a group document library.
Action details
| Property | Value |
|---|---|
| Action label | MS Entra – Groups – Add Library Item |
| Category | CloudTools |
| Apex class and method | UploadEntraGroupLibraryItem.addLibraryItem |
| Input type | UploadEntraGroupLibraryItem.AddEntraGroupLibraryItemInput |
| Output type | List<MSGraphDriveItem> |
| Authorization | Microsoft 365 connector; supported authorization depends on the endpoint and target. |
| Microsoft Graph request | GET {fileUrl}, then PUT /groups/{groupId}/drives/{driveId}/items/{itemId}:/{fileName}:/content |
Prerequisites and permissions
Configure a CloudTools Connector with Connector Type set to Microsoft 365. Complete sign-in for OAuth Delegated (Authorization Code). For supported OAuth Application (Client Credentials) requests, grant application permissions and administrator consent. The identity must have access to the selected resource; directory operations can also require Microsoft Entra roles. Use Creating an Entra ID App and Integration Connectors for setup.
The action permission provider declares these alternatives. They are not cumulative requirements or universally interchangeable; check the Microsoft reference for endpoint, target, and property restrictions.
| Permission type | Declared alternatives |
|---|---|
| Delegated | Files.ReadWrite, Files.ReadWrite.All, Sites.ReadWrite.All |
| Application | Files.ReadWrite.All, Sites.ReadWrite.All |
Endpoints: {fileUrl}, then PUT /groups/{groupId}/drives/{driveId}/items/{itemId}:/{fileName}:/content. File and site scopes depend on the resource and tenant policy.
See the Microsoft operation and permissions reference.
Inputs
| Input | Apex field | Type | Required | Description |
|---|---|---|---|---|
| Group Id | groupId | String | Yes | Group identifier |
| Library Id | driveId | String | Yes | Library (drive) identifier |
| Item Id | itemId | String | Yes | Parent library item identifier |
| File URL | fileUrl | String | Yes | Direct URL to fetch file content from |
| File Name | fileName | String | No | Optional override for the uploaded file name (defaults from URL/headers) |
| Content Type | contentType | String | No | MIME content type to send (defaults to text/plain) |
Supply a nonempty list with a non-null first request. Graph actions process only that first request. Global inputs do not expose connectorId; subscriber Apex and Flow use CloudTools connector selection. Use Microsoft Graph resource IDs or the specifically documented user identifier, and resolve dynamic values before invocation.
Outputs
Returns one mapped MSGraphDriveItem inside a list. Check the actual result shape and fields before use.
| Output | Apex field | Type | Description |
|---|---|---|---|
| id | id | String | Mapped drive item property; populated only when returned and supported by the resource. |
| name | name | String | Mapped drive item property; populated only when returned and supported by the resource. |
| description | description | String | Mapped drive item property; populated only when returned and supported by the resource. |
| createdDateTime | createdDateTime | String | Mapped drive item property; populated only when returned and supported by the resource. |
| lastModifiedDateTime | lastModifiedDateTime | String | Mapped drive item property; populated only when returned and supported by the resource. |
| createdBy | createdBy | MSGraphDriveIdentitySet | Mapped drive item property; populated only when returned and supported by the resource. |
| lastModifiedBy | lastModifiedBy | MSGraphDriveIdentitySet | Mapped drive item property; populated only when returned and supported by the resource. |
| webUrl | webUrl | String | Mapped drive item property; populated only when returned and supported by the resource. |
| webDavUrl | webDavUrl | String | Mapped drive item property; populated only when returned and supported by the resource. |
| size | size | Long | Mapped drive item property; populated only when returned and supported by the resource. |
| eTag | eTag | String | Mapped drive item property; populated only when returned and supported by the resource. |
| cTag | cTag | String | Mapped drive item property; populated only when returned and supported by the resource. |
| odataType | odataType | String | Mapped drive item property; populated only when returned and supported by the resource. |
| odataEtag | odataEtag | String | Mapped drive item property; populated only when returned and supported by the resource. |
| downloadUrl | downloadUrl | String | Mapped drive item property; populated only when returned and supported by the resource. |
| sourceUrl | sourceUrl | String | Mapped drive item property; populated only when returned and supported by the resource. |
| conflictBehavior | conflictBehavior | String | Mapped drive item property; populated only when returned and supported by the resource. |
| content | content | String | Mapped drive item property; populated only when returned and supported by the resource. |
| parentReference | parentReference | MSGraphDriveItemReference | Mapped drive item property; populated only when returned and supported by the resource. |
| fileSystemInfo | fileSystemInfo | MSGraphDriveFileSystemInfo | Mapped drive item property; populated only when returned and supported by the resource. |
| folder | folder | MSGraphDriveFolderFacet | Mapped drive item property; populated only when returned and supported by the resource. |
| file | file | MSGraphDriveFileFacet | Mapped drive item property; populated only when returned and supported by the resource. |
| image | image | MSGraphDriveImageFacet | Mapped drive item property; populated only when returned and supported by the resource. |
| photo | photo | MSGraphDrivePhotoFacet | Mapped drive item property; populated only when returned and supported by the resource. |
| audio | audio | MSGraphDriveAudioFacet | Mapped drive item property; populated only when returned and supported by the resource. |
| video | video | MSGraphDriveVideoFacet | Mapped drive item property; populated only when returned and supported by the resource. |
| location | location | MSGraphDriveGeoCoordinates | Mapped drive item property; populated only when returned and supported by the resource. |
| deleted | deleted | MSGraphDriveDeletedFacet | Mapped drive item property; populated only when returned and supported by the resource. |
| pendingOperations | pendingOperations | MSGraphDrivePendingOperations | Mapped drive item property; populated only when returned and supported by the resource. |
| packageInfo | packageInfo | MSGraphDrivePackageFacet | Mapped drive item property; populated only when returned and supported by the resource. |
| publication | publication | MSGraphDrivePublicationFacet | Mapped drive item property; populated only when returned and supported by the resource. |
| remoteItem | remoteItem | MSGraphDriveRemoteItem | Mapped drive item property; populated only when returned and supported by the resource. |
| root | root | MSGraphDriveRootFacet | Mapped drive item property; populated only when returned and supported by the resource. |
| searchResult | searchResult | MSGraphDriveSearchResult | Mapped drive item property; populated only when returned and supported by the resource. |
| shared | shared | MSGraphDriveSharedFacet | Mapped drive item property; populated only when returned and supported by the resource. |
| sharepointIds | sharepointIds | MSGraphDriveSharePointIds | Mapped drive item property; populated only when returned and supported by the resource. |
| specialFolder | specialFolder | MSGraphDriveSpecialFolder | Mapped drive item property; populated only when returned and supported by the resource. |
| malware | malware | MSGraphDriveMalwareFacet | Mapped drive item property; populated only when returned and supported by the resource. |
| bundle | bundle | MSGraphDriveBundleFacet | Mapped drive item property; populated only when returned and supported by the resource. |
| children | children | List<MSGraphDriveItem> | Mapped drive item property; populated only when returned and supported by the resource. |
| permissions | permissions | List<MSGraphDrivePermission> | Mapped drive item property; populated only when returned and supported by the resource. |
| versions | versions | List<MSGraphDriveItemVersion> | Mapped drive item property; populated only when returned and supported by the resource. |
| thumbnails | thumbnails | List<MSGraphDriveThumbnailSet> | Mapped drive item property; populated only when returned and supported by the resource. |
| listItem | listItem | MSGraphDriveListItem | Mapped drive item property; populated only when returned and supported by the resource. |
| analytics | analytics | MSGraphDriveItemAnalytics | Mapped drive item property; populated only when returned and supported by the resource. |
Behavior and limits
This wrapper delegates the Graph operation to a shared file helper. It does not pass an explicit connector record ID to that helper, which initializes the default MSENTRA connector. A controller request.connectorId does not select the connection used by the delegated file call.
The input fileUrl is fetched server-side and uploaded to the target item path with fileName. This action does not accept Salesforce ContentVersion IDs or base64 file content. Ensure the source is accessible and the callout context permits it. It does not implement upload sessions; Salesforce heap and callout limits apply.
Use in Flow
Use MS Entra – Groups – Add Library Item where supported. Use a Microsoft 365 application connector configured as Set as default for Flow automations only if the endpoint and target support application access. Supply required values, retain useful outputs, and add fault handling. Delegated connections are not supported for CloudTools Flow automation. The action processes only the first input request.
Use in custom Apex
This subscriber-org example uses the Apptigent namespace. Replace identifiers and example values before use. Configure the connector, complete authorization first, run in a context permitting callouts, and handle exceptions, empty results, and unmapped fields.
Apptigent.UploadEntraGroupLibraryItem.AddEntraGroupLibraryItemInput request =
new Apptigent.UploadEntraGroupLibraryItem.AddEntraGroupLibraryItemInput();
request.groupId = 'f11f1340-30b1-4f1d-91ec-c853b7245646';
request.driveId = 'b!X5oVvJY9mkCm2tS6Dpo0Q6';
request.itemId = '01ABCDEF23456789!123';
request.fileUrl = 'https://example.com/files/notes.txt';
request.fileName = '';
request.contentType = 'text/plain';
List<Apptigent.MSGraphDriveItem> results =
Apptigent.UploadEntraGroupLibraryItem.addLibraryItem(
new List<Apptigent.UploadEntraGroupLibraryItem.AddEntraGroupLibraryItemInput>{ request }
);
System.debug(results);
Use in a Lightning Web Component
Use uploadEntraGroupLibraryItem from msEntraConnectorLib through MSEntraConnectorController. These c/ imports apply in the same namespace. Set request.connectorId for direct MSEntraAction calls. This action delegates to a file helper using the default connection; the request selection does not reach that file call.
| Global input | LWC request mapping |
|---|---|
groupId | request.groupId |
driveId | request.driveId |
itemId | request.itemId |
fileUrl | request.fileUrl |
fileName | request.fileName |
contentType | request.contentType |
entraActionExample.js
import { LightningElement } from 'lwc';
import { uploadEntraGroupLibraryItem } from 'c/msEntraConnectorLib';
export default class EntraActionExample 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.groupId = 'f11f1340-30b1-4f1d-91ec-c853b7245646';
request.driveId = 'b!X5oVvJY9mkCm2tS6Dpo0Q6';
request.itemId = '01ABCDEF23456789!123';
request.fileUrl = 'https://example.com/files/notes.txt';
request.fileName = '';
request.contentType = 'text/plain';
this.result = await uploadEntraGroupLibraryItem(request);
this.completed = true;
} catch (error) {
this.errorMessage = error.requiresInteractiveAuthorization
? 'Sign in to Microsoft for the connector, then try again.'
: error.message || 'The Entra action failed.';
} finally {
this.isRunning = false;
}
}
}
entraActionExample.html
<template>
<lightning-button label="Run action" onclick={handleRun}
disabled={isRunning}></lightning-button>
<p role="alert">{errorMessage}</p>
</template>
The library returns one mapped DTO or null. The controller can flatten nested fields, serialize data, or map an action result into an operation DTO. rawJson contains serialized mapped Apex data rather than the untouched Graph response.
Use getMSEntraAuthorizationState, beginMSEntraAuthorization, and createMSEntraOAuthMessageHandler to arrange delegated sign-in. The library normalizes errors but does not automatically sign in or retry. Reset completed for a new deliberate operation, and 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 and required or conditionally required inputs. For LWC, use the mapped field names. |
| Authorization or access denied | Check connector selection, sign-in, endpoint/target permission support, administrator consent, directory roles, and resource access. |
| Resource not found | Check Microsoft IDs and parent resource relationships. Preserve group/drive/item associations and mailbox/calendar/event IDs. |
| Missing or unexpected output | Check query support, pagination, wrapper versus item models, public-only properties, and mapped DTO fields. |
| Operation rejected | Inspect the Microsoft error, supported writable fields, group/calendar restrictions, recipient/license data, and file transfer limits. |