How to get file ID from SharePoint in n8n?

Hi,
I’m trying to download a file from SharePoint in my n8n workflow, but I need the file id to do that.

When I use Get Many Items, I get a list of objects with fields like parentReference, webUrl, etc., but I can’t find the actual file id anywhere.

Does anyone know how I can retrieve the file id?
Or is there a way to download the file directly using webUrl instead of the id?

Thanks in advance!

1 Like

@Dorota_Maliszewska The “id” field IS in the response but it’s often a long string that contains additional metadata. You need to extract the GUID from it.

When you get items from SharePoint, the id field looks something like this:

"id": "01ABC12345DEFGHIJKLMNOPQRSTUVWXYZABCDE-12345"

The part you need is usually the first segment before any hyphens or special characters

To extract the file id add a Function Node after your “Get Many Items” node

// Extract the clean file ID from SharePoint's response
const items = $input.all();

const processedItems = items.map(item => {
  const fullId = item.json.id;
  
  // Extract the GUID (first part before any special characters)
  const cleanId = fullId.split(/[-_]/)[0];
  
  return {
    json: {
      fileId: cleanId,
      fileName: item.json.name,
      webUrl: item.json.webUrl,
      // Include other fields you need
      ...item.json
    }
  };
});

return processedItems;

But alternatively you can download directly with weburl

Thank you for your quick reply.
Could you please point out which specific element contains the file ID?
And how can the file be retrieved using the webUrl? Which node should be used for that?
{
“@odata.etag”: “#etag1”,
“createdBy”: {
“user”: {
“email”: “#email1”,
“id”: “#id1”,
“displayName”: “#name1”
}
},
“createdDateTime”: “#datetime1”,
“eTag”: “#etag1”,
“id”: “#itemId1”,
“lastModifiedBy”: {
“user”: {
“email”: “#email1”,
“id”: “#id1”,
“displayName”: “#name1”
}
},
“lastModifiedDateTime”: “#datetime1”,
“parentReference”: {
“id”: “#id2”,
“listId”: “#id3”,
“siteId”: “#siteId1”
},
“webUrl”: “#url1”,
“contentType”: {
“id”: “#id4”,
“name”: “#name2”
}
}

Did you ever get anywhere with this?

I’m facing the same issue, I want to get a list of files from a document library and download them but the id’s returned don’t ressemble the actual file ids

No, I haven’t gotten anywhere with this yet—I’m still waiting for a solution. :smiling_face_with_tear:

1 Like

I have same issue. I can get many info with Get many items but I need drive ID for Download File what is not included in Get many items response even if I turn off simplify option. Atm I think sharepoint node pretty useless or I am noob. But I see there are people who have some problem as mine. Zelite your method not working cuz I got this type id like

id: 661