Sharepoint and Node-Red

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?

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!

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:

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

[{"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":[]}]

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