2 websites to post results to for agent

Currently I have a beta version of a website set up and production website set up. I can not get the agent to send it to both. Right now it only sends it to the last site in my code.

`
function httpPostInsert(data, url) {
server.log(data);
local request = http.post(url, {“Content-Type”: “application/x-www-form-urlencoded”}, data)
local response = request.sendsync();
return response;
}

device.on(“logData”, function(data) {
local response = httpPostInsert(data, “http://website1Beta” );
server.log("response body1: " + response.body);
});

device.on(“logData”, function(data) {
local response = httpPostInsert(data, “http://website2Production” );
server.log("response body: " + response.body);
});
`

Meaning that only the website2Production is getting information sent to it right now.

You need to put both calls in the same handler function:

`function httpPostInsert(data, url) {
server.log(data);
local request = http.post(url, {“Content-Type”: “application/x-www-form-urlencoded”}, data)
local response = request.sendsync();
return response;
}

device.on(“logData”, function(data) {
local response1 = httpPostInsert(data, “http://website1Beta” );
server.log("response body1: " + response1.body);
local response2 = httpPostInsert(data, “http://website2Production” );
server.log("response body: " + response2.body);
});`

To add to Phil’s point: the second “device.on” is overwriting the first. Only the most-recently-registered handler (per event name) is called. Per the docs: “Setting a new handler for an existing event name will prevent the old handler from being called.”

A year later and I am getting back to some old projects. I want to share gratitude for your help. Thank you.