cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
TorreyFalconer
Helper IV
Helper IV

Get drive id for Doc Library selection

Hey all, 

I am using the Excel action 'Create Worksheet' and I would like to make the 'Document Library' property dynamic rather than select it from the dropdown. However it does not accept the Document Library 'Display Name' or Id,  it only seems to accept the 'drive' property.

Does anybody know how to get the 'drive' of a document library? I tried sending an HTTP request to SharePoint but I must have something incorrect.

1 ACCEPTED SOLUTION

Accepted Solutions

UPDATE:
I was able to accomplish this with a work around. 
1) In my HTTP request to SharePoint I used the uri: _api/v2.0/drives

     It then listed all the drives and drive id's on that site

2) Then I used Parse JSON to get the values inside the output Body of the HTTP Request
3)  Then a Filter Array to find the document library I needed (I filtered by name)
4) Then finally I used a Compose with the Id from the Filter array. *Note - Many Ids may be listed from the output so if this helps anyone it is: @{items('Apply_to_each')?['id']} 

And of course I set this as a variable because that was a bit of a ridiculous process to get one id. 
So, a bit nuts, but it works if you are having the trouble with the _api/v2.0/drive/root:/<FileName> uri as I was.

I believe this is all much easier to achieve using the Microsoft Graph api if you are registered
But, I hope this helps anyone with the same issue. 


Thanks for your guidance and help @annajhaveri!

View solution in original post

11 REPLIES 11
annajhaveri
Super User
Super User

@TorreyFalconer  are you also providing the dynamic file name, in the excel actions of Power Automate, we cant simply provide the library and filename as their actual names, we need to fetch the drive id and file id and use it in the Create Worksheet action, please see below steps on how to do it:

 

1. Add 'Send an HTTP request to SharePoint' action to the flow and configure it was follows:

annajhaveri_0-1615557284416.png

Uri should be _api/v2.0/drive/root:/<filename>

here replace <filename> with a variable or the actual file name e.g. book1.xlsx

 

2. Then add Compose action and configure following expression in this compose action

outputs('Send_an_HTTP_request_to_SharePoint')?['body']['Id']

annajhaveri_1-1615557388048.png

 

3. Now again add Compose action and configure following expression in this compose action

outputs('Send_an_HTTP_request_to_SharePoint')?['body']['parentReference']['driveId']

annajhaveri_2-1615557487411.png

 

4. Then in Create Worksheet action configure it as follows, use compose action output in the Document library and file name parameters, as shown in screenshot below

annajhaveri_3-1615557637797.png

 

 

Regards,
Anna Jhaveri

If I have answered your question, please mark the post as Solved to help other users to identify the correct answer
If you like my response, please give it a Thumbs Up.

Thanks! 

I think this will work but I am still getting a 400 error at the moment with my HTTP request Uri. 
It just says that it got an unexpected response from the request. 


I have my Uri input: 

_api/v2.0/drive/root:/book1.xlsx

 I tried it various ways using a variable, the actual file name etc. (I even tried using the doc library name instead) but still get the same error.
Any thoughts?

@TorreyFalconer  could you please let me know following:

 

1. Excel file name in which you want to create the worksheet? 

2. Document library in which file exists

3. Is file added directly under document library or under a folder, if under folder can you share the folder path

 

With these answers i can help you to figure out what will the Uri in your case

Regards,
Anna Jhaveri

If I have answered your question, please mark the post as Solved to help other users to identify the correct answer
If you like my response, please give it a Thumbs Up.

Hey!

 

File Name: 2021-03_PersonCount.xlsx

Document Library: Meeting Attendance 
Not under a folder, directly in the document library!

 

Hope that helps!

UPDATE:
I was able to accomplish this with a work around. 
1) In my HTTP request to SharePoint I used the uri: _api/v2.0/drives

     It then listed all the drives and drive id's on that site

2) Then I used Parse JSON to get the values inside the output Body of the HTTP Request
3)  Then a Filter Array to find the document library I needed (I filtered by name)
4) Then finally I used a Compose with the Id from the Filter array. *Note - Many Ids may be listed from the output so if this helps anyone it is: @{items('Apply_to_each')?['id']} 

And of course I set this as a variable because that was a bit of a ridiculous process to get one id. 
So, a bit nuts, but it works if you are having the trouble with the _api/v2.0/drive/root:/<FileName> uri as I was.

I believe this is all much easier to achieve using the Microsoft Graph api if you are registered
But, I hope this helps anyone with the same issue. 


Thanks for your guidance and help @annajhaveri!

View solution in original post

@TorreyFalconer  the reason why below Uri input did not work for is because your document library name is Meeting Attendance , the below Uri works for default Documents library of the site. If not using default documents library then the solution that you provided is correct, which worked for your scenario

_api/v2.0/drive/root:/book1.xlsx

 

Regards,
Anna Jhaveri

If I have answered your question, please mark the post as Solved to help other users to identify the correct answer
If you like my response, please give it a Thumbs Up.

I configured it exactly like that and it did not work. Glad I found a work around though! 

@TorreyFalconer I just meant to explain why it didnt work for your scenario. I hope that makes sense.

Regards,
Anna Jhaveri

If I have answered your question, please mark the post as Solved to help other users to identify the correct answer
If you like my response, please give it a Thumbs Up.

@annajhaveri it did! Thank you very much for the help!

klee7777
Frequent Visitor

Hi @annajhaveri  / @TorreyFalconer 

I tried both ways:

klee7777_0-1628859270616.png

But both HTTP Get actions failed with "Unexpected response from the service
clientRequestId: 6afea342-387b-4c35-ba2b-28bc1b1837d0
serviceRequestId: d11be59f-a0f6-c000-47d7-b2029fb9b849"

 

So, I couldn't even proceed to the next step. How were you able to pass that action?

What is the syntax if the file is located in a folder and not directly under the document library.  The document library is TestLib and the folder is Output.

Helpful resources

Announcements
UG GA Amplification 768x460.png

Launching new user group features

Learn how to create your own user groups today!

Community Connections 768x460.jpg

Community & How To Videos

Check out the new Power Platform Community Connections gallery!

M365 768x460.jpg

Microsoft 365 Collaboration Conference | December 7–9, 2021

Join us, in-person, December 7–9 in Las Vegas, for the largest gathering of the Microsoft community in the world.

Top Solution Authors
Users online (2,827)