I can't edit my post
Anyway.
version node-red: 1.3.5
plataform: Ubuntu Server 22.04.4 LTS
example:
[
{
"id": "b5f8496f.14d4c8",
"type": "inject",
"z": "e41869bb.09b5a8",
"name": "ADD",
"props": [
{
"p": "payload"
},
{
"p": "topic",
"vt": "str"
}
],
"repeat": "",
"crontab": "",
"once": false,
"onceDelay": "20",
"topic": "add",
"payload": "",
"payloadType": "date",
"x": 250,
"y": 200,
"wires": [
[
"2ac302f7.1b52ee"
]
]
},
{
"id": "2ac302f7.1b52ee",
"type": "function",
"z": "e41869bb.09b5a8",
"name": "config req",
"func": "try{\n const body = {\n \"Title\": \"01001989\",\n \"field_0\": \"C@RLOS KÖNDE KANTÉ\"\n }\n const len = JSON.stringify(body).length;\n \n msg.payload = body;\n // msg.payload = JSON.stringify(body);\n \n msg.headers = {\n 'Authorization': 'Barear + accestoken',\n 'Content-Type': \"application/json;\",\n 'Content-Length': len,\n 'X-RequestDigest': \"{form_digest_value}\"\n }\n \n msg.url = \"https:/....sharepoint.com/.../web/lists/getByTitle('listName')/items\";\n \n node.status({ fill: \"green\", text: \"done\" });\n return msg;\n}catch(err){\n node.status({ fill: \"red\", text: \"error\" });\n node.error(err);\n throw err;\n}",
"outputs": 1,
"noerr": 0,
"initialize": "",
"finalize": "",
"libs": [],
"x": 400,
"y": 200,
"wires": [
[
"7af78bcc.1e27f4"
]
]
},
{
"id": "7af78bcc.1e27f4",
"type": "http request",
"z": "e41869bb.09b5a8",
"name": "add",
"method": "POST",
"ret": "obj",
"paytoqs": "ignore",
"url": "",
"tls": "",
"persist": false,
"proxy": "",
"authType": "",
"x": 550,
"y": 200,
"wires": [
[]
]
}
]
Solved:
[
{
"id": "8be1e4a3.4be038",
"type": "function",
"z": "8e958c14.3560d",
"name": "add",
"func": "try{\n const request = global.get('request');\n \n const url = 'https://.....sharepoint.com/..../_api/web/lists/getByTitle(\\'ListName\\')/items';\n const data = {\n \"Title\": \"01001989\",\n \"field_0\": \"C@RLOS KÖNDE KANTÉ\"\n }\n const options = {\n 'method': 'POST',\n 'url': url,\n 'headers': {\n 'Authorization': 'Bearer + access_token',\n 'Accept': 'application/json;odata=verbose',\n 'X-RequestDigest': '{form_digest_value}',\n 'Content-Type': 'application/json'\n },\n body: JSON.stringify(data)\n };\n \n request(options, function (error, response) {\n if (response.statusCode === 201) {\n node.status({ fill: \"green\", text: response.statusCode });\n return response;\n }\n if (response.statusCode !== 201) {\n node.status({ fill: \"yellow\", text: response.statusCode });\n return response;\n }\n if (error) {\n node.status({ fill: \"red\", text: \"error\" });\n node.error(error);\n return error;\n }\n });\n}catch(err){\n node.status({ fill: \"red\", text: \"error\" });\n node.error(err);\n throw err;\n}",
"outputs": 0,
"noerr": 0,
"initialize": "",
"finalize": "",
"libs": [],
"x": 530,
"y": 300,
"wires": [],
"icon": "node-red/white-globe.svg"
}
]