5

I'm working on a Node.js app and I'd like to use some basic SharePoint services inside the app.
I've already done this using java and SOAP web services (copy, list, search) And now I'd like to do the same thing in node.js and RESTful web services.
Is there a good API wrapper you could recommend or some sample code for using SharePoint-REST-API ?
(I'm new to RESTful services)

I'm also working on SharePoint 2013 and SharePoint Online and would like to use oAuth2 for both of them, is that possible ?

8

It depends heavily on your requirements and on the app type you are going to build (web application or just console daemon, azure function, etc.). Does it require user context or not?

Here are the options available:

  1. Create Azure AD application, give required permissions to SharePoint and use node-adal library for OAuth (authorization code flow, client creds flow). Works only with Azure AD apps, you may have user context (authorization code flow) or application only permissions with client creds flow. Works for SharePoint online only.
  2. Create SharePoint addin. Now you have options depending on your requirements.
    a. For SharePoint online you can try to use passport-sharepoint express middleware for authenticating inside SharePoint. You will get user context. It works only with low-trust addins. b. If user context is not necessary and it's ok to use addin only permissions everywhere in your app, you can use sp-request. It allows you to create access token with client creds flow for both Online and on-premise

For mapping consider PnP-JS-Core, but it doesn't work well with nodejs, because the primary purpose of this library is browser. Hopefully I've created a sample on how you can setup it up for nodejs here - node-pnpjs-sample

UPD
You know, there is no "silver bullet" (especially when we are talking about SharePoint and nodejs). For SharePoint Online I would recommend Azure AD app and node-adal. But you need to think carefully if Azure AD app is acceptable for your requirements. A good starting point in descision will be following article deciding between the SharePoint app model and the Office 365 APIs. If you selected Azure AD for SharePoint online, go ahead with node-adal. If you selected SharePoint addin instead of Azure AD app, then you can use either sp-request or passport-sharepoint (again depending if user context is required or not).

For on-premise (high-trust) I don't know about module similar to passport-sharepoint, so in case if you need user context here, you need to search or implement on your own. If user context isn't required, you can go ahead with sp-request for on-premise.
Since you are not able to decide right now, may be that's worthwhile to spend some trying different options in order to make decision.

Try to answer on the following questions:

  • Is that a nodejs web application or console or desktop or daemon service?
  • Is authentication for users required?
  • Do you need in your app to use user context (run search queries with user identity, separate access to the different parts of the app (or SharePoint) based on the user permissions, list security trimming, etc)?

UDP2
So the problem: nodejs backend service, which requires user context, need to talk with SharePoint as connector between mobile app and SharePoint.

In that case, as your service needs user context and you are not able to interact with user directly (because of service), I think the mobile app need to send you authentication data about the user. This depends on the app implementation. That might be an OAuth access token, a cookie, or any other authentication header the mobile app might use. Of course all communication should be performed via secure https channel.
Your service will attach that authentication data to http request to SharePoint.

| improve this answer | |
  • Thanks for the answer @kai ! I'm actually working on a connector between node.js and SharePoint that my company will integrate into the core of it's app. the company has a lot of clients that use different SharePoint versions and some of them migrated to SharePoint Online, that's why I want it to support both : SharePoint server (distant access) and SharePoint Online. So which method would you recommend ? – Ali Nov 17 '16 at 15:29
  • 1
    Please, look at my updated answer – Sergei Sergeev Nov 17 '16 at 17:31
  • 2
    I fixed the links in your answer. You had two links marked as [5], so I changed one to [6], and updated the text that was supposed to link to that one. – wjervis Nov 17 '16 at 19:04
  • Thanks for the updates. to respond to your questions: 1) my app is a daemon service 2) users are required to use authentication in order to use the front-end app calling the daemon 3) I do need the app to use user context because the user will use the front-end app (Android / IOS ..) to access files on SharePoint and I need to make sure he only sees what his SharePoint Admin authorizes him to see. – Ali Nov 18 '16 at 15:31
  • @alioss Let me clarify: You have the front-end app (mobile) your company owns, and you are building nodejs service (connector) between this app and SharePoint, right? – Sergei Sergeev Nov 18 '16 at 15:43
0

I've seen a few REST wrappers for Node.js, some from this Stack Exchange post in March. Is there anything in particular you'd like to accomplish?

node-sharepoint-rest - How to use

csom-node

sp-request

| improve this answer | |
0

In addition to the other answers here, something you might be interested in, as you have asked for an API wrapper for the SharePoint REST services, is:

the BRAVO Core Library

which is exactly that. They have wrapped the SP REST service calls in an API that has a syntax much more similar to server side C# code, or Powershell.

[As an aside: that's one of the ways I use it. If I do not have remote access to a SharePoint server, and need to do something I would normally turn to Powershell for (usually just exploratory stuff), I will create a blank Wiki page on the site, upload the BRAVO Core Library somewhere, link to the script on the page, open the page in a browser (loading the script), and open the browser dev tools. I can then do "Powershell via REST" in the browser console window. Super handy.]


Edit: Just saw that he reworked the whole thing in TypeScript. Haven't played around with that yet, but looks interesting.

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.