MS OneDrive – Get Folder Items
MS OneDrive – Get Folder Items
Lists the immediate children of the specified folder. Leave Item Id blank to list the root folder. It does not recursively traverse descendant folders. Select, Top, and Order By are passed to Microsoft.
Action details
| Property | Value |
|---|---|
| Action label | MS OneDrive – Get Folder Items |
| Category | CloudTools |
| Apex class and method | GetOneDriveLibraryItemChildren.getLibraryItemChildren |
| Input type | GetOneDriveLibraryItemChildren.GetOneDriveLibraryItemChildrenInput |
| Output type | List<List<MSGraphDriveItem>> |
| Authorization | OAuth Delegated (Authorization Code) or OAuth Application (Client Credentials). |
| Flow automation | Use an application connector configured as the Flow default. |
| Microsoft Graph operation | GET /v1.0/drives/{driveId}/items/{itemId}/children for Authorization Code Flow; otherwise GET /v1.0/users/{userIdOrPrincipalName}/drives/{driveId}/items/{itemId}/children. With blank Item Id, use /root/children instead of /items/{itemId}/children. |
Prerequisites and permissions
Configure a CloudTools Connector with Connector Type set to Microsoft 365. For delegated access, complete the current user’s Microsoft sign-in. For application access where supported, grant application permissions and administrator consent and provide the target user ID or principal name. The identity must have access to the selected drive and item.
Delegated calls generally require Files.Read; application calls generally require Files.Read.All. Broader file or site read/write permissions may also satisfy the operation. See the Microsoft operation and permissions reference.
Drive selection: For Authorization Code Flow, a populated driveId uses /drives/{driveId} and userIdOrPrincipalName is ignored. Other authorization types require userIdOrPrincipalName and use the user-scoped drive path shown above. A Library Id is a Graph drive ID and Item Id is an item within that drive; neither is a Salesforce record ID or browser URL.
Inputs
The table lists action labels, Apex field names, and Apex data types. Supply one non-null request with nonblank required text values.
| Input | Apex field | Type | Required | Description |
|---|---|---|---|---|
| User Id or Principal Name | userIdOrPrincipalName | String | Unless Authorization Code Flow is enabled | User id or user principal name. Ignored for Authorization Code Flow. |
| Library Id | driveId | String | Yes | Library (drive) identifier. |
| Item Id | itemId | String | No | Library (drive) item identifier. Leave blank for root folder.. |
| Select | selectQuery | String | No | Comma-separated properties to return. Supply only the OData value, without $select=, $top=, $orderby=, or a full URL. Microsoft validates support. |
| Top | topQuery | String | No | Number of items to return. Supply only the OData value, without $select=, $top=, $orderby=, or a full URL. Microsoft validates support. |
| Order By | orderbyQuery | String | No | Comma-separated properties to sort by. Supply only the OData value, without $select=, $top=, $orderby=, or a full URL. Microsoft validates support. |
The global invocable input has no connectorId field. Direct subscriber Apex and Flow calls use CloudTools connector selection. This action does not resolve replacement tokens; resolve dynamic values before invocation. See Using Token Replacements.
Outputs
The global invocable method returns List<List<MSGraphDriveItem>>, with one outer entry holding the collection for the first request. An empty lookup returns an empty inner list. In Apex, read results[0]; Flow receives a collection output. The LWC library returns a flat array.
The helper maps the response collection but does not follow or return @odata.nextLink. The result can contain only the first page. Top, where exposed, is a request page-size input rather than an exhaustive lookup. There is no continuation URL input.
| Output | Apex field | Type | Description |
|---|---|---|---|
| id | id | String | Microsoft Graph resource identifier. |
| name | name | String | Resource name. |
| description | description | String | Item description. |
| createdDateTime | createdDateTime | String | Creation timestamp retained as text. |
| lastModifiedDateTime | lastModifiedDateTime | String | Last modification timestamp retained as text. |
| createdBy | createdBy | MSGraphDriveIdentitySet | Identity that created the resource. |
| lastModifiedBy | lastModifiedBy | MSGraphDriveIdentitySet | Identity that last modified the resource. |
| webUrl | webUrl | String | Browser link to the resource. |
| webDavUrl | webDavUrl | String | WebDAV URL. |
| size | size | Long | Size in bytes. |
| eTag | eTag | String | Item entity tag. |
| cTag | cTag | String | Content entity tag. |
| odataType | odataType | String | Mapped OData type. |
| odataEtag | odataEtag | String | Mapped OData entity tag. |
| downloadUrl | downloadUrl | String | Mapped @microsoft.graph.downloadUrl, when returned. |
| sourceUrl | sourceUrl | String | Metadata returned when populated. |
| conflictBehavior | conflictBehavior | String | Metadata returned when populated. |
| content | content | String | Content field, if mapped; do not rely on it as a download. |
| parentReference | parentReference | MSGraphDriveItemReference | Parent identifiers and path through driveId, id, and path. |
| fileSystemInfo | fileSystemInfo | MSGraphDriveFileSystemInfo | File system timestamps. |
| folder | folder | MSGraphDriveFolderFacet | Folder facet, including childCount. |
| file | file | MSGraphDriveFileFacet | File facet, including mimeType; this facet is not the file bytes. |
| image | image | MSGraphDriveImageFacet | Metadata returned when populated. |
| photo | photo | MSGraphDrivePhotoFacet | Metadata returned when populated. |
| audio | audio | MSGraphDriveAudioFacet | Metadata returned when populated. |
| video | video | MSGraphDriveVideoFacet | Metadata returned when populated. |
| location | location | MSGraphDriveGeoCoordinates | Metadata returned when populated. |
| deleted | deleted | MSGraphDriveDeletedFacet | Metadata returned when populated. |
| pendingOperations | pendingOperations | MSGraphDrivePendingOperations | Metadata returned when populated. |
| packageInfo | packageInfo | MSGraphDrivePackageFacet | Metadata returned when populated. |
| publication | publication | MSGraphDrivePublicationFacet | Publication state and checkout identity. |
| remoteItem | remoteItem | MSGraphDriveRemoteItem | Metadata returned when populated. |
| root | root | MSGraphDriveRootFacet | Metadata returned when populated. |
| searchResult | searchResult | MSGraphDriveSearchResult | Metadata returned when populated. |
| shared | shared | MSGraphDriveSharedFacet | Metadata returned when populated. |
| sharepointIds | sharepointIds | MSGraphDriveSharePointIds | Metadata returned when populated. |
| specialFolder | specialFolder | MSGraphDriveSpecialFolder | Metadata returned when populated. |
| malware | malware | MSGraphDriveMalwareFacet | Metadata returned when populated. |
| bundle | bundle | MSGraphDriveBundleFacet | Metadata returned when populated. |
| children | children | List<MSGraphDriveItem> | Child items only when included in the response. |
| permissions | permissions | List<MSGraphDrivePermission> | Permissions only when included in the response. |
| versions | versions | List<MSGraphDriveItemVersion> | Versions only when included in the response. |
| thumbnails | thumbnails | List<MSGraphDriveThumbnailSet> | Metadata returned when populated. |
| listItem | listItem | MSGraphDriveListItem | Metadata returned when populated. |
| analytics | analytics | MSGraphDriveItemAnalytics | Metadata returned when populated. |
Optional facets depend on the item type and response. Parent Reference exposes driveId, id, and path; Folder exposes childCount; File exposes mimeType rather than bytes. Metadata timestamps remain text. This action does not automatically expand children, permissions, or versions. A downloadUrl, when supplied, is a temporary download URL; webUrl is the browser link.
Use in Flow
Add MS OneDrive – Get Folder Items in Flow Builder. Use a Microsoft 365 application connector configured as Set as default for Flow automations, supply the target user and resource IDs, and handle faults. Delegated connections are not supported for CloudTools Flow automation. This implementation processes only the first request; it is not a bulk operation.
Use in custom Apex
This subscriber-org example uses the Apptigent namespace. Replace all identifiers and run in a context that permits callouts with a configured connector. The example supplies the user for application access; omit it for an already-authorized delegated connector.
Apptigent.GetOneDriveLibraryItemChildren.GetOneDriveLibraryItemChildrenInput request =
new Apptigent.GetOneDriveLibraryItemChildren.GetOneDriveLibraryItemChildrenInput();
request.userIdOrPrincipalName = 'REPLACE_WITH_MICROSOFT_USER_ID_OR_UPN';
request.driveId = 'REPLACE_WITH_DRIVE_ID';
List<List<Apptigent.MSGraphDriveItem>> results =
Apptigent.GetOneDriveLibraryItemChildren.getLibraryItemChildren(
new List<Apptigent.GetOneDriveLibraryItemChildren.GetOneDriveLibraryItemChildrenInput>{ request }
);
List<Apptigent.MSGraphDriveItem> items = results.isEmpty()
? new List<Apptigent.MSGraphDriveItem>() : results[0];
System.debug(items.size());
The example leaves exception handling, authorization setup, and presentation or persistence of the result to the calling application.
Use in a Lightning Web Component
Use getOneDriveLibraryItemChildren from msOneDriveConnectorLib, through MSOneDriveConnectorController. These repository c/ imports apply to an LWC in the same namespace. Complete connector authorization before use.
Connector selection limitation: The wrapper accepts a second connectorId argument, but the current controller/action path does not forward it to select the Graph connector for this operation. Calls use CloudTools default connector selection. Passing a connectorId does not guarantee that this action uses that record. The Result wrapper can check authorization against the supplied record before invoking the action, while the action still selects its default connector.
oneDriveActionExample.js
import { LightningElement } from 'lwc';
import { getOneDriveLibraryItemChildren, MSOneDriveObjects } from 'c/msOneDriveConnectorLib';
export default class OneDriveActionExample extends LightningElement {
connectorId = 'REPLACE_WITH_CONNECTOR_RECORD_ID';
result = null;
errorMessage = '';
isRunning = false;
completed = false;
async handleRun() {
if (this.isRunning) {
return;
}
this.isRunning = true;
this.errorMessage = '';
try {
const request = MSOneDriveObjects.inputs.getOneDriveLibraryItemChildren();
request.userIdOrPrincipalName = 'REPLACE_WITH_MICROSOFT_USER_ID_OR_UPN';
request.driveId = 'REPLACE_WITH_DRIVE_ID';
const result = await getOneDriveLibraryItemChildren(request);
if (!Array.isArray(result)) {
throw new Error('The action did not return a usable result.');
}
this.result = result;
this.completed = true;
} catch (error) {
this.errorMessage = error.requiresInteractiveAuthorization
? 'Sign in to Microsoft for the connector, then try again.'
: error.message || 'The OneDrive action failed.';
} finally {
this.isRunning = false;
}
}
}
oneDriveActionExample.html
<template>
<lightning-button label="Run action" onclick={handleRun}
disabled={isRunning}></lightning-button>
<p role="alert">{errorMessage}</p>
</template>
The library resolves to a flat array, without an outer Apex list.
The controller flattens parentReference into parentDriveId, parentItemId, and parentPath; folder.childCount into folderChildCount; and file.mimeType into fileMimeType. Identity names and publication metadata are also flattened. Its rawJson serializes the mapped Apex model, not the original Microsoft response.
For structured failures, getOneDriveLibraryItemChildrenResult returns success, code, message, requiresInteractiveAuthorization, connector metadata, resultJson, and a parsed payload. The convenience function used above unwraps payload on success and throws on failure. The Result wrapper checks authorization before calling the action; it does not sign the user in.
For delegated sign-in, use getOneDriveAuthorizationState, beginOneDriveAuthorization, and createOneDriveOAuthMessageHandler. The example only reports errors. This controller path exposes structured requiresInteractiveAuthorization errors.
Error handling and troubleshooting
| Symptom | What to check |
|---|---|
| Required fields error | Provide a nonempty request list with a non-null first item and the required identifiers. Supply the user for non-delegated connectors. |
| Authorization or access denied | Check connector selection, Microsoft sign-in, consent, permission type, and access to the drive or item. |
| Resource not found | Verify driveId, itemId, and any version or permission ID. Keep related IDs associated with their source drive. |
| Missing fields or items | Check Select, item type, mapping limitations, and first-page behavior. Empty results and omitted fields are not proof that a resource does not exist. |
| Unexpected connector | Review the connector selection limitation above and the Microsoft 365 Flow default. |
| Operation rejected | Inspect the Microsoft error, item state, library capability, and tenant policy. Handle exceptions or structured Result failures in the caller. |