spacer
Skip to content

@pnp/graph/insights

This module helps you get Insights in form of Trending, Used and Shared. The results are based on relationships calculated using advanced analytics and machine learning techniques.

IInsights

Invokable Banner Selective Imports Banner

Scenario Import Statement
Selective import { graph } from "@pnp/graph";
import "@pnp/graph/insights";
Preset: All import "@pnp/graph/presets/all";

Returns documents from OneDrive and SharePoint sites trending around a user.

import { graph } from "@pnp/graph";
import "@pnp/graph/insights";
import "@pnp/graph/users";

const trending = await graph.me.insights.trending()

const trending = await graph.users.getById("userId").insights.trending()

Using the getById method to get a trending document by Id.

import { graph } from "@pnp/graph";
import "@pnp/graph/insights";
import "@pnp/graph/users";

const trendingDoc = await graph.me.insights.trending.getById('Id')()

const trendingDoc = await graph.users.getById("userId").insights.trending.getById('Id')()

Using the resources method to get the resource from a trending document.

import { graph } from "@pnp/graph";
import "@pnp/graph/insights";
import "@pnp/graph/users";

const resource = await graph.me.insights.trending.getById('Id').resource()

const resource = await graph.users.getById("userId").insights.trending.getById('Id').resource()

Get all Used documents

Returns documents viewed and modified by a user. Includes documents the user used in OneDrive for Business, SharePoint, opened as email attachments, and as link attachments from sources like Box, DropBox and Google Drive.

import { graph } from "@pnp/graph";
import "@pnp/graph/insights";
import "@pnp/graph/users";

const used = await graph.me.insights.used()

const used = await graph.users.getById("userId").insights.used()

Get a Used document by Id

Using the getById method to get a used document by Id.

import { graph } from "@pnp/graph";
import "@pnp/graph/insights";
import "@pnp/graph/users";

const usedDoc = await graph.me.insights.used.getById('Id')()

const usedDoc = await graph.users.getById("userId").insights.used.getById('Id')()

Get the resource from Used document

Using the resources method to get the resource from a used document.

import { graph } from "@pnp/graph";
import "@pnp/graph/insights";
import "@pnp/graph/users";

const resource = await graph.me.insights.used.getById('Id').resource()

const resource = await graph.users.getById("userId").insights.used.getById('Id').resource()

Get all Shared documents

Returns documents shared with a user. Documents can be shared as email attachments or as OneDrive for Business links sent in emails.

import { graph } from "@pnp/graph";
import "@pnp/graph/insights";
import "@pnp/graph/users";

const shared = await graph.me.insights.shared()

const shared = await graph.users.getById("userId").insights.shared()

Get a Shared document by Id

Using the getById method to get a shared document by Id.

import { graph } from "@pnp/graph";
import "@pnp/graph/insights";
import "@pnp/graph/users";

const sharedDoc = await graph.me.insights.shared.getById('Id')()

const sharedDoc = await graph.users.getById("userId").insights.shared.getById('Id')()

Get the resource from a Shared document

Using the resources method to get the resource from a shared document.

import { graph } from "@pnp/graph";
import "@pnp/graph/insights";
import "@pnp/graph/users";

const resource = await graph.me.insights.shared.getById('Id').resource()

const resource = await graph.users.getById("userId").insights.shared.getById('Id').resource()