Can I query for a list of NR accounts I have access to?

Is there a way to make an API query and get a list of the New Relic accounts that I can access with the key I used for the query?

I tried the “View accounts” example from here this NerdGraph documentation, NerdGraph tutorial: view, create, and rename accounts | New Relic Documentation

However, that does not work. It gives me this result:

    {
  "data": {
    "actor": {
      "organization": {
        "accountManagement": {
          "managedAccounts": null
        }
      }
    }
  },
  "errors": [
    {
      "extensions": {
        "errorClass": "SERVER_ERROR"
      },
      "locations": [
        {
          "column": 9,
          "line": 5
        }
      ],
      "message": "An error occurred resolving this field",
      "path": [
        "actor",
        "organization",
        "accountManagement",
        "managedAccounts"
      ]
    }
  ]
}

I don’t know if this query is the right thing to do, or if it’s supposes to work. I don’t know if we haven an “organization”. What I do know is that we have multiple NR accounts one of which is called the “MSA” account and sometimes referred to as a master account. I know that with my user key, I can query for data from different accounts, if I give the account ID in my query.

What I’d like to do is find some query that can give me the list of accounts that I have access to with the supplied key. How do I do that?

Hi @cos1

I hope you are well. Thank you for reaching out.

Please try;

{
  actor {
    accounts(scope: GLOBAL) {
      id
      name
    }
  }
}

I hope this proves successful, please confirm is this was helpful. Should you have further questions, please reach out.

1 Like

Thank you, this works!

Can you explain:

  • Why the query I got from the documentation did not work?
  • What is the difference between what this query is supposed to do, and what that one is supposed to do, if they do different things?

Also, can you get this query example added to that documentation?

Hi @cos1

Its possible you were applying it correctly, or didnt meet the requirements. Its hard to say as I can not reproduce the issue on my side.

Unfortunately we cant add ever query etc to our documentation (as it would be never ending ). However I will reach out the team as mention this to them.

Im glad you were able to apply my workings to help resolve this challenge for you.

In relation to why is Introduction to New Relic NerdGraph, our GraphQL API | New Relic Documentation query different to the query is sent. Nerdgraph is an API method / NRQL is a UI method for querying the data., i.e one is for UI the other is for API.

I hope this helped clear things up. Feel free to reach out if you have additional questions.

Your response is somewhat ambiguous. Can you clarify whether you intended to say that a) that original query I gave is supposed to work, and b) that it is supposed to do exactly the same thing as the query you gave?