MS SharePoint – Files – Create Folder
MS SharePoint – Files – Create Folder
Creates a folder beneath Item Id by sending name, an empty folder facet, and optional @microsoft.graph.conflictBehavior. Item Id is the destination parent folder, not the ID of the folder being created. Retain the returned id for later item operations.
Action details
| Property | Value |
|---|---|
| Action label | MS SharePoint – Files – Create Folder |
| Category | CloudTools |
| Apex class and method | CreateSharePointLibraryFolder.createLibraryFolder |
| Input type | CreateSharePointLibraryFolder.CreateSharePointLibraryFolderInput |
| Output type | List<MSGraphDriveItem> |
| Authorization | OAuth Delegated (Authorization Code) or OAuth Application (Client Credentials), subject to endpoint restrictions. |
| Microsoft Graph request | POST /v1.0/sites/{siteId}/drives/{driveId}/items/{itemId}/children |
Prerequisites and permissions
Configure a CloudTools Connector with Connector Type set to Microsoft 365. Complete user sign-in for delegated access. For supported application access, grant application permissions and administrator consent. The calling identity must have access to the relevant site, list, library, or item; tenant policy and resource configuration still apply.
The action permission provider declares the following permission alternatives. These are not cumulative requirements and not all are least privileged. Check the linked Microsoft reference for the endpoint, authorization type, and current restrictions.
| Permission type | Declared alternatives |
|---|---|
| Delegated | Files.ReadWrite, Files.ReadWrite.All, Sites.ReadWrite.All |
| Application | Files.ReadWrite.All, Sites.ReadWrite.All |
See the Microsoft operation and permissions reference.
Inputs
Supply one non-null request with nonblank required identifiers. IDs must belong to the indicated site, list, or drive; do not substitute Salesforce IDs or browser URLs.
| Input | Apex field | Type | Required | Description |
|---|---|---|---|---|
| Site Id | siteId | String | Yes | SharePoint site identifier. |
| Library Id | driveId | String | Yes | Library (drive) identifier. |
| Item Id | itemId | String | Yes | Library (drive) item identifier. Identifies the existing destination parent folder. |
| Folder Name | name | String | Yes | Name of the new folder. |
| Conflict Behavior | conflictBehavior | String | No | Conflict behavior (rename, fail, replace). |
The global invocable input does not expose connectorId. Direct subscriber Apex and Flow calls use CloudTools connector selection. Resolve dynamic values before invocation; this action does not resolve replacement tokens.
Outputs
Returns one MSGraphDriveItem inside a list, or an empty list if no response is mapped. Check for an empty result before reading fields.
| 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 item type and the returned properties. Folder contains childCount; File contains mimeType rather than binary content. Nested children, permissions, and versions are not automatically expanded. webUrl is a browser link; downloadUrl, when provided, is temporary.
Use in Flow
Add MS SharePoint – Files – Create Folder in Flow Builder. Use a Microsoft 365 application connector configured as Set as default for Flow automations, supply the required resource IDs, and add fault handling. Delegated connections are not supported for CloudTools Flow automation. This implementation processes only the first input request and is not a bulk operation.
Use in custom Apex
This subscriber-org example uses the Apptigent namespace. Replace the identifiers, configure the connector, and run in a context that permits callouts. Arrange authorization before calling and handle exceptions in the caller.
Apptigent.CreateSharePointLibraryFolder.CreateSharePointLibraryFolderInput request =
new Apptigent.CreateSharePointLibraryFolder.CreateSharePointLibraryFolderInput();
request.siteId = 'REPLACE_WITH_SITE_ID';
request.driveId = 'REPLACE_WITH_DRIVE_ID';
request.itemId = 'REPLACE_WITH_ITEM_OR_PARENT_ID';
request.name = 'Project Files';
List<Apptigent.MSGraphDriveItem> results =
Apptigent.CreateSharePointLibraryFolder.createLibraryFolder(
new List<Apptigent.CreateSharePointLibraryFolder.CreateSharePointLibraryFolderInput>{ request }
);
Apptigent.MSGraphDriveItem item = results.isEmpty() ? null : results[0];
System.debug(item == null ? null : item.id);
Use in a Lightning Web Component
Use createSharePointLibraryFolder from msSharePointConnectorLib, through MSSharePointConnectorController. These c/ imports apply to an LWC in the same namespace. The function accepts one request object, including connectorId when applicable.
Connector selection limitation: This action delegates its Graph call to a shared file helper that does not receive the SharePoint request connectorId. It uses default Microsoft 365 connector selection. Supplying connectorId does not guarantee use of that record. Configure and authorize the default connector for this example.
sharePointActionExample.js
import { LightningElement } from 'lwc';
import { createSharePointLibraryFolder, MSSharePointObjects } from 'c/msSharePointConnectorLib';
export default class SharePointActionExample 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 = MSSharePointObjects.inputs.libraryItem();
request.siteId = 'REPLACE_WITH_SITE_ID';
request.driveId = 'REPLACE_WITH_DRIVE_ID';
request.itemId = 'REPLACE_WITH_ITEM_OR_PARENT_ID';
request.name = 'Project Files';
const result = await createSharePointLibraryFolder(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 SharePoint action failed.';
} finally {
this.isRunning = false;
}
}
}
sharePointActionExample.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 resource object or null.
The controller exposes driveId, listItemId, parentPath, parentSiteId, parentListId, and parentListItemId when available. File MIME type is exposed as mimeType and folder status as isFolder. These are LWC fields rather than global invocable output fields.
LWC rawJson serializes the mapped Apex object; it is not the untouched Microsoft response or an additional global invocable output. Use getMSSharePointAuthorizationState, beginMSSharePointAuthorization, and createMSSharePointOAuthMessageHandler to arrange delegated sign-in. The library normalizes controller errors, including requiresInteractiveAuthorization when available; it does not automatically sign in or retry.
The example prevents repeating a completed operation. Reset completed only for a new deliberate operation. If a failure leaves the outcome uncertain, inspect the resource before retrying. For Copy, completed means the request returned, not that the background copy finished.
Error handling and troubleshooting
| Symptom | What to check |
|---|---|
| Required fields error | Supply a nonempty request list, a non-null first request, and the required identifiers or body values. |
| Authorization or access denied | Check connector selection, sign-in, application versus delegated permissions, administrator consent, and resource access. |
| Resource not found | Verify the parent site, list, and drive IDs. Distinguish list item IDs from drive item IDs and retain permission or version IDs with their resource. |
| Missing fields or items | Check query inputs, first-page behavior, supported expansions, item type, and mapped output limitations. |
| Unexpected connector | Review the connector selection behavior described above and the Microsoft 365 default connector. |
| Operation rejected | Inspect the Microsoft error, JSON field values, library or page state, supported API capabilities, and tenant policies. |