Last active
September 19, 2022 23:40
-
-
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
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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