# Get code references statistics for flags

GET https://app.launchdarkly.com/api/v2/code-refs/statistics/{projectKey}

Get statistics about all the code references across repositories for all flags in your project that have code references in the default branch, for example, `main`. Optionally, you can include the `flagKey` query parameter to limit your request to statistics about code references for a single flag. This endpoint returns the number of references to your flag keys in your repositories, as well as a link to each repository.

Reference: https://launchdarkly.com/docs/api/code-references/get-statistics

## OpenAPI Specification

```yaml
openapi: 3.1.0
info:
  title: LaunchDarkly REST API
  version: 1.0.0
paths:
  /api/v2/code-refs/statistics/{projectKey}:
    get:
      operationId: get-statistics
      summary: Get code references statistics for flags
      description: >-
        Get statistics about all the code references across repositories for all
        flags in your project that have code references in the default branch,
        for example, `main`. Optionally, you can include the `flagKey` query
        parameter to limit your request to statistics about code references for
        a single flag. This endpoint returns the number of references to your
        flag keys in your repositories, as well as a link to each repository.
      tags:
        - subpackage_codeReferences
      parameters:
        - name: projectKey
          in: path
          description: The project key
          required: true
          schema:
            type: string
            format: string
        - name: flagKey
          in: query
          description: Filter results to a specific flag key
          required: false
          schema:
            type: string
            format: string
        - name: Authorization
          in: header
          required: true
          schema:
            type: string
      responses:
        '200':
          description: Statistic collection response
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/StatisticCollectionRep'
        '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'
        '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:
    StatisticRepType:
      type: string
      enum:
        - bitbucket
        - custom
        - github
        - gitlab
      description: The type of repository
      title: StatisticRepType
    Link:
      type: object
      properties:
        href:
          type: string
          description: The URL of the link
        type:
          type: string
          description: The type of the link
      title: Link
    UnixMillis:
      type: integer
      format: int64
      title: UnixMillis
    StatisticRep:
      type: object
      properties:
        name:
          type: string
          description: The repository name
        type:
          $ref: '#/components/schemas/StatisticRepType'
          description: The type of repository
        sourceLink:
          type: string
          description: A URL to access the repository
        defaultBranch:
          type: string
          description: The repository's default branch
        enabled:
          type: boolean
          description: Whether or not a repository is enabled for code reference scanning
        version:
          type: integer
          description: The version of the repository's saved information
        hunkCount:
          type: integer
          description: >-
            The number of code reference hunks in which the flag appears in this
            repository
        fileCount:
          type: integer
          description: The number of files in which the flag appears in this repository
        _links:
          type: object
          additionalProperties:
            $ref: '#/components/schemas/Link'
          description: The location and content type of related resources
        latestCommitTime:
          $ref: '#/components/schemas/UnixMillis'
          description: >-
            The timestamp of the latest commit in the repository including the
            flag
      required:
        - name
        - type
        - sourceLink
        - defaultBranch
        - enabled
        - version
        - hunkCount
        - fileCount
        - _links
      title: StatisticRep
    StatisticCollectionRep:
      type: object
      properties:
        flags:
          type: object
          additionalProperties:
            type: array
            items:
              $ref: '#/components/schemas/StatisticRep'
          description: >-
            A map of flag keys to a list of code reference statistics for each
            code repository in which the flag key appears
        _links:
          type: object
          additionalProperties:
            $ref: '#/components/schemas/Link'
          description: The location and content type of related resources
      required:
        - flags
        - _links
      title: StatisticCollectionRep
    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
    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/code-refs/statistics/projectKey"

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

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

print(response.json())
```

```javascript
const url = 'https://app.launchdarkly.com/api/v2/code-refs/statistics/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/code-refs/statistics/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/code-refs/statistics/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/code-refs/statistics/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/code-refs/statistics/projectKey', [
  'headers' => [
    'Authorization' => '<apiKey>',
  ],
]);

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

```csharp
using RestSharp;

var client = new RestClient("https://app.launchdarkly.com/api/v2/code-refs/statistics/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/code-refs/statistics/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()
```