---
title: NerdGraph tutorial: View, create, rename, or cancel accounts
source: https://docs.newrelic.com/docs/apis/nerdgraph/examples/manage-accounts-nerdgraph
---

As an alternative to [using the New Relic UI](https://docs.newrelic.com/docs/accounts/accounts-billing/account-structure/add-accounts), you can use [NerdGraph](https://docs.newrelic.com/docs/apis/nerdgraph/get-started/introduction-new-relic-nerdgraph) to view your organization's accounts, as well as create, rename, or cancel accounts.

## Requirements [#requirements]

For requirements to manage organization-level settings via NerdGraph, see [Add accounts](https://docs.newrelic.com/docs/accounts/accounts-billing/account-structure/add-accounts).

## Before you start [#concepts]

Before you use NerdGraph to manage your accounts, it will probably help you to understand:

-   [What accounts are and what they're used for](https://docs.newrelic.com/docs/accounts/accounts-billing/account-structure/new-relic-account-structure)
-   That you can also [manage and add accounts via the UI](https://docs.newrelic.com/docs/accounts/accounts-billing/account-structure/add-accounts).
-   [The basics of using NerdGraph](https://docs.newrelic.com/docs/apis/nerdgraph/get-started/introduction-new-relic-nerdgraph)
-   That you can [track changes to your New Relic account](https://docs.newrelic.com/docs/data-apis/understand-data/event-data/query-account-audit-logs-nrauditevent)

## Tips on terms and fields [#field-definitions]

Some tips about some of the fields used in these requests:

-   The `managedAccount` and `managedAccounts` fields are simply terms for the accounts in an organization. They're synonymous with "accounts."
-   The `regionCode` field refers to [the data center used by an account](https://docs.newrelic.com/docs/accounts/accounts-billing/account-setup/choose-your-data-center). Valid values are `us01` and `eu01` which map to the US and EU regions respectively.

Note that the [NerdGraph explorer](https://docs.newrelic.com/docs/apis/nerdgraph/get-started/introduction-new-relic-nerdgraph/#explorer) has built-in docs that defines fields.

## View accounts [#view-accounts]

Here's an example of returning the accounts in your organization:

```graphql
{
  actor {
    organization {
      accountManagement {
        managedAccounts {
          name
          id
          regionCode
        }
      }
    }
  }
}
```

## Create accounts [#create-accounts]

Here's an example of how to create an account. Before creating an account, make sure you understand [what an account is used for](https://docs.newrelic.com/docs/accounts/accounts-billing/account-structure/new-relic-account-structure).

```graphql
mutation {
  accountManagementCreateAccount(
    managedAccount: {name: "NEW_ACCOUNT_NAME"}
  ) {
    managedAccount {
      id
      name
      regionCode
    }
  }
}
```

If you have a complex account structure you may use the optional `regionCode` parameter to target a specific data center.

```graphql
mutation {
  accountManagementCreateAccount(
    managedAccount: { name: "NEW_ACCOUNT_NAME", regionCode: "eu01" }
  ) {
    managedAccount {
      id
      name
      regionCode
    }
  }
}
```

## Rename an account [#rename-accounts]

Here's an example of how to rename an account.

```graphql
mutation {
  accountManagementUpdateAccount(
    managedAccount: { name: "UPDATED_ACCOUNT_NAME", id: 101010101 }
  ) {
    managedAccount {
      id
      name
      regionCode
    }
  }
}
```

## Cancel an account [#cancel-an-account]

If you no longer want to keep an account active, you can cancel it using NerdGraph.

Before you cancel an account, review the effects of [cancelling an account](https://docs.newrelic.com/docs/accounts/accounts-billing/account-setup/downgradecancel-account). Once you're sure you want to cancel an account, you can use this mutation:

```graphql
mutation {
  accountManagementCancelAccount(id: $accountId) {
    id
    isCanceled
    name
    regionCode
  }
}
```

> #### 💡 TIP
>
> As an alternative to cancelling an account, consider [removing a monitored entity](https://docs.newrelic.com/docs/apis/nerdgraph/examples/nerdgraph-entities-api-tutorial/#delete-entities).

## Errors [#errors]

Here are some errors and what they mean:

| **Error message**                                                                                                                                                                      | **Likely cause**                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                |
| -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| ```` "unauthorized", {   extensions: { nerdGraphExtensions: { errorClass: "ACCESS_DENIED" } } } ```  ````                                                                              | This points to a problem with your organization structure (for example, an account that is outside the boundaries of an organization). If you get this message, contact [support](https://docs.newrelic.com/docs/new-relic-solutions/solve-common-issues/find-help-use-support-portal) or your account representative.                                                                                                                                                                                                                          |
| ```` "cannot create subaccount -- multiple parent account ids found. Please use Partnership API.", {   extensions: { nerdGraphExtensions: { errorClass: "SERVER_ERROR" } } } ```  ```` | This is a message returned when your organization has more than one "parent account," which is an indicator that your organization has a complex account structure that was set up with the [Partnership API](https://docs.newrelic.com/docs/new-relic-partnerships/partner-integration-guide/partner-account-maintenance/partner-api) and requires the use of that API. Have questions? Contact [support](https://docs.newrelic.com/docs/new-relic-solutions/solve-common-issues/find-help-use-support-portal) or your account representative. |
| Other errors                                                                                                                                                                           | Contact [support](https://docs.newrelic.com/docs/new-relic-solutions/solve-common-issues/find-help-use-support-portal) or your account representative.                                                                                                                                                                                                                                                                                                                                                                                          |
