Sharepoint framework, how to get Item (Library Page) URL and Views Count using context.spHttpClient

Copper Contributor

We are building a "pages summary web part" that shows the main informations inside a given List (Library Page). For every Item I need to retrieve its URL and its Views Counter.


Using Sharepoint Framework, I was able to retrieve Title, Description, BannerImageURL, but I can't get the Item URL or Views Counter.


My code looks like:


private _getListData(): Promise < ISPLists > {
·····return this.context.spHttpClient.get(this.context.pageContext.web.absoluteUrl + `/_api/web/lists/getbytitle('LibName')/items?select=ID,Title,Section,Topic,Description,BannerImageUrl`, SPHttpClient.configurations.v1)
·····.then((response: SPHttpClientResponse) => {
··········return response.json();



·····private _renderList(items: ISPList[]): void {
·····let html: string = '';
·····items.forEach((item: ISPList) => {
··········html += `
··········<div >
···············<a href=${item.PageURL}>
···················<img aria-hidden="true" role="presentation" src=${item.BannerImageUrl.Url}>
···············<a href=${item.BannerImageUrl.Url}>
····················<h3>Department: ${item.Section} - ${item.Created}</h3>
····················<h5>${item.viewcount} visualizaciones</h5>
····· `;}


obviously item.PageURL and item.viewcount do not exist, I'm writing them in order to explain what I'm looking for.


Any ideas about how to reach the URL and the View Counts?




0 Replies