0

I am working on SharePoint Online. Inside the 'Site Pages' library, I have created a few site Pages and I also create a 'Link' item using the New > Links option. I use the 'Link' to connect to a page in SharePoint. After the link item is created, the Name of the Link is 'sample.Url'. When I click on the link from SharePoint, it takes me to the page associated with the link.

My issue is that, I try to get the items in Site Pages library using Rest API and display as a tree view in my SPFx web part. But inside the web part, if I click on the link, it just download the page.

Can any one help to resolve the issue. Is there any way I can use REST API to get the actual URL I gave in SharePoint while creating the field?

This is the API I used to get the items

const url = subPageUrl + "/_api/web/lists/getbytitle('Site%20Pages')/items?$select=Title,FileDirRef,File_x0020_Type,EncodedAbsUrl,FileRef,FileLeafRef"
3
  • Can you show us the code generated in the browser by the SPFX part for the link to the Site Page? Thanks Jun 23 at 4:58
  • Which endpoint are you using to fetch the site page items? can you show us the code you used or the response you get from API call? Jun 23 at 5:18
  • I updated the question with the API I used
    – Treesa
    Jun 24 at 1:36

2 Answers 2

2

You can use below endpoint to get the actual web page URL you provided while creating a link page:

<siteUrl>/_api/SP.Utilities.ShortcutLink.GetShortcutLink(@a1)?@a1='https://tenant.sharepoint.com/sites/siteName/SitePages/googlehome.url'

Where @a1 is the URL of shortcut link name, like sample.Url in your case.

Sample output:

<m:properties>
    <d:siteId m:type="Edm.Guid">00000000-0000-0000-0000-000000000000</d:siteId>
    <d:uniqueId m:type="Edm.Guid">00000000-0000-0000-0000-000000000000</d:uniqueId>
    <d:url>http://google.com/</d:url>
    <d:webId m:type="Edm.Guid">00000000-0000-0000-0000-000000000000</d:webId>
</m:properties>

Where url is the actual web page URL you provided while creating a link page.

2
  • 1
    Thanks! I am able to get the Url using this API. Just wanted to ask one more thing, because i am getting the items inside the Site Page library using the below API <siteurl> + "/_api/web/lists/getbytitle('Site%20Pages')/items?$select=*" Is there any way i can get this shortcut link using the select keyword?
    – Treesa
    Jun 24 at 1:22
  • I think you got the answer already. Glad you found the solution. Jun 24 at 4:19
0

Thanks for your answers! I managed to get the shortcut link using the same API

  const url =
  subPageUrl +
  "/_api/web/lists/getbytitle('Site%20Pages')/items?$select=Properties/vti_x005f_shortcuturl&$expand=Properties"

This gives me the url and also the shortcut link.

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.