Search code examples
office365sharepoint-onlineonedrive

OneDrive For Business: How do I overcome the MaxUrlLength issue while accessing an item by its path?


My main objective is to retrieve the ID of a file.

The scenario is as follows

  • I need to access the meta data for a file and I only have the file path (I can't use the /drive/items/{item-id} method)

  • When the path gets too big, I am unable to access the metadata.

https://tenant-my.sharepoint.com/personal/some_user_some_domain_elasticadev_com/_api/v2.0/drive/root:/mauze/test/This is supposed/This is really supposed to be a really long name for a folder which normally isn't the case!/SomeName-123456789012345678901234567890123456789012345678901234567890123456789012.txt

The error

401 Unauthorized

The length of the URL for this request exceeds the configured maxUrlLength value.

When using Sharepoint Online APIs, I used to cater this issue by using the URL parameters like

https://tenant-my.sharepoint.com/personal/user_account_tenant_onmicrosoft_com/_api/web/getfilebyserverrelativeurl(@v)/startupload(uploadId=guid'bla-bla')?@v='/personal/user_account_tenant_onmicrosoft_com/Documents/Test/reeeaaaaallllyyybiiignameblablblalblalb.txt'

I am unable to use this technique with the OneDrive API. Is there any work around for this?

One side question, I do have the ListItemUniqueId for the file (the UniqueID of the file on Sharepoint) Can I somehow use that to translate it into OneDrive ID? Any facet for this purpose? i.e, the reverse of SharepointIds Facet.


Solution

  • You should be able to use a similar aliasing approach with the OneDrive API, but it may not be as flexible in terms of alias naming.

    https://tenant-my.sharepoint.com/personal/some_user_some_domain_elasticadev_com/_api/v2.0/drive/root:@path?@path='/mauze/test/This%20is%20supposed/This%20is%20really%20supposed%20to%20be%20a%20really%20long%20name%20for%20a%20folder%20which%20normally%20isn''t%20the%20case!/SomeName-123456789012345678901234567890123456789012345678901234567890123456789012.txt'
    

    Having said that, we really should be supporting URLs of that length now so I'll need to follow up to see what's going wrong on that front.