Pnpjs: how to call other graph endpoints?? like /v1.0/search

Created on 17 Dec 2020  路  5Comments  路  Source: pnp/pnpjs

Category

  • [ ] Enhancement
  • [ ] Bug
  • [x] Question
  • [ ] Documentation gap/issue

Version

Please specify what version of the library you are using: [2.0.12]

Expected / Desired Behavior / Question

I am trying to call endpoint like https://graph.microsoft.com/v1.0/search/query. I am not able find any method or function which can do this. Also in future if I need to call anyother endpoint how can it be done?

code complete enhancement

Most helpful comment

You can always build out queries such as:

import { graph, GraphQueryableCollection, graphPost } from "@pnp/graph";
import { body } from "@pnp/odata";

const query = GraphQueryableCollection("https://graph.microsoft.com/v1.0", "search/query");

const result = await graphPost(query, body({
    "requests": [
        {
            "entityTypes": [
                "site"
            ],
            "query": {
                "queryString": "test"
            }
        }
    ]
}));

We can also look at adding (or accepting a PR) to add additional functionality natively.

All 5 comments

You can always build out queries such as:

import { graph, GraphQueryableCollection, graphPost } from "@pnp/graph";
import { body } from "@pnp/odata";

const query = GraphQueryableCollection("https://graph.microsoft.com/v1.0", "search/query");

const result = await graphPost(query, body({
    "requests": [
        {
            "entityTypes": [
                "site"
            ],
            "query": {
                "queryString": "test"
            }
        }
    ]
}));

We can also look at adding (or accepting a PR) to add additional functionality natively.

thanks @patrick-rodgers do I have to do anything additional for authentication or graph setup... this is what my constructor looks like.... I am using in Teams Bot...

graph.setup({
            graph: {
                fetchClientFactory: () => {
                    return new AdalFetchClient("tenantId", appId, appPassword);
                }
            }
        });
graph.setEndpoint("beta");

I have not tested in a Teams bot - interested to hear what you learn.

@NWH-SAmin5 I would also be interested to hear what toolkit you are using! It's when I started playing with Teams solutions that I started having build issues, as reported in issue #1461.

Added support for graph search in 2.1.0 scheduled to go our Jan 15 2021.

Was this page helpful?
0 / 5 - 0 ratings