I have a file in a Document Library. I can reach that file with a direct URL in the form https://[tenant].sharepoint.com/sites/[site_name]/[Document_Library]/[Sub_Folder]/document.pdf

Now what I'm trying to do is create a List View Command Set that will post the document to an API, something like: Request.addFileByUrl('....') and pass the URL of the document as a parameter.

The problem is, I get a message "LinkKind cannot be Direct or Uninitialized". I've played around with some of the admin sharing settings to no avail. So my question is, is there a way to allow access to a direct URL temporarily or even somehow get the original document from the share link? Is there an option to integrate that method into a Command Set extension? (I am using the pnp/sp library at the moment to get the links)

Thank you for your help


Here's the code that I am using to get the share link from my List View Command Set:

    let getLink = await sp.web.getFileByServerRelativePath(filePath).getShareLink(SharingLinkKind.Direct, dateAdd(new Date(), "minute", 20));
    let url: string = getLink.sharingLinkInfo.Url; 

Now obviously the SharingLinkKind.Direct is the line that is giving me the error message, but I don't know how to work around it.

  • can you please share your code for List View Command set? Jun 30, 2023 at 5:31
  • @KalpeshVaghela not sure how much this helps but there you go..
    – whaleiam
    Jul 1, 2023 at 1:37
  • Is there any specific reason why you want Sharing Link Url? Would absolute URL (https://[tenant].sharepoint.com/sites/[site_name]/[Document_Library]/[Sub_Folder]/document.pdf) work for your custom API i.e. Request.addFileByUrl? Jul 1, 2023 at 5:51
  • @KalpeshVaghela So the getShareLink(SharingLinkKind.Direct) gets me the absolute url which you can extract from the second line of code I showed. However, in order to access the absolute url as an external user, or an API, there needs to be authorization. I'm looking to bypass this somehow so that the API can have access to the file contents
    – whaleiam
    Jul 1, 2023 at 6:05

1 Answer 1


The issue you're experiencing with the "LinkKind cannot be Direct or Uninitialized" message is likely due to the permissions and sharing settings of the document in SharePoint. By default, direct access to files in a SharePoint document library via a direct URL may be restricted.

To enable access to the direct URL temporarily or obtain the original document from the shared link, you can try the following options:

Go to the SharePoint document library where the file is located. Select the file and click on the "Share" button or ellipsis (...) menu to open the sharing options.

In the sharing settings, make sure the file is shared with appropriate permissions.

Check the "Anyone with the link" option to allow anonymous access to the file. Save the changes and test accessing the file using the direct URL again.

  • Thank you for your response. Unfortunately, sharing using that method doesn't give me the direct url right way. It does, however, give me the share link which is of the form https://[tenant].sharepoint.com/:i:/s/[Document Library]/ETV...?e Once you've opened this link, then you are permitted to view the direct url of a file which is not what I want. I need to be able to access the file's absolute url to pass as a parameter to send the file to an API.
    – whaleiam
    Jul 4, 2023 at 0:58

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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