Skip to content

Instantly share code, notes, and snippets.

@gspncr
Last active August 6, 2020 14:26
Show Gist options
  • Save gspncr/5f4dc0ee879bb8833b71ad6f632c0b6f to your computer and use it in GitHub Desktop.
Save gspncr/5f4dc0ee879bb8833b71ad6f632c0b6f to your computer and use it in GitHub Desktop.
New Relic NerdGraph GUID Lookup
import requests, json
graphQLEndpoint = 'https://api.newrelic.com/graphql'
#graphQLEndpoint = 'https://api.eu.newrelic.com/graphql'
APIKey = '<your key here>'
headers = {
"Content-Type": 'application/json',
"API-Key": APIKey
}
query = """
{
actor {
entitySearch(query: "name like 'prod'") {
results {
entities {
name
guid
}
}
}
}
}
"""
request = requests.post(
graphQLEndpoint,
json={'query': query},
headers=headers
)
def parseGUIDs(request):
jsonpayload = json.loads(request.text)
entries = len(jsonpayload["data"]["actor"]["entitySearch"]["results"]["entities"])
for x in range(entries):
print(jsonpayload["data"]["actor"]["entitySearch"]["results"]["entities"][x]["name"],
jsonpayload["data"]["actor"]["entitySearch"]["results"]["entities"][x]["guid"])
parseGUIDs(request)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment