# List metric groups

GET https://app.launchdarkly.com/api/v2/projects/{projectKey}/metric-groups

Get a list of all metric groups for the specified project.

### Expanding the metric groups response

This endpoint does not support response expansion.

Although the API accepts an `expand` query parameter for compatibility reasons, it does not currently modify the response. The parameter is reserved for future use.

### Filtering metric groups

The `filter` parameter supports the following operators: `contains`, `equals`, `anyOf`.

#### Supported fields and operators

You can only filter certain fields in metrics when using the `filter` parameter. Additionally, you can only filter some fields with certain operators.

When you search for metrics, the `filter` parameter supports the following fields and operators:

|<div style="width:120px">Field</div> |Description |Supported operators |
|---|---|---|
| `experimentStatus` | The experiment's status. One of `not_started`, `running`, `stopped`, `started`. | `equals` |
| `hasConnections` | Whether the metric group has connections to experiments or guarded rollouts. One of `true`, `false`. | `equals` |
| `kind` | The metric group kind. One of `funnel`, `standard`. | `equals` |
| `maintainerIds` | The metric maintainer IDs. | `anyOf` |
| `maintainerTeamKey` | The metric maintainer team key. | `equals` |
| `query` | A "fuzzy" search across metric group key and name. Supply a string or list of strings to the operator. | `equals` |

### Sorting metric groups

LaunchDarkly supports the following fields for sorting:

- `name` sorts by metric group name.
- `createdAt` sorts by the creation date of the metric group.
- `connectionCount` sorts by the number of connections to experiments the metric group has.

By default, the sort is in ascending order. Use `-` to sort in descending order. For example, `?sort=name` sorts the response by metric group name in ascending order, and `?sort=-name` sorts in descending order.

#### Sample query

`filter=experimentStatus equals 'not_started' and query equals 'metric name'`


Reference: https://launchdarkly.com/docs/api/metrics-beta/get-metric-groups

## OpenAPI Specification

```yaml
openapi: 3.1.0
info:
  title: LaunchDarkly REST API
  version: 1.0.0
paths:
  /api/v2/projects/{projectKey}/metric-groups:
    get:
      operationId: get-metric-groups
      summary: List metric groups
      description: >
        Get a list of all metric groups for the specified project.


        ### Expanding the metric groups response


        This endpoint does not support response expansion.


        Although the API accepts an `expand` query parameter for compatibility
        reasons, it does not currently modify the response. The parameter is
        reserved for future use.


        ### Filtering metric groups


        The `filter` parameter supports the following operators: `contains`,
        `equals`, `anyOf`.


        #### Supported fields and operators


        You can only filter certain fields in metrics when using the `filter`
        parameter. Additionally, you can only filter some fields with certain
        operators.


        When you search for metrics, the `filter` parameter supports the
        following fields and operators:


        |<div style="width:120px">Field</div> |Description |Supported operators
        |

        |---|---|---|

        | `experimentStatus` | The experiment's status. One of `not_started`,
        `running`, `stopped`, `started`. | `equals` |

        | `hasConnections` | Whether the metric group has connections to
        experiments or guarded rollouts. One of `true`, `false`. | `equals` |

        | `kind` | The metric group kind. One of `funnel`, `standard`. |
        `equals` |

        | `maintainerIds` | The metric maintainer IDs. | `anyOf` |

        | `maintainerTeamKey` | The metric maintainer team key. | `equals` |

        | `query` | A "fuzzy" search across metric group key and name. Supply a
        string or list of strings to the operator. | `equals` |


        ### Sorting metric groups


        LaunchDarkly supports the following fields for sorting:


        - `name` sorts by metric group name.

        - `createdAt` sorts by the creation date of the metric group.

        - `connectionCount` sorts by the number of connections to experiments
        the metric group has.


        By default, the sort is in ascending order. Use `-` to sort in
        descending order. For example, `?sort=name` sorts the response by metric
        group name in ascending order, and `?sort=-name` sorts in descending
        order.


        #### Sample query


        `filter=experimentStatus equals 'not_started' and query equals 'metric
        name'`
      tags:
        - subpackage_metricsBeta
      parameters:
        - name: projectKey
          in: path
          description: The project key
          required: true
          schema:
            type: string
            format: string
        - name: filter
          in: query
          description: >-
            Accepts filter by `experimentStatus`, `query`, `kind`,
            `hasConnections`, `maintainerIds`, and `maintainerTeamKey`. Example:
            `filter=experimentStatus equals 'running' and query equals 'test'`.
          required: false
          schema:
            type: string
            format: string
        - name: sort
          in: query
          description: >-
            A comma-separated list of fields to sort by. Fields prefixed by a
            dash ( - ) sort in descending order. Read the endpoint description
            for a full list of available sort fields.
          required: false
          schema:
            type: string
            format: string
        - name: expand
          in: query
          description: >-
            This parameter is reserved for future use and is not currently
            supported on this endpoint.
          required: false
          schema:
            type: string
            format: string
        - name: limit
          in: query
          description: >-
            The number of metric groups to return in the response. Defaults to
            20. Maximum limit is 50.
          required: false
          schema:
            type: integer
            format: int64
        - name: offset
          in: query
          description: >-
            Where to start in the list. Use this with pagination. For example,
            an offset of 10 skips the first ten items and returns the next
            `limit` items.
          required: false
          schema:
            type: integer
            format: int64
        - name: Authorization
          in: header
          required: true
          schema:
            type: string
      responses:
        '200':
          description: Metric group collection response
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/MetricGroupCollectionRep'
        '400':
          description: Invalid request
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/InvalidRequestErrorRep'
        '401':
          description: Invalid access token
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/UnauthorizedErrorRep'
        '403':
          description: Forbidden
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ForbiddenErrorRep'
        '404':
          description: Invalid resource identifier
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/NotFoundErrorRep'
        '405':
          description: Method not allowed
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/MethodNotAllowedErrorRep'
        '429':
          description: Rate limited
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/RateLimitedErrorRep'
servers:
  - url: https://app.launchdarkly.com
  - url: https://app.launchdarkly.us
components:
  schemas:
    MetricGroupRepKind:
      type: string
      enum:
        - funnel
        - standard
      description: The type of the metric group
      title: MetricGroupRepKind
    Link:
      type: object
      properties:
        href:
          type: string
          description: The URL of the link
        type:
          type: string
          description: The type of the link
      title: Link
    ActionIdentifier:
      type: string
      title: ActionIdentifier
    ActionSpecifier:
      type: string
      title: ActionSpecifier
    AccessDeniedReasonEffect:
      type: string
      enum:
        - allow
        - deny
      description: Whether this statement should allow or deny actions on the resources.
      title: AccessDeniedReasonEffect
    AccessDeniedReason:
      type: object
      properties:
        resources:
          type: array
          items:
            type: string
          description: Resource specifier strings
        notResources:
          type: array
          items:
            type: string
          description: >-
            Targeted resources are the resources NOT in this list. The
            <code>resources</code> and <code>notActions</code> fields must be
            empty to use this field.
        actions:
          type: array
          items:
            $ref: '#/components/schemas/ActionSpecifier'
          description: Actions to perform on a resource
        notActions:
          type: array
          items:
            $ref: '#/components/schemas/ActionSpecifier'
          description: >-
            Targeted actions are the actions NOT in this list. The
            <code>actions</code> and <code>notResources</code> fields must be
            empty to use this field.
        effect:
          $ref: '#/components/schemas/AccessDeniedReasonEffect'
          description: >-
            Whether this statement should allow or deny actions on the
            resources.
        role_name:
          type: string
      required:
        - effect
      title: AccessDeniedReason
    AccessDenied:
      type: object
      properties:
        action:
          $ref: '#/components/schemas/ActionIdentifier'
        reason:
          $ref: '#/components/schemas/AccessDeniedReason'
      required:
        - action
        - reason
      title: AccessDenied
    AccessAllowedReasonEffect:
      type: string
      enum:
        - allow
        - deny
      description: Whether this statement should allow or deny actions on the resources.
      title: AccessAllowedReasonEffect
    AccessAllowedReason:
      type: object
      properties:
        resources:
          type: array
          items:
            type: string
          description: Resource specifier strings
        notResources:
          type: array
          items:
            type: string
          description: >-
            Targeted resources are the resources NOT in this list. The
            <code>resources</code> and <code>notActions</code> fields must be
            empty to use this field.
        actions:
          type: array
          items:
            $ref: '#/components/schemas/ActionSpecifier'
          description: Actions to perform on a resource
        notActions:
          type: array
          items:
            $ref: '#/components/schemas/ActionSpecifier'
          description: >-
            Targeted actions are the actions NOT in this list. The
            <code>actions</code> and <code>notResources</code> fields must be
            empty to use this field.
        effect:
          $ref: '#/components/schemas/AccessAllowedReasonEffect'
          description: >-
            Whether this statement should allow or deny actions on the
            resources.
        role_name:
          type: string
      required:
        - effect
      title: AccessAllowedReason
    AccessAllowedRep:
      type: object
      properties:
        action:
          $ref: '#/components/schemas/ActionIdentifier'
        reason:
          $ref: '#/components/schemas/AccessAllowedReason'
      required:
        - action
        - reason
      title: AccessAllowedRep
    Access:
      type: object
      properties:
        denied:
          type: array
          items:
            $ref: '#/components/schemas/AccessDenied'
        allowed:
          type: array
          items:
            $ref: '#/components/schemas/AccessAllowedRep'
      required:
        - denied
        - allowed
      title: Access
    UnixMillis:
      type: integer
      format: int64
      title: UnixMillis
    MemberSummary:
      type: object
      properties:
        _links:
          type: object
          additionalProperties:
            $ref: '#/components/schemas/Link'
          description: The location and content type of related resources
        _id:
          type: string
          description: The member's ID
        firstName:
          type: string
          description: The member's first name
        lastName:
          type: string
          description: The member's last name
        role:
          type: string
          description: >-
            The member's base role. If the member has no additional roles, this
            role will be in effect.
        email:
          type: string
          description: The member's email address
      required:
        - _links
        - _id
        - role
        - email
      title: MemberSummary
    MemberTeamSummaryRep:
      type: object
      properties:
        customRoleKeys:
          type: array
          items:
            type: string
          description: A list of keys of the custom roles this team has access to
        key:
          type: string
          description: The team key
        _links:
          type: object
          additionalProperties:
            $ref: '#/components/schemas/Link'
        name:
          type: string
          description: The team name
      required:
        - customRoleKeys
        - key
        - name
      title: MemberTeamSummaryRep
    MaintainerRep:
      type: object
      properties:
        member:
          $ref: '#/components/schemas/MemberSummary'
          description: Details on the member who maintains this resource
        team:
          $ref: '#/components/schemas/MemberTeamSummaryRep'
          description: Details on the team that maintains this resource
      title: MaintainerRep
    MetricInGroupRepKind:
      type: string
      enum:
        - pageview
        - click
        - custom
      description: The kind of event the metric tracks
      title: MetricInGroupRepKind
    MetricInGroupRepUnitAggregationType:
      type: string
      enum:
        - sum
        - average
      description: The type of unit aggregation to use for the metric
      title: MetricInGroupRepUnitAggregationType
    MetricInGroupRep:
      type: object
      properties:
        key:
          type: string
          description: The metric key
        _versionId:
          type: string
          description: The version ID of the metric
        name:
          type: string
          description: The metric name
        kind:
          $ref: '#/components/schemas/MetricInGroupRepKind'
          description: The kind of event the metric tracks
        isNumeric:
          type: boolean
          description: >-
            For custom metrics, whether to track numeric changes in value
            against a baseline (<code>true</code>) or to track a conversion when
            an end user takes an action (<code>false</code>).
        unitAggregationType:
          $ref: '#/components/schemas/MetricInGroupRepUnitAggregationType'
          description: The type of unit aggregation to use for the metric
        eventKey:
          type: string
          description: >-
            The event key sent with the metric. Only relevant for custom
            metrics.
        _links:
          type: object
          additionalProperties:
            $ref: '#/components/schemas/Link'
          description: The location and content type of related resources
        nameInGroup:
          type: string
          description: >-
            Name of the metric when used within the associated metric group. Can
            be different from the original name of the metric. Required if and
            only if the metric group is a <code>funnel</code>.
        randomizationUnits:
          type: array
          items:
            type: string
          description: The randomization units for the metric
      required:
        - key
        - name
        - kind
        - _links
      title: MetricInGroupRep
    DependentExperimentRep:
      type: object
      properties:
        key:
          type: string
          description: The experiment key
        name:
          type: string
          description: The experiment name
        environmentId:
          type: string
          description: The environment ID
        environmentKey:
          type: string
          description: The environment key
        creationDate:
          $ref: '#/components/schemas/UnixMillis'
          description: Timestamp of when the experiment was created
        archivedDate:
          $ref: '#/components/schemas/UnixMillis'
          description: Timestamp of when the experiment was archived
        _links:
          type: object
          additionalProperties:
            $ref: '#/components/schemas/Link'
          description: The location and content type of related resources
      required:
        - key
        - name
        - environmentId
        - environmentKey
        - creationDate
        - _links
      title: DependentExperimentRep
    DependentExperimentListRep:
      type: array
      items:
        $ref: '#/components/schemas/DependentExperimentRep'
      title: DependentExperimentListRep
    MetricGroupRep:
      type: object
      properties:
        _id:
          type: string
          description: The ID of this metric group
        key:
          type: string
          description: A unique key to reference the metric group
        name:
          type: string
          description: A human-friendly name for the metric group
        kind:
          $ref: '#/components/schemas/MetricGroupRepKind'
          description: The type of the metric group
        description:
          type: string
          description: Description of the metric group
        _links:
          type: object
          additionalProperties:
            $ref: '#/components/schemas/Link'
          description: The location and content type of related resources
        _access:
          $ref: '#/components/schemas/Access'
          description: Details on the allowed and denied actions for this metric group
        tags:
          type: array
          items:
            type: string
          description: Tags for the metric group
        _creationDate:
          $ref: '#/components/schemas/UnixMillis'
          description: Timestamp of when the metric group was created
        _lastModified:
          $ref: '#/components/schemas/UnixMillis'
          description: Timestamp of when the metric group was last modified
        maintainer:
          $ref: '#/components/schemas/MaintainerRep'
          description: The maintainer of this metric
        metrics:
          type: array
          items:
            $ref: '#/components/schemas/MetricInGroupRep'
          description: An ordered list of the metrics in this metric group
        _version:
          type: integer
          description: The version of this metric group
        experiments:
          $ref: '#/components/schemas/DependentExperimentListRep'
          description: >-
            Experiments that use this metric group. Only included if specified
            in the <code>expand</code> query parameter in a
            <code>getMetricGroup</code> request.
        experimentCount:
          type: integer
          description: The number of experiments using this metric group
        activeExperimentCount:
          type: integer
          description: The number of active experiments using this metric group
        activeGuardedRolloutCount:
          type: integer
          description: The number of active guarded rollouts using this metric group
      required:
        - _id
        - key
        - name
        - kind
        - _links
        - tags
        - _creationDate
        - _lastModified
        - maintainer
        - metrics
        - _version
      title: MetricGroupRep
    MetricGroupCollectionRep:
      type: object
      properties:
        items:
          type: array
          items:
            $ref: '#/components/schemas/MetricGroupRep'
          description: An array of metric groups
        _links:
          type: object
          additionalProperties:
            $ref: '#/components/schemas/Link'
          description: The location and content type of related resources
        totalCount:
          type: integer
      required:
        - items
      title: MetricGroupCollectionRep
    InvalidRequestErrorRep:
      type: object
      properties:
        code:
          type: string
          description: Specific error code encountered
        message:
          type: string
          description: Description of the error
      required:
        - code
        - message
      title: InvalidRequestErrorRep
    UnauthorizedErrorRep:
      type: object
      properties:
        code:
          type: string
          description: Specific error code encountered
        message:
          type: string
          description: Description of the error
      required:
        - code
        - message
      title: UnauthorizedErrorRep
    ForbiddenErrorRep:
      type: object
      properties:
        code:
          type: string
          description: Specific error code encountered
        message:
          type: string
          description: Description of the error
      required:
        - code
        - message
      title: ForbiddenErrorRep
    NotFoundErrorRep:
      type: object
      properties:
        code:
          type: string
          description: Specific error code encountered
        message:
          type: string
          description: Description of the error
      required:
        - code
        - message
      title: NotFoundErrorRep
    MethodNotAllowedErrorRep:
      type: object
      properties:
        code:
          type: string
          description: Specific error code encountered
        message:
          type: string
          description: Description of the error
      required:
        - code
        - message
      title: MethodNotAllowedErrorRep
    RateLimitedErrorRep:
      type: object
      properties:
        code:
          type: string
          description: Specific error code encountered
        message:
          type: string
          description: Description of the error
      required:
        - code
        - message
      title: RateLimitedErrorRep
  securitySchemes:
    ApiKey:
      type: apiKey
      in: header
      name: Authorization

```

## SDK Code Examples

```python
import requests

url = "https://app.launchdarkly.com/api/v2/projects/projectKey/metric-groups"

headers = {"Authorization": "<apiKey>"}

response = requests.get(url, headers=headers)

print(response.json())
```

```javascript
const url = 'https://app.launchdarkly.com/api/v2/projects/projectKey/metric-groups';
const options = {method: 'GET', headers: {Authorization: '<apiKey>'}};

try {
  const response = await fetch(url, options);
  const data = await response.json();
  console.log(data);
} catch (error) {
  console.error(error);
}
```

```go
package main

import (
	"fmt"
	"net/http"
	"io"
)

func main() {

	url := "https://app.launchdarkly.com/api/v2/projects/projectKey/metric-groups"

	req, _ := http.NewRequest("GET", url, nil)

	req.Header.Add("Authorization", "<apiKey>")

	res, _ := http.DefaultClient.Do(req)

	defer res.Body.Close()
	body, _ := io.ReadAll(res.Body)

	fmt.Println(res)
	fmt.Println(string(body))

}
```

```ruby
require 'uri'
require 'net/http'

url = URI("https://app.launchdarkly.com/api/v2/projects/projectKey/metric-groups")

http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true

request = Net::HTTP::Get.new(url)
request["Authorization"] = '<apiKey>'

response = http.request(request)
puts response.read_body
```

```java
import com.mashape.unirest.http.HttpResponse;
import com.mashape.unirest.http.Unirest;

HttpResponse<String> response = Unirest.get("https://app.launchdarkly.com/api/v2/projects/projectKey/metric-groups")
  .header("Authorization", "<apiKey>")
  .asString();
```

```php
<?php
require_once('vendor/autoload.php');

$client = new \GuzzleHttp\Client();

$response = $client->request('GET', 'https://app.launchdarkly.com/api/v2/projects/projectKey/metric-groups', [
  'headers' => [
    'Authorization' => '<apiKey>',
  ],
]);

echo $response->getBody();
```

```csharp
using RestSharp;

var client = new RestClient("https://app.launchdarkly.com/api/v2/projects/projectKey/metric-groups");
var request = new RestRequest(Method.GET);
request.AddHeader("Authorization", "<apiKey>");
IRestResponse response = client.Execute(request);
```

```swift
import Foundation

let headers = ["Authorization": "<apiKey>"]

let request = NSMutableURLRequest(url: NSURL(string: "https://app.launchdarkly.com/api/v2/projects/projectKey/metric-groups")! as URL,
                                        cachePolicy: .useProtocolCachePolicy,
                                    timeoutInterval: 10.0)
request.httpMethod = "GET"
request.allHTTPHeaderFields = headers

let session = URLSession.shared
let dataTask = session.dataTask(with: request as URLRequest, completionHandler: { (data, response, error) -> Void in
  if (error != nil) {
    print(error as Any)
  } else {
    let httpResponse = response as? HTTPURLResponse
    print(httpResponse)
  }
})

dataTask.resume()
```