Forum Discussion
Siddheshwar
Nov 25, 2018Copper Contributor
How to fetch Save for later pages in SPFx Web part.
Hi, Microsoft rolled out new feature 'save for later' for modern pages. Once Save for later is clicked, it becomes Saved for later, and the associated icon is filled in. When Saved for later i...
- Jan 24, 2019
The json payload returned from:
/_api/sphomeservice/context?$expand=Token
includes a node named:
resource
which seems to show the complete hostname of the sphome.svc.ms to use.
You rightly point out this is not a documented API, so I wouldn't use it in any production code.
Siddheshwar
Nov 26, 2018Copper Contributor
Hi,
I found the way. here is the code snippet:
private async _getApiToken() : Promise<string> {
const siteCollectionUrl = this.props.context.pageContext.web.absoluteUrl;
const restQuery = `${siteCollectionUrl}/_api/sphomeservice/context?$expand=Token`;
const httpClientOptions: ISPHttpClientOptions = {};
const response: SPHttpClientResponse = await this.props.context.spHttpClient.fetch(restQuery, SPHttpClient.configurations.v1, httpClientOptions);
const responseJson: any = await response.json();
return responseJson.Token.access_token;
// Improvement: Grab the Hub api URL from: responseJson.Urls
}
private async _getsavedForLaterPages(): Promise<void> {
const isHubSite = await this._isHubSite();
if (!isHubSite) return;
const token = await this._getApiToken();
const restQuery = `https://{region}-sphomep.svc.ms/api/v1/documents/saveForLater?start=0&count=100`;
const httpClientOptions: IHttpClientOptions = {
headers: {
'authorization': `Bearer ${token}`,
'sphome-apicontext': `{"PortalUrl":"${this.props.context.pageContext.site.absoluteUrl}"}`
}
};
const response: HttpClientResponse = await this.props.context.httpClient.fetch(restQuery, SPHttpClient.configurations.v1, httpClientOptions);
const responseJson: any = await response.json();
console.log("Saved for later data:"+responseJson);
}
Thank You,
Siddheshwar Kohale
- SiddheshwarJan 16, 2019Copper Contributor
Hi All,
As I'm using undocumented service to get the save for later pages data.
But after some day this functionality stopped working so I to find root cause I debugged the source code and found that region {northeurope4} mentioned the service get keep changing after some days.
https://northeurope4-sphomep.svc.ms/api/v1/documents/saveForLater?start=0&count=100
I don't know why it's changing so frequently , is there any way out to resolve this kind of issue?
Thank You.
Siddheshwar
- Mark PowneyJan 24, 2019Copper Contributor
The json payload returned from:
/_api/sphomeservice/context?$expand=Token
includes a node named:
resource
which seems to show the complete hostname of the sphome.svc.ms to use.
You rightly point out this is not a documented API, so I wouldn't use it in any production code.