cancel
Showing results for 
Search instead for 
Did you mean: 

Ms Graph SharePoint - Check File Exist action

AP.Philippa
Level 5

Hi BP community,

We recently have implemented the SharePoint Graph api and already have made some custom actions. Now we are trying to create an action similar to the “Check File Exists” from the File Management Utility. With the current “Get Drive Item” action we are able to get the files within a specific folder, however we still have to loop through the whole collection and this is not really efficient.

We have tried creating a custom action using the following get request (relative file path should also include the file name and extension): “https://graph.microsoft.com/v1.0/sites/[SiteId]/drives/[DriveId]/root:/[Relative File Path]”. This action does work when the file exists, however will throw a 404 error when the file does not exists, resulting in no output and thus is not an ideal solution.

 

Do any of you guys have experience or an idea on how we could create a custom api action similar to the Check File Exist action? Ideally we would like the action to output a flag data item to indicate whether the file exist within a particular folder on SharePoint.


Many thanks in advance!

With kind regards,

Arthur Philippa

3 REPLIES 3

ewilson
Staff
Staff
Hi @AP.Philippa,

As far as I know, the two options you've described above are it. On the direct access URL you could always wrap the call in a Block, capture the exception, and then when you see that it's a 404 you know the file doesn't exist.

Cheers,
Eric​

AP.Philippa
Level 5
Hi @ewilson,

Thanks for your swift and conceise response!

Do you know if it would be possible to catch errors like "404 - resource not found" within the output of the api action?

This question came to bare as I have noticed that you can write custom code within the output of an API action.
When it would be possible to catch these errors, I think it should be able to output a flag that outputs true or false.

I look forward to your response!

With kind regards,

Arthur

ewilson
Staff
Staff
Hi @AP.Philippa,

Unfortunately there's no way to catch the exception within the WebAPI itself (even within the custom code for response handling). You have to wrap the actual stage in the calling process and then handle it. I have raised this with the product team in the past. I'm not sure if they will ever change the behavior though.

Cheers,
Eric​