0

I have a list with items in SharePoint Online. There many items and their structure look like a tree.

list/
    itemA/
    itemB/
          itemBa/
                 itemX
          itemBb/
                 itemY
          itemBc/
    itemC/

How can I get a parent guid of the itemX by REST or GraphAPI? (for example)

Actually, I have to get a hierarchy of items on the List. But SharePoint API provides children of a List, but not their hierarchy. Is it possible to get?

0

For Item-

_api/Web/Lists/getByTitle('MyList')/items(1)/ParentID

For Site-

_spPageContextInfo.webAbsoluteUrl/_api/web/parentweb?$select=Id

1
  • It doesn't work. { "error": { "code": "-1, Microsoft.SharePoint.Client.ResourceNotFoundException", "message": { "lang": "en-US", "value": "Cannot find resource for the request ParentID." } } } Apr 20 at 10:52
0

You can follow below steps to get the parent folder's GUID. You will require 2 calls to do so:

  1. Use below REST API to access the actual item. In that you will have file directory reference. This will be used to access your parent folder of item. i.e.: itemX

    https://<site-url>/_api/web/lists/getbytitle('<list-title>')/items(<item-id>)?$select=ID,FileDirRef

In the output: you will have relative path of the parent folder. Use that path in 2nd step.

  1. Create REST API to access GUID of the parent folder as below:

https://<site-url>/_api/web/getfolderbyserverrelativeurl('<pass the relative path of the parent folder>')/listitemallfields/GUID

output:

<d:GUID xmlns:d="http://schemas.microsoft.com/ado/2007/08/dataservices" xmlns:m="http://schemas.microsoft.com/ado/2007/08/dataservices/metadata" xmlns:georss="http://www.georss.org/georss" xmlns:gml="http://www.opengis.net/gml" m:type="Edm.Guid">70870a3f-2f73-4ad9-b5ac-8eeba2d823b0</d:GUID>

7
  • It returns the item properties. Apr 20 at 11:26
  • But I need a parent GUID of the item Apr 20 at 11:27
  • Please check my updated answer to get parent folder's GUID. Apr 20 at 11:47
  • Yes, it should work. But I prefer to use one request. Because there Throttling limits Apr 20 at 11:53
  • 1
    In that case, you can get all the items from list with their directory path & GUID. Then manipulate them within json array to identify the guid of the parent of your item. Because there is no such API I found that gives parent GUID details during actual item fetch. Apr 20 at 12:00

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.