Effectively trying to use an API called things.io - Currently I am using hard coded inputs on the php page my nodered is being posted to to send an XMLHTTPRequest to the apis network (just to make sure it wasn't my inputs that were at fault).
If I go to the web page directly it will successfully make a call to the api and log it on their platform, so that part of the code seems to be working correctly.
However if I do an XMLHTTPRequest to the same page, no errors will be thrown - but it also won't make the successful call to the API. I can see the content of my page in the debug area, it just doesn't make that call.
Fairly new at node red so sorry for any stupid mistakes, code is below:
<script>
window.onload = function(){
var test = "<?php echo htmlspecialchars($_GET["name"]) ?>";
var temperature = test.substring(test.indexOf("ID: 1, Temperature: ")+20, test.indexOf("*C"));
var humidity = test.substring(test.indexOf("Humidity")+10, test.indexOf("%"));
var data = JSON.stringify({
"values": [
{
"key": "temperature",
"value": 17
},
{
"key": "humidity",
"value": 34
}
]
});
var xhr = new XMLHttpRequest();
xhr.withCredentials = true;
xhr.addEventListener("readystatechange", function () {
if (this.readyState === this.DONE) {
console.log(this.responseText);
}
});
xhr.open("POST", "https://api.thethings.io/v2/things/ /* this is being censored sorry :P /* ?store=true");
xhr.send(data);
}
</script>
Ok Made an answer to this by just skipping this part of the code - Took the original messege - sent it to a nodeRed function
var temperature = msg.payload.substring(msg.payload.indexOf("ID: 1, Temperature:
")+20, msg.payload.indexOf("*C"));
var humidity = msg.payload.substring(msg.payload.indexOf("Humidity")+10, msg.payload.indexOf("%"));
msg.payload = {"values":[{"key":"temperature","value":temperature},{"key":"humidity","value":humidity}]};
msg.headers = {'content-type':'application/json'};
return msg;
Then sent that to the main address.