# List metrics

GET https://app.launchdarkly.com/api/v2/metrics/{projectKey}

Get a list of all metrics for the specified project.

### Filtering metrics

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 |
|---|---|---|
| `dataSourceKeys` | The data source that provides events for this metric (for example, "launchdarkly-hosted"). | `anyOf`, `notEquals` |
| `eventKeys` | The metric event key. | `anyOf` |
| `eventKind` | The metric event kind. One of `custom`, `pageview`, `click`. | `equals` |
| `hasConnections` | Whether the metric has connections to experiments or guarded rollouts. One of `true`, `false`. | `equals` |
| `isNumeric` | Whether the metric is numeric. One of `true`, `false`. | `equals` |
| `maintainerIds` | A comma-separated list of metric maintainer IDs. | `anyOf` |
| `maintainerTeamKey` | The metric maintainer team key. | `equals` |
| `metricUsedIn` | Filter by where the metric is used. One of `experiments`, `guarded_rollouts`, `any`, `none`. | `equals` |
| `query` | A "fuzzy" search across metric key and name. Supply a string or list of strings to the operator. | `equals` |
| `tags` | The metric tags. | `contains` |
| `unitAggregationType` | The metric's unit aggregation type. One of `sum`, `average`. | `equals` |
| `versionIds` | The metric version number. | `anyOf` |
| `view` | The view used to restrict access to the metric. | `equals` |

For example, the filter `?filter=tags contains ["tag1", "tag2", "tag3"]` matches metrics that have all three tags.

The documented values for `filter` query parameters are prior to URL encoding. For example, the `[` in `?filter=tags contains ["tag1", "tag2", "tag3"]` must be encoded to `%5B`.

### Expanding the metric list response

LaunchDarkly supports expanding the "List metrics" response. By default, the expandable field is **not** included in the response.

To expand the response, append the `expand` query parameter and add the following supported field:

- `experimentCount` includes the number of experiments from the specific project that use the metric

For example, `expand=experimentCount` includes the `experimentCount` field for each metric in the response.


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

## OpenAPI Specification

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


        ### Filtering metrics


        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
        |

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

        | `dataSourceKeys` | The data source that provides events for this
        metric (for example, "launchdarkly-hosted"). | `anyOf`, `notEquals` |

        | `eventKeys` | The metric event key. | `anyOf` |

        | `eventKind` | The metric event kind. One of `custom`, `pageview`,
        `click`. | `equals` |

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

        | `isNumeric` | Whether the metric is numeric. One of `true`, `false`. |
        `equals` |

        | `maintainerIds` | A comma-separated list of metric maintainer IDs. |
        `anyOf` |

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

        | `metricUsedIn` | Filter by where the metric is used. One of
        `experiments`, `guarded_rollouts`, `any`, `none`. | `equals` |

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

        | `tags` | The metric tags. | `contains` |

        | `unitAggregationType` | The metric's unit aggregation type. One of
        `sum`, `average`. | `equals` |

        | `versionIds` | The metric version number. | `anyOf` |

        | `view` | The view used to restrict access to the metric. | `equals` |


        For example, the filter `?filter=tags contains ["tag1", "tag2", "tag3"]`
        matches metrics that have all three tags.


        The documented values for `filter` query parameters are prior to URL
        encoding. For example, the `[` in `?filter=tags contains ["tag1",
        "tag2", "tag3"]` must be encoded to `%5B`.


        ### Expanding the metric list response


        LaunchDarkly supports expanding the "List metrics" response. By default,
        the expandable field is **not** included in the response.


        To expand the response, append the `expand` query parameter and add the
        following supported field:


        - `experimentCount` includes the number of experiments from the specific
        project that use the metric


        For example, `expand=experimentCount` includes the `experimentCount`
        field for each metric in the response.
      tags:
        - subpackage_metrics
      parameters:
        - name: projectKey
          in: path
          description: The project key
          required: true
          schema:
            type: string
            format: string
        - name: expand
          in: query
          description: >-
            A comma-separated list of properties that can reveal additional
            information in the response.
          required: false
          schema:
            type: string
            format: string
        - name: limit
          in: query
          description: >-
            The number of metrics 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: sort
          in: query
          description: >-
            A field to sort the items by. Prefix field by a dash ( - ) to sort
            in descending order. This endpoint supports sorting by `createdAt`
            or `name`.
          required: false
          schema:
            type: string
            format: string
        - name: filter
          in: query
          description: >-
            A comma-separated list of filters. This endpoint accepts filtering
            by `query`, `tags`, `eventKind`, `isNumeric`, `unitAggregationType`,
            `hasConnections`, `maintainerIds`, `maintainerTeamKey`, `view`,
            `dataSourceKeys`, `metricUsedIn`, `eventKeys`, and `versionIds`. To
            learn more about the filter syntax, read the 'Filtering metrics'
            section above.
          required: false
          schema:
            type: string
            format: string
        - name: Authorization
          in: header
          required: true
          schema:
            type: string
      responses:
        '200':
          description: Metrics collection response
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/MetricCollectionRep'
        '401':
          description: Invalid access token
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/UnauthorizedErrorRep'
        '404':
          description: Invalid resource identifier
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/NotFoundErrorRep'
servers:
  - url: https://app.launchdarkly.com
  - url: https://app.launchdarkly.us
components:
  schemas:
    MetricListingRepKind:
      type: string
      enum:
        - pageview
        - click
        - custom
      description: The kind of event the metric tracks
      title: MetricListingRepKind
    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
    Modification:
      type: object
      properties:
        date:
          type: string
          format: date-time
      title: Modification
    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
    MetricListingRepSuccessCriteria:
      type: string
      enum:
        - HigherThanBaseline
        - LowerThanBaseline
      description: For custom metrics, the success criteria
      title: MetricListingRepSuccessCriteria
    FilterType:
      type: string
      enum:
        - group
        - contextAttribute
        - eventProperty
      description: Filter type. One of [contextAttribute, eventProperty, group]
      title: FilterType
    Operator:
      type: string
      title: Operator
    Filter:
      type: object
      properties:
        type:
          $ref: '#/components/schemas/FilterType'
          description: Filter type. One of [contextAttribute, eventProperty, group]
        attribute:
          type: string
          description: >-
            If not a group node, the context attribute name or event property
            name to filter on
        op:
          $ref: '#/components/schemas/Operator'
          description: The function to perform
        values:
          type: array
          items:
            description: Any type
          description: The context attribute / event property values or group member nodes
        contextKind:
          type: string
          description: For context attribute filters, the context kind.
        negate:
          type: boolean
          description: >-
            If set, then take the inverse of the operator. 'in' becomes 'not
            in'.
      required:
        - type
        - op
        - values
        - negate
      title: Filter
    MetricListingRepUnitAggregationType:
      type: string
      enum:
        - average
        - sum
      description: The method by which multiple unit event values are aggregated
      title: MetricListingRepUnitAggregationType
    MetricListingRepAnalysisType:
      type: string
      enum:
        - mean
        - percentile
      description: The method for analyzing metric events
      title: MetricListingRepAnalysisType
    MetricEventDefaultRep:
      type: object
      properties:
        disabled:
          type: boolean
          description: >-
            Whether to disable defaulting missing unit events when calculating
            results. Defaults to false
        value:
          type: number
          format: double
          description: >-
            The default value applied to missing unit events. Set to 0 when
            <code>disabled</code> is false. No other values are currently
            supported.
      title: MetricEventDefaultRep
    MetricDataSourceRefRep:
      type: object
      properties:
        key:
          type: string
        environmentKey:
          type: string
        _name:
          type: string
        _integrationKey:
          type: string
      required:
        - key
      title: MetricDataSourceRefRep
    UrlMatcher:
      type: object
      additionalProperties:
        description: Any type
      title: UrlMatcher
    UrlMatchers:
      type: array
      items:
        $ref: '#/components/schemas/UrlMatcher'
      title: UrlMatchers
    MetricListingRep:
      type: object
      properties:
        experimentCount:
          type: integer
          description: The number of experiments using this metric
        metricGroupCount:
          type: integer
          description: The number of metric groups using this metric
        activeExperimentCount:
          type: integer
          description: The number of active experiments using this metric
        activeGuardedRolloutCount:
          type: integer
          description: The number of active guarded rollouts using this metric
        _id:
          type: string
          description: The ID of this metric
        _versionId:
          type: string
          description: The version ID of the metric
        _version:
          type: integer
          description: Version of the metric
        key:
          type: string
          description: A unique key to reference the metric
        name:
          type: string
          description: A human-friendly name for the metric
        kind:
          $ref: '#/components/schemas/MetricListingRepKind'
          description: The kind of event the metric tracks
        _attachedFlagCount:
          type: integer
          description: The number of feature flags currently attached to this metric
        _links:
          type: object
          additionalProperties:
            $ref: '#/components/schemas/Link'
          description: The location and content type of related resources
        _site:
          $ref: '#/components/schemas/Link'
          description: Details on how to access the metric in the LaunchDarkly UI
        _access:
          $ref: '#/components/schemas/Access'
          description: Details on the allowed and denied actions for this metric
        tags:
          type: array
          items:
            type: string
          description: Tags for the metric
        _creationDate:
          $ref: '#/components/schemas/UnixMillis'
          description: Timestamp of when the metric was created
        lastModified:
          $ref: '#/components/schemas/Modification'
        maintainerId:
          type: string
          description: The ID of the member who maintains this metric
        _maintainer:
          $ref: '#/components/schemas/MemberSummary'
          description: Details on the member who maintains this metric
        description:
          type: string
          description: Description of the metric
        category:
          type: string
          description: The category of the metric
        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>).
        successCriteria:
          $ref: '#/components/schemas/MetricListingRepSuccessCriteria'
          description: For custom metrics, the success criteria
        unit:
          type: string
          description: For numeric custom metrics, the unit of measure
        eventKey:
          type: string
          description: For custom metrics, the event key to use in your code
        randomizationUnits:
          type: array
          items:
            type: string
          description: An array of randomization units allowed for this metric
        filters:
          $ref: '#/components/schemas/Filter'
          description: >-
            The filters narrowing down the audience based on context attributes
            or event properties.
        unitAggregationType:
          $ref: '#/components/schemas/MetricListingRepUnitAggregationType'
          description: The method by which multiple unit event values are aggregated
        analysisType:
          $ref: '#/components/schemas/MetricListingRepAnalysisType'
          description: The method for analyzing metric events
        percentileValue:
          type: integer
          description: >-
            The percentile for the analysis method. An integer denoting the
            target percentile between 0 and 100. Required when
            <code>analysisType</code> is <code>percentile</code>.
        eventDefault:
          $ref: '#/components/schemas/MetricEventDefaultRep'
        dataSource:
          $ref: '#/components/schemas/MetricDataSourceRefRep'
        lastSeen:
          $ref: '#/components/schemas/UnixMillis'
          description: Timestamp of most recent data for this metric, at one-hour fidelity
        archived:
          type: boolean
          description: Whether the metric version is archived
        archivedAt:
          $ref: '#/components/schemas/UnixMillis'
          description: Timestamp when the metric version was archived
        selector:
          type: string
          description: For click metrics, the CSS selectors
        urls:
          $ref: '#/components/schemas/UrlMatchers'
          description: For click and pageview metrics, the target URLs
        windowStartOffset:
          type: integer
          format: int64
          description: >-
            Not yet implemented - The start of the measurement window, in
            milliseconds relative to the unit's first exposure to a flag
            variation
        windowEndOffset:
          type: integer
          format: int64
          description: >-
            Not yet implemented - The end of the measurement window, in
            milliseconds relative to the unit's first exposure to a flag
            variation
        traceQuery:
          type: string
          description: For trace metrics, the trace query to use for the metric.
        traceValueLocation:
          type: string
          description: >-
            For trace metrics, the location in the trace to use for numeric
            values.
      required:
        - _id
        - _versionId
        - key
        - name
        - kind
        - _links
        - tags
        - _creationDate
        - dataSource
      title: MetricListingRep
    MetricCollectionRep:
      type: object
      properties:
        items:
          type: array
          items:
            $ref: '#/components/schemas/MetricListingRep'
          description: An array of metrics
        _links:
          type: object
          additionalProperties:
            $ref: '#/components/schemas/Link'
          description: The location and content type of related resources
        totalCount:
          type: integer
      title: MetricCollectionRep
    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
    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
  securitySchemes:
    ApiKey:
      type: apiKey
      in: header
      name: Authorization

```

## SDK Code Examples

```python
import requests

url = "https://app.launchdarkly.com/api/v2/metrics/projectKey"

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

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

print(response.json())
```

```javascript
const url = 'https://app.launchdarkly.com/api/v2/metrics/projectKey';
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/metrics/projectKey"

	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/metrics/projectKey")

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/metrics/projectKey")
  .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/metrics/projectKey', [
  'headers' => [
    'Authorization' => '<apiKey>',
  ],
]);

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

```csharp
using RestSharp;

var client = new RestClient("https://app.launchdarkly.com/api/v2/metrics/projectKey");
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/metrics/projectKey")! 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()
```