# Sharepoint and Node-Red

**URL:** <https://discourse.nodered.org/t/sharepoint-and-node-red/33437>\
**Category:** General\
**Created:** [28 September 2020 07:35 UTC](https://discourse.nodered.org/t/sharepoint-and-node-red/33437 "2020-09-28T07:35:18Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Nxito](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/nxito/32/88293_2.png) [@Nxito](https://discourse.nodered.org/u/Nxito)\
**Post date:** [28 September 2020 07:35 UTC](https://discourse.nodered.org/t/sharepoint-and-node-red/33437/1 "2020-09-28T07:35:18Z")

</div>

i am trying to create a list in sharepoint. Also edit it and upload an image file (or url)  
I've been looking around the web but I found little for node-red or nodejs.  
I got a flow to get an access token and still can't authenticate

Has anyone achieved something with sharepoint and node-red or has experience?

---

<div class="post-metadata">

**Author:** ![pgalbavy](https://avatars.discourse-cdn.com/v4/letter/p/bc79bd/32.png) [@pgalbavy](https://discourse.nodered.org/u/pgalbavy)\
**Post date:** [28 September 2020 12:00 UTC](https://discourse.nodered.org/t/sharepoint-and-node-red/33437/2 "2020-09-28T12:00:31Z")

</div>

Unrelated to node-red but I do recall we tried to do "stuff" at work to access Sharepoint from automated tools and it proved a pain. Not sure if they even made it work. Would be interesting to find out where you get too!

---

<div class="post-metadata">

**Author:** ![TotallyInformation](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/totallyinformation/32/31_2.png) [@TotallyInformation](https://discourse.nodered.org/u/TotallyInformation)\
**Post date:** [28 September 2020 15:28 UTC](https://discourse.nodered.org/t/sharepoint-and-node-red/33437/3 "2020-09-28T15:28:21Z")

</div>

Is this SharePoint Online (Office 365) or on-prem (eg SP 2013)?

Microsoft maintain a whole bunch of tools for working with SharePoint from JavaScript and that is where I'd start. I don't remember ever seeing any nodes.

I'd be interested in following your exploration though. We make very heavy use of SharePoint Online but I have never had time to chase down more than the bare minimum of SP JavaScript.

Refs:

- [https://github.com/SharePoint](https://github.com/SharePoint)
- [https://github.com/pnp](https://github.com/pnp)
- [https://github.com/pnp/pnpjs](https://github.com/pnp/pnpjs)
- [https://github.com/SharePoint-NodeJS](https://github.com/SharePoint-NodeJS)
- [https://github.com/SharePoint-NodeJS/pnp-auth](https://github.com/SharePoint-NodeJS/pnp-auth)

---

<div class="post-metadata">

**Author:** ![Nxito](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/nxito/32/88293_2.png) [@Nxito](https://discourse.nodered.org/u/Nxito)\
**Post date:** [12 November 2020 09:43 UTC](https://discourse.nodered.org/t/sharepoint-and-node-red/33437/4 "2020-11-12T09:43:32Z")

</div>

Using this as a base and viewing the documentation, you can connect to sharepoint with node-red without any more libraries.

```auto
[{"id":"62b10548.ad1b4c","type":"inject","z":"a5f021c7.3b18e","name":"SHAREPOINT","topic":"","payload":"","payloadType":"date","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":260,"y":1640,"wires":[["89f43924.4f4cf8"]]},{"id":"89f43924.4f4cf8","type":"function","z":"a5f021c7.3b18e","name":"Constants","func":"/**\n\t * Metodo para autenticarse en Sharepoint 365 con Client ID y Client Secret\n\t * @param url\n\t * @param clientID\n\t * @param clientSecret\n\n*/\nmsg.Constants = {\n url:\"<YourSite>.sharepoint.com\",\n urlAPI:\"<YourSite>.sharepoint.com/sites/test/_api\",\n clientID:\"7sde6a2e-6334-44re-bb35-36501078s8s8\",\n clientSecret:\"J9oddMNzHToW8EZIoW0VicSOR6EF7cY+dtz3WXfgccc=\",\n list:\"MyTestList\"\n \n}\nreturn msg;","outputs":1,"noerr":0,"x":420,"y":1640,"wires":[["b65732ba.6e9f7"]]},{"id":"b65732ba.6e9f7","type":"http request","z":"a5f021c7.3b18e","name":"Obtenemos el tenant ID","method":"GET","ret":"obj","paytoqs":false,"url":"{{{Constants.url}}}/_vti_bin/client.svc","tls":"","persist":false,"proxy":"","authType":"","x":610,"y":1640,"wires":[["b12d80e8.7f3c5"]],"info":"SI copias este nodo, reasigna el acceso como bearer"},{"id":"b12d80e8.7f3c5","type":"function","z":"a5f021c7.3b18e","name":"\"tenant ID\"","func":"const url=msg.Constants.url\nconst clientID=msg.Constants.clientID\nconst clientSecret=msg.Constants.clientSecret\n\nvar headersArray = msg.headers[\"www-authenticate\"].split(\",\")\nvar bearerRealm = headersArray[0].split(\"\\\"\");\nvar resource = headersArray[1].split(\"\\\"\");\n\nmsg.headers={}\nmsg.url = \"https://accounts.accesscontrol.windows.net/\"+bearerRealm[1]+\"/tokens/OAuth/2\";\nmsg.headers[\"content-type\"] = \"application/x-www-form-urlencoded\";\nmsg.payload = {\n \"grant_type\": \"client_credentials\",\n \"client_id\": clientID+\"@\"+bearerRealm[1],\n \"client_secret\": clientSecret,\n \"resource\": resource[1]+\"/\"+url+\"@\"+bearerRealm[1],\n \"redirect_uri\":\"http://localhost:1880/\",\n //\"code\":code\n\n \n }\n\n\n\nreturn msg;","outputs":1,"noerr":0,"x":850,"y":1640,"wires":[["f537729c.d0438"]]},{"id":"f537729c.d0438","type":"http request","z":"a5f021c7.3b18e","name":"Obtenemos el token de acceso","method":"POST","ret":"obj","paytoqs":false,"url":"","tls":"","persist":false,"proxy":"","authType":"","x":1090,"y":1640,"wires":[["1de1a6b4.d90c39"]]},{"id":"1de1a6b4.d90c39","type":"function","z":"a5f021c7.3b18e","name":"Constants","func":"/**\n\t * Metodo para leer datos de una lista de Sharepoint 365\n\t * @param urlAPI\n\t * @param urlSite\n\t * @param AccessToken\n\t * @param fileName\n\t * @param filePath\n\n*/\n\nvar urlAPI=msg.Constants.urlAPI,\n accessToken=msg.payload.access_token,\n titleList=msg.Constants.list\n\n\nmsg.headers={}\n\nmsg.headers[\"Authorization\"] = \"Bearer \"+accessToken;\nmsg.headers[\"Accept\"] = \"application/json;odata=verbose\";\n\nmsg.url =urlAPI+'/Web/Lists/getbytitle(\\''+titleList+'\\')/items';\n\n\n\n\nreturn msg;","outputs":1,"noerr":0,"x":420,"y":1700,"wires":[["51c0fdc.9043204"]]},{"id":"51c0fdc.9043204","type":"http request","z":"a5f021c7.3b18e","name":"Get List","method":"GET","ret":"obj","paytoqs":false,"url":"","tls":"","persist":false,"proxy":"","authType":"","x":560,"y":1700,"wires":[["27acf87f.7b0dd8"]]},{"id":"27acf87f.7b0dd8","type":"debug","z":"a5f021c7.3b18e","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","x":770,"y":1700,"wires":[]},{"id":"32143622.178d6a","type":"inject","z":"a5f021c7.3b18e","name":"SHAREPOINT","topic":"","payload":"","payloadType":"date","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":260,"y":1820,"wires":[["ff92c35.73d844"]]},{"id":"ff92c35.73d844","type":"function","z":"a5f021c7.3b18e","name":"Constants","func":"/**\n\t * Metodo para autenticarse en Sharepoint 365 con Client ID y Client Secret\n\t * @param url\n\t * @param clientID\n\t * @param clientSecret\n\n*/\nmsg.Constants = {\n url:\"<YourSite>.sharepoint.com\",\n urlAPI:\"<YourSite>.sharepoint.com/sites/test/_api\",\n clientID:\"7sde6a2e-6334-44re-bb35-36501078s8s8\",\n clientSecret:\"J9oddMNzHToW8EZIoW0VicSOR6EF7cY+dtz3WXfgccc=\",\n list:\"MyTestList\",\n column:\"Title\",\n data:\"SomeData\"\n}\n \nreturn msg;","outputs":1,"noerr":0,"x":420,"y":1820,"wires":[["af03a126.2e47e"]]},{"id":"af03a126.2e47e","type":"http request","z":"a5f021c7.3b18e","name":"Obtenemos el tenant ID","method":"GET","ret":"obj","paytoqs":false,"url":"https://tecdesoftes.sharepoint.com/_vti_bin/client.svc","tls":"","persist":false,"proxy":"","authType":"bearer","x":610,"y":1820,"wires":[["503735e2.4b9a0c"]],"info":"SI copias este nodo, reasigna el acceso como bearer"},{"id":"503735e2.4b9a0c","type":"function","z":"a5f021c7.3b18e","name":"\"tenant ID\"","func":"const url=msg.Constants.url\nconst clientID=msg.Constants.clientID\nconst clientSecret=msg.Constants.clientSecret\n\nvar headersArray = msg.headers[\"www-authenticate\"].split(\",\")\nvar bearerRealm = headersArray[0].split(\"\\\"\");\nvar resource = headersArray[1].split(\"\\\"\");\n\nmsg.headers={}\nmsg.url = \"https://accounts.accesscontrol.windows.net/\"+bearerRealm[1]+\"/tokens/OAuth/2\";\nmsg.headers[\"content-type\"] = \"application/x-www-form-urlencoded\";\nmsg.payload = {\n \"grant_type\": \"client_credentials\",\n \"client_id\": clientID+\"@\"+bearerRealm[1],\n \"client_secret\": clientSecret,\n \"resource\": resource[1]+\"/\"+url+\"@\"+bearerRealm[1],\n \"redirect_uri\":\"http://localhost:1880/\",\n }\n\nreturn msg;","outputs":1,"noerr":0,"x":850,"y":1820,"wires":[["f26c521a.bf065"]]},{"id":"f26c521a.bf065","type":"http request","z":"a5f021c7.3b18e","name":"Obtenemos el token de acceso","method":"POST","ret":"obj","paytoqs":false,"url":"","tls":"","persist":false,"proxy":"","authType":"","x":1090,"y":1820,"wires":[["48cf57d5.dff318"]]},{"id":"48cf57d5.dff318","type":"function","z":"a5f021c7.3b18e","name":"Constants","func":"/**\n\t * Metodo para añadir datos a una lista de Sharepoint 365\n\t * @param urlAPI\n\t * @param urlSite\n\t * @param AccessToken\n\t * @param fileName\n\t * @param filePath\n\n*/\n\nvar urlAPI=msg.Constants.urlAPI,\n accessToken=msg.payload.access_token,\n titleList=msg.Constants.list,\n titleMetadata =msg.Constants.list\n\n\nmsg.headers={}\n\nmsg.headers[\"Authorization\"] = \"Bearer \"+accessToken;\nmsg.headers[\"Accept\"] = \"application/json;odata=verbose\";\nmsg.headers[\"X-HTTP-Method\"] = \"POST\";\nmsg.headers[\"content-type\"] = \"application/json;odata=verbose\";\nmsg.headers[\"IF-MATCH\"] = \"*\";\n\nmsg.url =urlAPI+'/Web/Lists/getbytitle(\\''+titleList+'\\')/items';\n\n msg.payload = {\n \"__metadata\": {\n \"type\": \"SP.Data.\"+titleMetadata+\"ListItem\"\n },\n [msg.Constants.column]: msg.Constants.data\n}\n\n\nreturn msg;","outputs":1,"noerr":0,"x":420,"y":1880,"wires":[["36f04919.6f32d6"]]},{"id":"36f04919.6f32d6","type":"http request","z":"a5f021c7.3b18e","name":"Post item to list cell","method":"POST","ret":"obj","paytoqs":false,"url":"","tls":"","persist":false,"proxy":"","authType":"","x":590,"y":1880,"wires":[["a1f6efbf.f1a5d"]]},{"id":"a1f6efbf.f1a5d","type":"debug","z":"a5f021c7.3b18e","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","x":770,"y":1880,"wires":[]},{"id":"97782c01.6609e","type":"comment","z":"a5f021c7.3b18e","name":"GET LIST FROM SHAREPOINT","info":"","x":290,"y":1600,"wires":[]},{"id":"95992546.9a6208","type":"comment","z":"a5f021c7.3b18e","name":"POST ITEM TO A SHAREPOINT LIST","info":"se pueden añadir varios elementos ,\npero de momento se añade solo titulo para comprobar","x":310,"y":1780,"wires":[]},{"id":"728494e1.58b54c","type":"comment","z":"a5f021c7.3b18e","name":"https://docs.microsoft.com/es-es/sharepoint/dev/sp-add-ins/working-with-lists-and-list-items-with-rest","info":"","x":500,"y":1560,"wires":[]},{"id":"b78320a7.48bbb","type":"comment","z":"a5f021c7.3b18e","name":"Set this to bearer auth","info":"","x":620,"y":1620,"wires":[]},{"id":"e9c3c13b.82efe","type":"comment","z":"a5f021c7.3b18e","name":"Set this to bearer auth","info":"(if its bearer yet, change, deploy and set bearer again, its a bug i think)","x":600,"y":1780,"wires":[]}]

```

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/1X/d073cd938eafa2e558d7c2cd59003b3ef4963033.png) [@system](https://discourse.nodered.org/u/system)\
**Post date:** [26 November 2020 09:43 UTC](https://discourse.nodered.org/t/sharepoint-and-node-red/33437/5 "2020-11-26T09:43:34Z")

</div>

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.
