Hi
How to call sharepoint restful api by pnp library? There is something not include in the pnp library, so i want to call the restful api directly.
thanks
From Peter
Hi @peterremote1980,
SPHttpClient is a help in such a case:
import { SPHttpClient } from '@pnp/sp';
const client = new SPHttpClient();
// client.get | client.post to custom endpoints
Client instance is a customized fetch client which adds some SharePoint-aware goodies.
@peterremote1980, it would also be useful to know which REST endpoint you are trying to call which isn鈥檛 in the library so it could be added.
Hi
/_vti_bin/homeapi.ashx/sites/followed
/_vti_bin/homeapi.ashx/sites/suggested
@sympmarc , I have been trying to use pnp graph to call other MS graph APIs that are not available in pnp graph module e.g. https://graph.microsoft.com/v1.0/me/calendar/getschedule. It seems the graph capability in pnp does not cover all MS graph APIs? We want to use pnp library for all our API calls so that we can leverage pnp logging module to log errors. I tried using SPHttpClient to make call to the aforementioned API but the listener could not track or report the error. Please what is the best way to do this?
@saregbesola - it comes down to time for folks to extend the API to support new calls. If you have a need for one that isn't implemented you can certainly submit a PR. Otherwise, opening an issue and requesting more coverage of specific methods lets us know there is a need. You can also always extend the objects in your projects or do something like:
import { graph, GraphQueryableInstance } from "@pnp/graph";
// create a new queryably based on a base already supported
// explicitly set the additional path
const query = new GraphQueryableInstance(graph.me, "calendar/getschedule");
// invoke get as normal
const result = await query.get();
If there are APIs you would like supported please open an issue listing them so we are aware there is a need.
@patrick-rodgers , thanks for this. I have found a way to handle exceptions for other APIs that are not currently supported by using Logger.log in the catch exception to log to my subscriber listener. But a quick question, does GraphQueryableInstance support a post action? I couldn't use it for the getschedule API as that operation is a post action.
There is a post method, but it is protected. This will change in v2, but for now you can either subclass GraphQueryableInstance and call it (the original design idea) OR case the object to any and invoke it
(<any>obj).postCore();, You can look at other methods such as here to see what you can pass to post.
@patrick-rodgers , thanks! Your help is well appreciated. I will take a look at it.
Most helpful comment
@saregbesola - it comes down to time for folks to extend the API to support new calls. If you have a need for one that isn't implemented you can certainly submit a PR. Otherwise, opening an issue and requesting more coverage of specific methods lets us know there is a need. You can also always extend the objects in your projects or do something like:
If there are APIs you would like supported please open an issue listing them so we are aware there is a need.