@ticaki aaaalso - so einfach scheint es nicht zu klappen.
Ich hab schon die beiden überflüssigen "," entfernt (innerhalb von headers nach dem Content-Type und nach bode: strBody.
Aber es funktioniert trotzdem noch nicht und der Fehler ist nicht gerade sprechend:
const axios = require('axios');
const strBody =
'{"token":"xxxxxx","user":"yyyyyy","title":"' +
strTitle +
'","text":"' +
strText +
'" ,"subtext":"' +
strSubtext +
'"}';
log('body: ' + strBody);
let strErg;
try {
const result = await axios(
{
timeout: 5000,
method: 'POST',
headers: {
'Content-Type': 'application/json'
},
url: 'https://api.pushover.net/1/glances.json',
body: strBody
}
);
log('body:' + result.data);
setState('0_userdata.0.PostRequest',body,true);
} catch(error) {
log(JSON.stringify(error.toJSON()));
}
return '';
Hier der Fehler:
{
"message": "Request failed with status code 400",
"name": "AxiosError",
"stack": "AxiosError: Request failed with status code 400\n at settle (/opt/iobroker/node_modules/iobroker.javascript/node_modules/axios/lib/core/settle.js:19:12)\n at IncomingMessage.handleStreamEnd (/opt/iobroker/node_modules/iobroker.javascript/node_modules/axios/lib/adapters/http.js:570:11)\n at IncomingMessage.emit (node:events:526:35)\n at IncomingMessage.emit (node:domain:489:12)\n at endReadableNT (node:internal/streams/readable:1359:12)\n at processTicksAndRejections (node:internal/process/task_queues:82:21)",
"config": {
"transitional": {
"silentJSONParsing": true,
"forcedJSONParsing": true,
"clarifyTimeoutError": false
},
"adapter": [
"xhr",
"http"
],
"transformRequest": [
null
],
"transformResponse": [
null
],
"timeout": 5000,
"xsrfCookieName": "XSRF-TOKEN",
"xsrfHeaderName": "X-XSRF-TOKEN",
"maxContentLength": -1,
"maxBodyLength": -1,
"env": {},
"headers": {
"Accept": "application/json, text/plain, */*",
"Content-Type": "application/json",
"User-Agent": "axios/1.4.0",
"Accept-Encoding": "gzip, compress, deflate, br"
},
"method": "post",
"url": "https://api.pushover.net/1/glances.json",
"body": "{\"token\":\"xxxx\",\"user\":\"yyyy\",\"title\":\"12.9 °C\",\"text\":\"12.9\" ,\"subtext\":\"17:25\"}"
},
"code": "ERR_BAD_REQUEST",
"status": 400
}