1

I'm creating a folder inside library via rest and as next step I search it again via

/_api/web/lists/getbytitle('{docLibraryName}')/Items?$filter=(OpportunityNumber eq '{folderName}')&$top=1

to get Edit url in a form

_api/Web/Lists(guid'293c51c7-0628-4fb4-85a4-8bc484efed86')/Items(128)

as only this url which has List guid and numeric ID of a folder allows me to do post to update its metadata.

problem is first query returns me guid (after placing index on it) of the folder and not numeric value

...<id>66c976c3-c1b1-4aa4-88c0-57e0c333052d</id>...

Is there a way to get numeric ID of a folder by its guid, or do the whole process in less steps, note I've tried

_api/Web/Lists(guid'07580897-2148-40a7-8464-87009e98183c')/GetItemByUniqueId(guid'66c976c3-c1b1-4aa4-88c0-57e0c333052d')

does not work and returns 'Value does not fall within the expected range.'

1
  • What is OpportunityNumber column here? You want item ID for a folder? – Ganesh Sanap Apr 30 at 3:25
1

To create a folder and get its ID in one request, you can simply create a list item with a folder content type (0x0120):

POST request

/_api/web/lists/getByTitle('Custom List')/items

Body

ContentTypeId: "0x0120"
Title: "FolderName"
__metadata: {type: "SP.Data.CustomListListItem"}
type: "SP.Data.TListItem"

Response

...
ID: 1
Id: 1
Title: "FolderName"
odata.id: "1c6a9c3a-2598-486a-8158-cf45d0503fd6"
...

Returned ID is the folder's item ID.

1

You can use the $select parameter to select the folder ID like below:

/_api/Web/Lists/getByTitle('Documents')/items?$select=FileLeafRef,ID

This will return you the folder name & ID like:

<content type="application/xml">
    <m:properties>
        <d:FileLeafRef>folder2</d:FileLeafRef>
        <d:ID m:type="Edm.Int32">33</d:ID>
    </m:properties>
</content>

You can modify your REST call something like:

/_api/web/lists/getbytitle('{docLibraryName}')/Items?$select=FileLeafRef,ID,OpportunityNumber&$filter=(OpportunityNumber eq '{folderName}')&$top=1

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.