Your data. Anywhere you go.

New Relic for iOS or Android


Download on the App Store    Android App on Google play


New Relic Insights App for iOS


Download on the App Store


Learn more

Close icon

Https get request with certificate is failing

synthetics-script

#1

I am writing api test monitor for my api. My api needs certificate.

  • Please share a Permalink or a direct link to the synthetics monitor you have questions about:
 /**
 * Feel free to explore, or check out the full documentation
 * https://docs.newrelic.com/docs/synthetics/new-relic-synthetics/scripting-monitors/writing-api-tests
 * for details.
 */

var assert = require('assert');
var apptDate = new Date();
apptDate.setMonth(apptDate.getMonth() + 3);
var apptDt = formatDateToString(apptDate);
//console.log('apptDt '+apptDt);
var encodedcert = 'base64 encoded certificate'

let text = Buffer.from(encodedcert, 'base64');
$http.get({
    //Define endpoint URI
    url: "https://api.xtime.com/consumer/v2/timeslots/companyId/120/companyCode/640/year/2013/make/NISSAN/model/Altima?serviceCodes=MB1&startDate="+apptDt+"&numberOfDays=2&maxNumberOfSlots=7&transportationType=DropOff",
    headers: {
		"Accept": "application/json",
		"developerKey": "[redacted]"
	},
 // agent: $globalAgents.https,
    strictSSL: true,
     agentOptions: {
        pfx: text
        
    }	
},

  // Callback
  function callback (err, response, body) {
    console.log('response '+response);
  //  console.log('body '+body);
  //  console.log('status code '+response.statusCode);
    assert.equal(response.statusCode, 200, 'Expected a 200 OK response');

    //console.log('Response:', body.json);

  }
);

function formatDateToString(date){
   // 01, 02, 03, ... 29, 30, 31
   var dd = (date.getDate() < 10 ? '0' : '') + date.getDate();
   // 01, 02, 03, ... 10, 11, 12
   var MM = ((date.getMonth() + 1) < 10 ? '0' : '') + (date.getMonth() + 1);
   // 1970, 1971, ... 2015, 2016, ...
   var yyyy = date.getFullYear();

   // create the format you want
   return (yyyy + "-" + MM + "-" + dd);
}

In the above if i uncomment // agent: $globalAgents.https,
the script is failing. If I comment those code, the script is successful but graph is not loading.

  • Describe what are you seeing. How does that differ than what were you expecting to see?

#2

Hi @gandhirajan.somasund, would you mind sharing the failure message of the monitor when the agent: $globalAgents.http is uncommented and I can take a closer look? You can also see more info on the agentOptions parameter in the GitHub Request documentation: