Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in

My api key is when i gen it it does not show the api key

Shawn Hamby June 18, 2020

also when i put this code in i get a error 

 

CODE: 

  1. var http = require('http');

  2.  

  3. // The following 4 are the actual values that pertain to your account and this specific metric.

  4. var apiKey = 'your-api-key-goes-here';

  5. var pageId = 'ktnkzq1wp4wc';

  6. var metricId = 'ly0m7lhl7gj0';

  7. var apiBase = 'https://api.statuspage.io/v1';

  8.  

  9. var url = apiBase + '/pages/' + pageId + '/metrics/' + metricId + '/data.json';

  10. var authHeader = { 'Authorization': 'OAuth ' + apiKey };

  11. var options = { method: 'POST', headers: authHeader };

  12.  

  13. // Need at least 1 data point for every 5 minutes.

  14. // Submit random data for the whole day.

  15. var totalPoints = 60 / 5 * 24;

  16. var epochInSeconds = Math.floor(new Date() / 1000);

  17.  

  18. // This function gets called every second.

  19. function submit(count) {

  20. count = count + 1;

  21.  

  22. if(count > totalPoints) return;

  23.  

  24. var currentTimestamp = epochInSeconds - (count - 1) * 5 * 60;

  25. var randomValue = Math.floor(Math.random() * 1000);

  26.  

  27. var data = {

  28. timestamp: currentTimestamp,

  29. value: randomValue,

  30. };

  31.  

  32. var request = http.request(url, options, function (res) {

  33. res.on('data', function () {

  34. console.log('Submitted point ' + count + ' of ' + totalPoints);

  35. });

  36. res.on('end', function() {

  37. setTimeout(function() { submit(count); }, 1000);

  38. });

  39. });

  40.  

  41. request.end(JSON.stringify({ data: data }));

  42. }

  43.  

  44. // Initial call to start submitting data.

  45. 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'
}

1 answer

0 votes
Nick Coates
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
June 19, 2020

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.

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events