
You can use the New Relic REST API v2 to record deployments, get a list of past deployments, and delete deployments
on the following Official Link you can explore all the methods you can do with the Rest API –
https://rpm.newrelic.com/api/explore
on the following example we’ll review requirements to Invoke-RestMethod on newrelic Deployments and we’ll create a function so we can call it easily
for any purpose .
first you must have an API key for your New Relic account.
to Determine your API key login to your newrelic account go to Account Settings–>API keys
if you need create one or Regenerate it .
Authentication for new relic –
to authenticate with the newrelic Rest API we’ll have to provide Authentication details : URL, Headers(API key) & Creds.
1 2 3 4 5 6 7 8 |
$user = "DevOps@******.com" $Pass = "1l@***!" $secpasswd = $Pass | ConvertTo-SecureString -AsPlainText -Force $cred = New-Object System.Management.Automation.PSCredential($user, $secpasswd) $url = "https://api.newrelic.com/deployments.xml" [string]$APIkey = "?4db55e6e*****f272301e***b8" $headers = @{"x-api-key"="$APIkey"} |
For deployment record we will post the following data : Application Name , Application ID, Description, Deploying User
& Revision deployment.
now lets wrapping it up and try to invoke it –
1 |
Invoke-RestMethod -uri $url -Method Post -Credential $cred -Headers @{"x-api-key"=$APIkey} -Body @{"deployment[app_name]"="$app_name"; "deployment[application_id]"="$application_id" ; "deployment[description]" = "$description" ; "deployment[user]" = "$DeployingUser" ; "deployment[revision]" = "$revision" } |
that’s it