MS OneDrive – Move Library Item

Estimated reading: 7 minutes

MS OneDrive – Move Library Item

Updates parentReference to move an item within the same drive and can rename it through New Name. Microsoft does not support moves between drives with this operation; Parent Library Id is not a cross-drive move capability. To target the root, supply its actual item ID rather than the literal root as Parent Folder Id. The helper requires a nonblank New Name or parent reference; New Name alone performs a rename. No If-Match input is exposed.

Action details

PropertyValue
Action labelMS OneDrive – Move Library Item
CategoryCloudTools
Apex class and methodMoveOneDriveLibraryItem.moveLibraryItem
Input typeMoveOneDriveLibraryItem.MoveOneDriveLibraryItemInput
Output typeList<MSGraphDriveItem>
AuthorizationOAuth Delegated (Authorization Code) or OAuth Application (Client Credentials).
Flow automationUse an application connector configured as the Flow default.
Microsoft Graph operationPATCH /v1.0/drives/{driveId}/items/{itemId} for Authorization Code Flow; otherwise PATCH /v1.0/users/{userIdOrPrincipalName}/drives/{driveId}/items/{itemId}.

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 require Files.ReadWrite or a supported broader write permission; application calls require Files.ReadWrite.All or Sites.ReadWrite.All. 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.

InputApex fieldTypeRequiredDescription
User Id or Principal NameuserIdOrPrincipalNameStringUnless Authorization Code Flow is enabledUser id or user principal name. Ignored for Authorization Code Flow.
Library IddriveIdStringYesLibrary (drive) identifier.
Item IditemIdStringYesLibrary (drive) item identifier.
New NamenewNameStringNoNew item name.
Parent Library IdparentDriveIdStringNoParent library (drive) identifier.
Parent Folder IdparentItemIdStringNoParent folder identifier.

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

Returns one MSGraphDriveItem inside a list, or an empty list when no response is mapped. Check for an empty result and a populated resource ID before subsequent operations.

OutputApex fieldTypeDescription
ididStringMicrosoft Graph resource identifier.
namenameStringResource name.
descriptiondescriptionStringItem description.
createdDateTimecreatedDateTimeStringCreation timestamp retained as text.
lastModifiedDateTimelastModifiedDateTimeStringLast modification timestamp retained as text.
createdBycreatedByMSGraphDriveIdentitySetIdentity that created the resource.
lastModifiedBylastModifiedByMSGraphDriveIdentitySetIdentity that last modified the resource.
webUrlwebUrlStringBrowser link to the resource.
webDavUrlwebDavUrlStringWebDAV URL.
sizesizeLongSize in bytes.
eTageTagStringItem entity tag.
cTagcTagStringContent entity tag.
odataTypeodataTypeStringMapped OData type.
odataEtagodataEtagStringMapped OData entity tag.
downloadUrldownloadUrlStringMapped @microsoft.graph.downloadUrl, when returned.
sourceUrlsourceUrlStringMetadata returned when populated.
conflictBehaviorconflictBehaviorStringMetadata returned when populated.
contentcontentStringContent field, if mapped; do not rely on it as a download.
parentReferenceparentReferenceMSGraphDriveItemReferenceParent identifiers and path through driveId, id, and path.
fileSystemInfofileSystemInfoMSGraphDriveFileSystemInfoFile system timestamps.
folderfolderMSGraphDriveFolderFacetFolder facet, including childCount.
filefileMSGraphDriveFileFacetFile facet, including mimeType; this facet is not the file bytes.
imageimageMSGraphDriveImageFacetMetadata returned when populated.
photophotoMSGraphDrivePhotoFacetMetadata returned when populated.
audioaudioMSGraphDriveAudioFacetMetadata returned when populated.
videovideoMSGraphDriveVideoFacetMetadata returned when populated.
locationlocationMSGraphDriveGeoCoordinatesMetadata returned when populated.
deleteddeletedMSGraphDriveDeletedFacetMetadata returned when populated.
pendingOperationspendingOperationsMSGraphDrivePendingOperationsMetadata returned when populated.
packageInfopackageInfoMSGraphDrivePackageFacetMetadata returned when populated.
publicationpublicationMSGraphDrivePublicationFacetPublication state and checkout identity.
remoteItemremoteItemMSGraphDriveRemoteItemMetadata returned when populated.
rootrootMSGraphDriveRootFacetMetadata returned when populated.
searchResultsearchResultMSGraphDriveSearchResultMetadata returned when populated.
sharedsharedMSGraphDriveSharedFacetMetadata returned when populated.
sharepointIdssharepointIdsMSGraphDriveSharePointIdsMetadata returned when populated.
specialFolderspecialFolderMSGraphDriveSpecialFolderMetadata returned when populated.
malwaremalwareMSGraphDriveMalwareFacetMetadata returned when populated.
bundlebundleMSGraphDriveBundleFacetMetadata returned when populated.
childrenchildrenList<MSGraphDriveItem>Child items only when included in the response.
permissionspermissionsList<MSGraphDrivePermission>Permissions only when included in the response.
versionsversionsList<MSGraphDriveItemVersion>Versions only when included in the response.
thumbnailsthumbnailsList<MSGraphDriveThumbnailSet>Metadata returned when populated.
listItemlistItemMSGraphDriveListItemMetadata returned when populated.
analyticsanalyticsMSGraphDriveItemAnalyticsMetadata 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 – Move Library Item 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.MoveOneDriveLibraryItem.MoveOneDriveLibraryItemInput request =
    new Apptigent.MoveOneDriveLibraryItem.MoveOneDriveLibraryItemInput();
request.userIdOrPrincipalName = 'REPLACE_WITH_MICROSOFT_USER_ID_OR_UPN';
request.driveId = 'REPLACE_WITH_DRIVE_ID';
request.itemId = 'REPLACE_WITH_ITEM_OR_PARENT_ID';
request.parentItemId = 'REPLACE_WITH_DESTINATION_FOLDER_ID';

List<Apptigent.MSGraphDriveItem> results =
    Apptigent.MoveOneDriveLibraryItem.moveLibraryItem(
        new List<Apptigent.MoveOneDriveLibraryItem.MoveOneDriveLibraryItemInput>{ request }
    );

Apptigent.MSGraphDriveItem item = results.isEmpty() ? null : results[0];
String resultId = item == null ? null : item.id;
System.debug(resultId);

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 moveOneDriveLibraryItem 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.

oneDriveActionExample.js

import { LightningElement } from 'lwc';
import { moveOneDriveLibraryItem, 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 || this.completed) {
            return;
        }
        this.isRunning = true;
        this.errorMessage = '';
        try {
            const request = MSOneDriveObjects.inputs.moveOneDriveLibraryItem();
            request.userIdOrPrincipalName = 'REPLACE_WITH_MICROSOFT_USER_ID_OR_UPN';
            request.driveId = 'REPLACE_WITH_DRIVE_ID';
            request.itemId = 'REPLACE_WITH_ITEM_OR_PARENT_ID';
            request.parentItemId = 'REPLACE_WITH_DESTINATION_FOLDER_ID';
            const result = await moveOneDriveLibraryItem(request);
            if (!result?.id) {
                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 one resource object or null when no response is mapped; read result.id directly.

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 delegated sign-in, use getOneDriveAuthorizationState, beginOneDriveAuthorization, and createOneDriveOAuthMessageHandler. The example only reports errors. This controller path converts failures to plain Aura-handled messages, so requiresInteractiveAuthorization is not guaranteed. Use the authorization-state helper before calling and handle message-only failures.

The example avoids repeating a completed operation. Reset completed only when starting another deliberate operation. If an error leaves the outcome uncertain, inspect the item or destination before retrying. For Copy, completed means the request returned, not that the background copy has finished.

Error handling and troubleshooting

SymptomWhat to check
Required fields errorProvide a nonempty request list with a non-null first item and the required identifiers. Supply the user for non-delegated connectors.
Authorization or access deniedCheck connector selection, Microsoft sign-in, consent, permission type, and access to the drive or item.
Resource not foundVerify driveId, itemId, and any version or permission ID. Keep related IDs associated with their source drive.
Missing fields or itemsCheck Select, item type, mapping limitations, and first-page behavior. Empty results and omitted fields are not proof that a resource does not exist.
Unexpected connectorReview the connector selection limitation above and the Microsoft 365 Flow default.
Operation rejectedInspect the Microsoft error, item state, library capability, and tenant policy. Handle exceptions or structured Result failures in the caller.
Share this Doc

MS OneDrive – Move Library Item

Or copy link

CONTENTS

Free eBook: The Ultimate Guide to Power Platform Custom Connectors

Antimanual

Ask our AI support assistant your questions about our platform, features, and services.

You are offline
Chatbot avatar
What can I help you with?

Subscribe

×
Cancel