---
title: Query accounts
description: Datadog, the leading service for cloud-scale monitoring.
breadcrumbs: Docs > API Reference > Rum Audience Management
---

# Query accounts{% #query-accounts %}
Copy pageCopied
{% tab title="v2" %}
**Note**: This endpoint may be subject to changes.
| Datadog site      | API endpoint                                                               |
| ----------------- | -------------------------------------------------------------------------- |
| ap1.datadoghq.com | POST https://api.ap1.datadoghq.com/api/v2/product-analytics/accounts/query |
| ap2.datadoghq.com | POST https://api.ap2.datadoghq.com/api/v2/product-analytics/accounts/query |
| app.datadoghq.eu  | POST https://api.datadoghq.eu/api/v2/product-analytics/accounts/query      |
| app.ddog-gov.com  | POST https://api.ddog-gov.com/api/v2/product-analytics/accounts/query      |
| us2.ddog-gov.com  | POST https://api.us2.ddog-gov.com/api/v2/product-analytics/accounts/query  |
| app.datadoghq.com | POST https://api.datadoghq.com/api/v2/product-analytics/accounts/query     |
| us3.datadoghq.com | POST https://api.us3.datadoghq.com/api/v2/product-analytics/accounts/query |
| us5.datadoghq.com | POST https://api.us5.datadoghq.com/api/v2/product-analytics/accounts/query |

### Overview

Query accounts with flexible filtering by account properties

### Request

#### Body Data (required)



{% tab title="Model" %}

| Parent field | Field                  | Type     | Description                                                                          |
| ------------ | ---------------------- | -------- | ------------------------------------------------------------------------------------ |
|              | data                   | object   | The data object containing the resource type and attributes for querying accounts.   |
| data         | attributes             | object   | Attributes for filtering and shaping the account query results.                      |
| attributes   | limit                  | int64    | Maximum number of account records to return in the response.                         |
| attributes   | query                  | string   | Filter expression using account attribute conditions to narrow results.              |
| attributes   | select_columns         | [string] | List of account attribute column names to include in the response.                   |
| attributes   | sort                   | object   | Sorting configuration specifying the field and direction for ordering query results. |
| sort         | field                  | string   | The attribute field name to sort results by.                                         |
| sort         | order                  | string   | The sort direction, either ascending or descending.                                  |
| attributes   | wildcard_search_term   | string   | Free-text term used for wildcard search across account attribute values.             |
| data         | id                     | string   | Unique identifier for the query account request resource.                            |
| data         | type [*required*] | enum     | Query account request resource type. Allowed enum values: `query_account_request`    |

{% /tab %}

{% tab title="Example" %}

```json
{
  "data": {
    "attributes": {
      "limit": "integer",
      "query": "string",
      "select_columns": [],
      "sort": {
        "field": "string",
        "order": "string"
      },
      "wildcard_search_term": "string"
    },
    "id": "string",
    "type": "query_account_request"
  }
}
```

{% /tab %}

### Response

{% tab title="200" %}
Successful response with account data
{% tab title="Model" %}
Response containing the query results with matched records and total count.

| Parent field | Field                  | Type   | Description                                                                                     |
| ------------ | ---------------------- | ------ | ----------------------------------------------------------------------------------------------- |
|              | data                   | object | The data object containing the resource type and attributes of the query response.              |
| data         | attributes             | object | Attributes of the query response, containing the matched records and total count.               |
| attributes   | hits                   | []     | The list of matching records returned by the query, each as a map of attribute names to values. |
| attributes   | total                  | int64  | Total number of records matching the query, regardless of the limit applied.                    |
| data         | id                     | string | Unique identifier for the query response resource.                                              |
| data         | type [*required*] | enum   | Query response resource type. Allowed enum values: `query_response`                             |

{% /tab %}

{% tab title="Example" %}

```json
{
  "data": {
    "attributes": {
      "hits": [
        {
          "first_browser_name": "Chrome",
          "first_city": "San Francisco",
          "first_country_code": "US",
          "first_device_type": "Desktop",
          "last_seen": "2025-08-14T06:45:12.142Z",
          "session_count": 47,
          "user_created": "2024-12-15T08:42:33.287Z",
          "user_email": "john.smith@techcorp.com",
          "user_id": "150847",
          "user_name": "John Smith",
          "user_org_id": "5001"
        },
        {
          "first_browser_name": "Chrome",
          "first_city": "Austin",
          "first_country_code": "US",
          "first_device_type": "Desktop",
          "last_seen": "2025-08-14T05:22:08.951Z",
          "session_count": 89,
          "user_created": "2024-11-28T14:17:45.634Z",
          "user_email": "john.williams@techcorp.com",
          "user_id": "150848",
          "user_name": "John Williams",
          "user_org_id": "5001"
        },
        {
          "first_browser_name": "Chrome",
          "first_city": "Seattle",
          "first_country_code": "US",
          "first_device_type": "Desktop",
          "last_seen": "2025-08-14T04:18:34.726Z",
          "session_count": 23,
          "user_created": "2025-01-03T16:33:21.445Z",
          "user_email": "john.jones@techcorp.com",
          "user_id": "150849",
          "user_name": "John Jones",
          "user_org_id": "5001"
        }
      ],
      "total": 147
    },
    "id": "query_response",
    "type": "query_response"
  }
}
```

{% /tab %}

{% /tab %}

{% tab title="429" %}
Too many requests
{% tab title="Model" %}
API error response.

| Field                    | Type     | Description       |
| ------------------------ | -------- | ----------------- |
| errors [*required*] | [string] | A list of errors. |

{% /tab %}

{% tab title="Example" %}

```json
{
  "errors": [
    "Bad Request"
  ]
}
```

{% /tab %}

{% /tab %}

### Code Example

##### 
                  \## default
# 
 \# Curl command curl -X POST "https://api.datadoghq.com/api/v2/product-analytics/accounts/query" \
-H "Accept: application/json" \
-H "Content-Type: application/json" \
-H "DD-API-KEY: ${DD_API_KEY}" \
-H "DD-APPLICATION-KEY: ${DD_APP_KEY}" \
-d @- << EOF
{
  "data": {
    "attributes": {
      "limit": 20,
      "query": "plan_type:enterprise AND user_count:\u003e100 AND subscription_status:active",
      "select_columns": [
        "account_id",
        "account_name",
        "user_count",
        "plan_type",
        "subscription_status",
        "created_at",
        "mrr",
        "industry"
      ],
      "sort": {
        "field": "user_count",
        "order": "DESC"
      },
      "wildcard_search_term": "tech"
    },
    "id": "query_account_request",
    "type": "query_account_request"
  }
}
EOF 
                
##### 

```python
"""
Query accounts returns "Successful response with account data" response
"""

from datadog_api_client import ApiClient, Configuration
from datadog_api_client.v2.api.rum_audience_management_api import RumAudienceManagementApi
from datadog_api_client.v2.model.query_account_request import QueryAccountRequest
from datadog_api_client.v2.model.query_account_request_data import QueryAccountRequestData
from datadog_api_client.v2.model.query_account_request_data_attributes import QueryAccountRequestDataAttributes
from datadog_api_client.v2.model.query_account_request_data_attributes_sort import QueryAccountRequestDataAttributesSort
from datadog_api_client.v2.model.query_account_request_data_type import QueryAccountRequestDataType

body = QueryAccountRequest(
    data=QueryAccountRequestData(
        attributes=QueryAccountRequestDataAttributes(
            limit=20,
            query="plan_type:enterprise AND user_count:>100 AND subscription_status:active",
            select_columns=[
                "account_id",
                "account_name",
                "user_count",
                "plan_type",
                "subscription_status",
                "created_at",
                "mrr",
                "industry",
            ],
            sort=QueryAccountRequestDataAttributesSort(
                field="user_count",
                order="DESC",
            ),
            wildcard_search_term="tech",
        ),
        id="query_account_request",
        type=QueryAccountRequestDataType.QUERY_ACCOUNT_REQUEST,
    ),
)

configuration = Configuration()
configuration.unstable_operations["query_accounts"] = True
with ApiClient(configuration) as api_client:
    api_instance = RumAudienceManagementApi(api_client)
    response = api_instance.query_accounts(body=body)

    print(response)
```

#### Instructions

First [install the library and its dependencies](https://docs.datadoghq.com/api/latest.md?code-lang=python) and then save the example to `example.py` and run following commands:
    DD_SITE="datadoghq.com" DD_API_KEY="<DD_API_KEY>" DD_APP_KEY="<DD_APP_KEY>" python3 "example.py"
##### 

```ruby
# Query accounts returns "Successful response with account data" response

require "datadog_api_client"
DatadogAPIClient.configure do |config|
  config.unstable_operations["v2.query_accounts".to_sym] = true
end
api_instance = DatadogAPIClient::V2::RumAudienceManagementAPI.new

body = DatadogAPIClient::V2::QueryAccountRequest.new({
  data: DatadogAPIClient::V2::QueryAccountRequestData.new({
    attributes: DatadogAPIClient::V2::QueryAccountRequestDataAttributes.new({
      limit: 20,
      query: "plan_type:enterprise AND user_count:>100 AND subscription_status:active",
      select_columns: [
        "account_id",
        "account_name",
        "user_count",
        "plan_type",
        "subscription_status",
        "created_at",
        "mrr",
        "industry",
      ],
      sort: DatadogAPIClient::V2::QueryAccountRequestDataAttributesSort.new({
        field: "user_count",
        order: "DESC",
      }),
      wildcard_search_term: "tech",
    }),
    id: "query_account_request",
    type: DatadogAPIClient::V2::QueryAccountRequestDataType::QUERY_ACCOUNT_REQUEST,
  }),
})
p api_instance.query_accounts(body)
```

#### Instructions

First [install the library and its dependencies](https://docs.datadoghq.com/api/latest.md?code-lang=ruby) and then save the example to `example.rb` and run following commands:
    DD_SITE="datadoghq.com" DD_API_KEY="<DD_API_KEY>" DD_APP_KEY="<DD_APP_KEY>" rb "example.rb"
##### 

```go
// Query accounts returns "Successful response with account data" response

package main

import (
	"context"
	"encoding/json"
	"fmt"
	"os"

	"github.com/DataDog/datadog-api-client-go/v2/api/datadog"
	"github.com/DataDog/datadog-api-client-go/v2/api/datadogV2"
)

func main() {
	body := datadogV2.QueryAccountRequest{
		Data: &datadogV2.QueryAccountRequestData{
			Attributes: &datadogV2.QueryAccountRequestDataAttributes{
				Limit: datadog.PtrInt64(20),
				Query: datadog.PtrString("plan_type:enterprise AND user_count:>100 AND subscription_status:active"),
				SelectColumns: []string{
					"account_id",
					"account_name",
					"user_count",
					"plan_type",
					"subscription_status",
					"created_at",
					"mrr",
					"industry",
				},
				Sort: &datadogV2.QueryAccountRequestDataAttributesSort{
					Field: datadog.PtrString("user_count"),
					Order: datadog.PtrString("DESC"),
				},
				WildcardSearchTerm: datadog.PtrString("tech"),
			},
			Id:   datadog.PtrString("query_account_request"),
			Type: datadogV2.QUERYACCOUNTREQUESTDATATYPE_QUERY_ACCOUNT_REQUEST,
		},
	}
	ctx := datadog.NewDefaultContext(context.Background())
	configuration := datadog.NewConfiguration()
	configuration.SetUnstableOperationEnabled("v2.QueryAccounts", true)
	apiClient := datadog.NewAPIClient(configuration)
	api := datadogV2.NewRumAudienceManagementApi(apiClient)
	resp, r, err := api.QueryAccounts(ctx, body)

	if err != nil {
		fmt.Fprintf(os.Stderr, "Error when calling `RumAudienceManagementApi.QueryAccounts`: %v\n", err)
		fmt.Fprintf(os.Stderr, "Full HTTP response: %v\n", r)
	}

	responseContent, _ := json.MarshalIndent(resp, "", "  ")
	fmt.Fprintf(os.Stdout, "Response from `RumAudienceManagementApi.QueryAccounts`:\n%s\n", responseContent)
}
```

#### Instructions

First [install the library and its dependencies](https://docs.datadoghq.com/api/latest.md?code-lang=go) and then save the example to `main.go` and run following commands:
    DD_SITE="datadoghq.com" DD_API_KEY="<DD_API_KEY>" DD_APP_KEY="<DD_APP_KEY>" go run "main.go"
##### 

```java
// Query accounts returns "Successful response with account data" response

import com.datadog.api.client.ApiClient;
import com.datadog.api.client.ApiException;
import com.datadog.api.client.v2.api.RumAudienceManagementApi;
import com.datadog.api.client.v2.model.QueryAccountRequest;
import com.datadog.api.client.v2.model.QueryAccountRequestData;
import com.datadog.api.client.v2.model.QueryAccountRequestDataAttributes;
import com.datadog.api.client.v2.model.QueryAccountRequestDataAttributesSort;
import com.datadog.api.client.v2.model.QueryAccountRequestDataType;
import com.datadog.api.client.v2.model.QueryResponse;
import java.util.Arrays;

public class Example {
  public static void main(String[] args) {
    ApiClient defaultClient = ApiClient.getDefaultApiClient();
    defaultClient.setUnstableOperationEnabled("v2.queryAccounts", true);
    RumAudienceManagementApi apiInstance = new RumAudienceManagementApi(defaultClient);

    QueryAccountRequest body =
        new QueryAccountRequest()
            .data(
                new QueryAccountRequestData()
                    .attributes(
                        new QueryAccountRequestDataAttributes()
                            .limit(20L)
                            .query(
                                "plan_type:enterprise AND user_count:>100 AND"
                                    + " subscription_status:active")
                            .selectColumns(
                                Arrays.asList(
                                    "account_id",
                                    "account_name",
                                    "user_count",
                                    "plan_type",
                                    "subscription_status",
                                    "created_at",
                                    "mrr",
                                    "industry"))
                            .sort(
                                new QueryAccountRequestDataAttributesSort()
                                    .field("user_count")
                                    .order("DESC"))
                            .wildcardSearchTerm("tech"))
                    .id("query_account_request")
                    .type(QueryAccountRequestDataType.QUERY_ACCOUNT_REQUEST));

    try {
      QueryResponse result = apiInstance.queryAccounts(body);
      System.out.println(result);
    } catch (ApiException e) {
      System.err.println("Exception when calling RumAudienceManagementApi#queryAccounts");
      System.err.println("Status code: " + e.getCode());
      System.err.println("Reason: " + e.getResponseBody());
      System.err.println("Response headers: " + e.getResponseHeaders());
      e.printStackTrace();
    }
  }
}
```

#### Instructions

First [install the library and its dependencies](https://docs.datadoghq.com/api/latest.md?code-lang=java) and then save the example to `Example.java` and run following commands:
    DD_SITE="datadoghq.com" DD_API_KEY="<DD_API_KEY>" DD_APP_KEY="<DD_APP_KEY>" java "Example.java"
##### 

```rust
// Query accounts returns "Successful response with account data" response
use datadog_api_client::datadog;
use datadog_api_client::datadogV2::api_rum_audience_management::RumAudienceManagementAPI;
use datadog_api_client::datadogV2::model::QueryAccountRequest;
use datadog_api_client::datadogV2::model::QueryAccountRequestData;
use datadog_api_client::datadogV2::model::QueryAccountRequestDataAttributes;
use datadog_api_client::datadogV2::model::QueryAccountRequestDataAttributesSort;
use datadog_api_client::datadogV2::model::QueryAccountRequestDataType;

#[tokio::main]
async fn main() {
    let body = QueryAccountRequest::new().data(
        QueryAccountRequestData::new(QueryAccountRequestDataType::QUERY_ACCOUNT_REQUEST)
            .attributes(
                QueryAccountRequestDataAttributes::new()
                    .limit(20)
                    .query(
                        "plan_type:enterprise AND user_count:>100 AND subscription_status:active"
                            .to_string(),
                    )
                    .select_columns(vec![
                        "account_id".to_string(),
                        "account_name".to_string(),
                        "user_count".to_string(),
                        "plan_type".to_string(),
                        "subscription_status".to_string(),
                        "created_at".to_string(),
                        "mrr".to_string(),
                        "industry".to_string(),
                    ])
                    .sort(
                        QueryAccountRequestDataAttributesSort::new()
                            .field("user_count".to_string())
                            .order("DESC".to_string()),
                    )
                    .wildcard_search_term("tech".to_string()),
            )
            .id("query_account_request".to_string()),
    );
    let mut configuration = datadog::Configuration::new();
    configuration.set_unstable_operation_enabled("v2.QueryAccounts", true);
    let api = RumAudienceManagementAPI::with_config(configuration);
    let resp = api.query_accounts(body).await;
    if let Ok(value) = resp {
        println!("{:#?}", value);
    } else {
        println!("{:#?}", resp.unwrap_err());
    }
}
```

#### Instructions

First [install the library and its dependencies](https://docs.datadoghq.com/api/latest.md?code-lang=rust) and then save the example to `src/main.rs` and run following commands:
    DD_SITE="datadoghq.com" DD_API_KEY="<DD_API_KEY>" DD_APP_KEY="<DD_APP_KEY>" cargo run
##### 

```typescript
/**
 * Query accounts returns "Successful response with account data" response
 */

import { client, v2 } from "@datadog/datadog-api-client";

const configuration = client.createConfiguration();
configuration.unstableOperations["v2.queryAccounts"] = true;
const apiInstance = new v2.RumAudienceManagementApi(configuration);

const params: v2.RumAudienceManagementApiQueryAccountsRequest = {
  body: {
    data: {
      attributes: {
        limit: 20,
        query:
          "plan_type:enterprise AND user_count:>100 AND subscription_status:active",
        selectColumns: [
          "account_id",
          "account_name",
          "user_count",
          "plan_type",
          "subscription_status",
          "created_at",
          "mrr",
          "industry",
        ],
        sort: {
          field: "user_count",
          order: "DESC",
        },
        wildcardSearchTerm: "tech",
      },
      id: "query_account_request",
      type: "query_account_request",
    },
  },
};

apiInstance
  .queryAccounts(params)
  .then((data: v2.QueryResponse) => {
    console.log(
      "API called successfully. Returned data: " + JSON.stringify(data)
    );
  })
  .catch((error: any) => console.error(error));
```

#### Instructions

First [install the library and its dependencies](https://docs.datadoghq.com/api/latest.md?code-lang=typescript) and then save the example to `example.ts` and run following commands:
    DD_SITE="datadoghq.com" DD_API_KEY="<DD_API_KEY>" DD_APP_KEY="<DD_APP_KEY>" tsc "example.ts"
{% /tab %}
