Skip to content

Instantly share code, notes, and snippets.

@lostphilosopher
Last active September 19, 2022 23:40
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save lostphilosopher/899a5ccce78f692906d7ee3e330aa098 to your computer and use it in GitHub Desktop.
Save lostphilosopher/899a5ccce78f692906d7ee3e330aa098 to your computer and use it in GitHub Desktop.
New Relic Synthetic API call with OAuth 2.0 (client_credentials flow) Raw
var assert = require('assert');
function new_relic_callback(err, response, body) {
assert.equal(response.statusCode, 200, 'Expected a 200 OK response');
};
function api_request_callback(err, response, body) {
var parsed_body = JSON.parse(body);
var api_request = {
url: 'https://example.com',
headers: {
'Authorization': 'Bearer ' + parsed_body["access_token"]
}
};
$http.get(api_request, new_relic_callback);
};
var token_request = {
url: 'https://example.com/oauth/token',
form: {
client_id: "YOUR_CLIENT_ID",
client_secret: "YOUR_CLIENT_SECRET",
grant_type: "client_credentials"
}
};
$http.post(token_request, api_request_callback);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment