Does PnP JS plan to support SharePoint REST API v2?
We have discussed it. Right now most of that is available through the graph package - which lacks documentation currently. Do you think it makes sense to bring that into the sp library via the v2 interface? Certainly not against it, and with selective imports folks wouldn't be impacted by larger library size unless they chose to use it. What are your thoughts? Are we missing anything that you want to use in v2?
Yes, I think it would be good to have a dedicated SP library for that. At least, nobody will be confused by the fact that SP-only project uses Graph library to make requests to SharePoint endpoints.
I am not sure if something is really missing, but sometimes I cannot get some parts work (yes, you are absolutely right about documentation). Currently, for example, I am struggling with JSON batching for SharePoint REST API v2. I hope that /api/v2.0/$batch endpoint supports JSON the same way as Graph do. But it always returns the error "invalidRequest: The request is malformed or incorrect." while another request for the same data (and to the same v2 batch endpoint) by using "old style" format (with content type multipart/mixed and raw text body) works fine.
So, in this case, seems like I can use @pnp/graph and @pnp/odata with updated base URL to fetch the data in batches as needed because all the things for building such non-JSON batch queries and parsing their responses are already implemented in the library, right? However, I still cannot realise how to do it. It would be really helpful if you provide an example. Could you please?
My understanding of the v2 api's is that they are the basis for the Graph calls. We do support and will continue to support graph calls directly and I'm not sure I see the benefit in adding yet another layer to this already complex library unless there is specific functionality that exists in the V2 endpoint that wasn't yet exposed by the official Graph endpoints
This statement...
nobody will be confused by the fact that SP-only project uses Graph library to make requests to SharePoint endpoints.
implies Graph is a product completely separate from SharePoint when in reality its a more standardized interface to Microsoft 365 data (although an incomplete one), SharePoint just being one of them vs the older V1 endpoints that have a more customized implementation of RESTful standards (that might even be too generous a description).
So all of that said, I would think to answer your question above you would really either want to use V1 batching or use the Graph batching directly. Our need to provide an example of how to use Graph batching is something we can work on.
The main benefit I see of using the SP v2 REST API/Graph in the context of SharePoint was in the area of list items, in that it expanded some of the field types that the v1 SP REST API didn't.
The v1 RenderListDataAsStream API does a similar thing I think, so perhaps there is little enough overlap in use-cases that it would add confusion to the library to introduce a v2 API also?
Plus as @juliemturner says it shouldn't be confusing to developers to be faced with a SharePoint project that also uses the Graph API - you pick the best API for the task at hand?
My understanding of the v2 api's is that they are the basis for the Graph calls.
Exactly. My understanding is the same. However, the point is that our solution works with SharePoint data and is located on SharePoint page so we already have an appropriate context to make queries directly. As per documentation:
_In scenarios where a solutions already have access tokens available to access SharePoint content, it's possible to access the REST API nativly within SharePoint instead of calling via the Microsoft Graph API._
Plus, we want to be ready to migrate to Graph later if needed.
Thank you for the detailed explanations, Julie!
Most helpful comment
My understanding of the v2 api's is that they are the basis for the Graph calls. We do support and will continue to support graph calls directly and I'm not sure I see the benefit in adding yet another layer to this already complex library unless there is specific functionality that exists in the V2 endpoint that wasn't yet exposed by the official Graph endpoints
This statement...
implies Graph is a product completely separate from SharePoint when in reality its a more standardized interface to Microsoft 365 data (although an incomplete one), SharePoint just being one of them vs the older V1 endpoints that have a more customized implementation of RESTful standards (that might even be too generous a description).
So all of that said, I would think to answer your question above you would really either want to use V1 batching or use the Graph batching directly. Our need to provide an example of how to use Graph batching is something we can work on.