Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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
You can’t perform that action at this time.