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

%3CLINGO-SUB%20id%3D%22lingo-sub-485382%22%20slang%3D%22en-US%22%3ESharepoint%20framework%2C%20how%20to%20get%20Item%20(Library%20Page)%20URL%20and%20Views%20Count%20using%20context.spHttpClient%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-485382%22%20slang%3D%22en-US%22%3E%3CP%3EWe%20are%20building%20a%20%22pages%20summary%20web%20part%22%20that%20shows%20the%20main%20informations%20inside%20a%20given%20List%20(Library%20Page).%20For%20every%20Item%20I%20need%20to%20retrieve%20its%20URL%20and%20its%20Views%20Counter.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EUsing%20Sharepoint%20Framework%2C%20I%20was%20able%20to%20retrieve%20Title%2C%20Description%2C%20BannerImageURL%2C%20but%20I%20can't%20get%20the%20Item%20URL%20or%20Views%20Counter.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EMy%20code%20looks%20like%3A%3C%2FP%3E%3CDIV%3E%3CDIV%3E%26nbsp%3B%3C%2FDIV%3E%3CDIV%3E%26nbsp%3B%3CP%3Eprivate%20_getListData()%3A%20Promise%20%26lt%3B%20ISPLists%20%26gt%3B%20%7B%3CBR%20%2F%3E%C2%B7%C2%B7%C2%B7%C2%B7%C2%B7return%20this.context.spHttpClient.get(this.context.pageContext.web.absoluteUrl%20%2B%20%60%2F_api%2Fweb%2Flists%2Fgetbytitle('LibName')%2Fitems%3Fselect%3DID%2CTitle%2CSection%2CTopic%2CDescription%2CBannerImageUrl%60%2C%20SPHttpClient.configurations.v1)%3CBR%20%2F%3E%C2%B7%C2%B7%C2%B7%C2%B7%C2%B7.then((response%3A%20SPHttpClientResponse)%20%3D%26gt%3B%20%7B%3CBR%20%2F%3E%C2%B7%C2%B7%C2%B7%C2%B7%C2%B7%C2%B7%C2%B7%C2%B7%C2%B7%C2%B7return%20response.json()%3B%3CBR%20%2F%3E%C2%B7%C2%B7%C2%B7%C2%B7%C2%B7%7D)%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%C2%B7%C2%B7%C2%B7%C2%B7%C2%B7private%20_renderList(items%3A%20ISPList%5B%5D)%3A%20void%20%7B%3CBR%20%2F%3E%C2%B7%C2%B7%C2%B7%C2%B7%C2%B7let%20html%3A%20string%20%3D%20''%3B%3CBR%20%2F%3E%C2%B7%C2%B7%C2%B7%C2%B7%C2%B7items.forEach((item%3A%20ISPList)%20%3D%26gt%3B%20%7B%3CBR%20%2F%3E%C2%B7%C2%B7%C2%B7%C2%B7%C2%B7%C2%B7%C2%B7%C2%B7%C2%B7%C2%B7html%20%2B%3D%20%60%3CBR%20%2F%3E%C2%B7%C2%B7%C2%B7%C2%B7%C2%B7%C2%B7%C2%B7%C2%B7%C2%B7%C2%B7%3C%2FP%3E%3CDIV%3E%3CBR%20%2F%3E%C2%B7%C2%B7%C2%B7%C2%B7%C2%B7%C2%B7%C2%B7%C2%B7%C2%B7%C2%B7%C2%B7%C2%B7%C2%B7%C2%B7%C2%B7%3CA%20href%3D%22%24%7B%26lt%3BSTRONG%22%20target%3D%22_blank%22%20rel%3D%22nofollow%20noopener%20noreferrer%22%3Eitem.PageURL%7D%26gt%3B%3CBR%20%2F%3E%C2%B7%C2%B7%C2%B7%C2%B7%C2%B7%C2%B7%C2%B7%C2%B7%C2%B7%C2%B7%C2%B7%C2%B7%C2%B7%C2%B7%C2%B7%C2%B7%C2%B7%C2%B7%C2%B7%3CIMG%20aria-hidden%3D%22%26quot%3Btrue%26quot%3B%22%20role%3D%22%26quot%3Bpresentation%26quot%3B%22%20src%3D%22%24%7Bitem.BannerImageUrl.Url%7D%22%20%2F%3E%3CBR%20%2F%3E%C2%B7%C2%B7%C2%B7%C2%B7%C2%B7%C2%B7%C2%B7%C2%B7%C2%B7%C2%B7%C2%B7%C2%B7%C2%B7%C2%B7%C2%B7%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FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3Eobviously%3CSTRONG%3E%20item.PageURL%26nbsp%3B%3C%2FSTRONG%3Eand%26nbsp%3B%3CSTRONG%3Eitem.viewcount%26nbsp%3B%3C%2FSTRONG%3Edo%20not%20exist%2C%20I'm%20writing%20them%20in%20order%20to%20explain%20what%20I'm%20looking%20for.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EAny%20ideas%20about%20how%20to%20reach%20the%20URL%20and%20the%20View%20Counts%3F%3C%2FP%3E%3C%2FDIV%3E%3C%2FDIV%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3C%2FDIV%3E%3C%2FLINGO-BODY%3E%3CLINGO-LABS%20id%3D%22lingo-labs-485382%22%20slang%3D%22en-US%22%3E%3CLINGO-LABEL%3EAPIs%3C%2FLINGO-LABEL%3E%3CLINGO-LABEL%3EDeveloper%3C%2FLINGO-LABEL%3E%3C%2FLINGO-LABS%3E
New 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>
··········<div>
···············<a href=${item.BannerImageUrl.Url}>
····················<h2>${item.Title}</h2>
···············</a>
···············<div>
····················<p>${item.Description}</p>
···············</div>
···············<div>
····················<h3>Department: ${item.Section} - ${item.Created}</h3>
···············</div>
···············<div>
····················<h5>${item.viewcount} visualizaciones</h5>
···············</div>
··········</div>
····· `;}
·····}

 

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