also when i put this code in i get a error
CODE:
var http = require('http');
// The following 4 are the actual values that pertain to your account and this specific metric.
var apiKey = 'your-api-key-goes-here';
var pageId = 'ktnkzq1wp4wc';
var metricId = 'ly0m7lhl7gj0';
var apiBase = 'https://api.statuspage.io/v1';
var url = apiBase + '/pages/' + pageId + '/metrics/' + metricId + '/data.json';
var authHeader = { 'Authorization': 'OAuth ' + apiKey };
var options = { method: 'POST', headers: authHeader };
// Need at least 1 data point for every 5 minutes.
// Submit random data for the whole day.
var totalPoints = 60 / 5 * 24;
var epochInSeconds = Math.floor(new Date() / 1000);
// This function gets called every second.
function submit(count) {
count = count + 1;
if(count > totalPoints) return;
var currentTimestamp = epochInSeconds - (count - 1) * 5 * 60;
var randomValue = Math.floor(Math.random() * 1000);
var data = {
timestamp: currentTimestamp,
value: randomValue,
};
var request = http.request(url, options, function (res) {
res.on('data', function () {
console.log('Submitted point ' + count + ' of ' + totalPoints);
});
res.on('end', function() {
setTimeout(function() { submit(count); }, 1000);
});
});
request.end(JSON.stringify({ data: data }));
}
// Initial call to start submitting data.
submit(0);
ERROR:
working
working
_http_client.js:152
throw new ERR_INVALID_PROTOCOL(protocol, expectedProtocol);
^TypeError [ERR_INVALID_PROTOCOL]: Protocol "https:" not supported. Expected "http:"
at new ClientRequest (_http_client.js:152:11)
at Object.request (http.js:46:10)
at submit (C:\Users\ShawnHamby\Desktop\John\APi.js:33:22)
at Object.<anonymous> (C:\Users\ShawnHamby\Desktop\John\APi.js:47:1)
at Module._compile (internal/modules/cjs/loader.js:1138:30)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:1158:10)
at Module.load (internal/modules/cjs/loader.js:986:32)
at Function.Module._load (internal/modules/cjs/loader.js:879:14)
at Function.executeUserEntryPoint [as runMain] (internal/modules/run_main.js:71:12)
at internal/main/run_main_module.js:17:47 {
code: 'ERR_INVALID_PROTOCOL'
}
Hi Shawn,
I think this is a Node (this looks like NodeJS, correct if I'm wrong) error where it's using the https protocol in the apiBase parameter and is expecting http instead.
TypeError [ERR_INVALID_PROTOCOL]: Protocol "https:" not supported. Expected "http:"
Thanks,
Nick Coates
Product Owner - Service Status, Broadcom.
Online forums and learning are now in one easy-to-use experience.
By continuing, you accept the updated Community Terms of Use and acknowledge the Privacy Policy. Your public name, photo, and achievements may be publicly visible and available in search engines.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.