Code references

Code references is an Enterprise feature

Code references is available to customers on an Enterprise plan. To learn more, read about our pricing. To upgrade your plan, contact Sales.

Use ld-find-code-refs

LaunchDarkly provides the ld-find-code-refs utility that creates repository connections, generates code reference data, and creates calls to the code references API. Most customers do not need to call this API directly.

The code references API provides access to all resources related to each connected repository, and associated feature flag code reference data for all branches. To learn more, read Code references.

List extinctions

Get a list of all extinctions. LaunchDarkly creates an extinction event after you remove all code references to a flag. To learn more, read About extinction events.

Request
query Parameters
repoName
string <string>

Filter results to a specific repository

branchName
string <string>

Filter results to a specific branch. By default, only the default branch will be queried for extinctions.

projKey
string <string>

Filter results to a specific project

flagKey
string <string>

Filter results to a specific flag key

from
integer <int64>

Filter results to a specific timeframe based on commit time, expressed as a Unix epoch time in milliseconds. Must be used with to.

to
integer <int64>

Filter results to a specific timeframe based on commit time, expressed as a Unix epoch time in milliseconds. Must be used with from.

Responses
200

Extinction collection response

401

Invalid access token

403

Forbidden

429

Rate limited

get/api/v2/code-refs/extinctions
Request samples
Response samples
application/json
{
  • "_links": {
    },
  • "items": {
    }
}

List repositories

Get a list of connected repositories. Optionally, you can include branch metadata with the withBranches query parameter. Embed references for the default branch with ReferencesForDefaultBranch. You can also filter the list of code references by project key and flag key.

Request
query Parameters
withBranches
string <string>

If set to any value, the endpoint returns repositories with associated branch data

withReferencesForDefaultBranch
string <string>

If set to any value, the endpoint returns repositories with associated branch data, as well as code references for the default git branch

projKey
string <string>

A LaunchDarkly project key. If provided, this filters code reference results to the specified project.

flagKey
string <string>

If set to any value, the endpoint returns repositories with associated branch data, as well as code references for the default git branch

Responses
200

Repository collection response

401

Invalid access token

403

Forbidden

429

Rate limited

get/api/v2/code-refs/repositories
Request samples
Response samples
application/json
{
  • "_links": {
    },
  • "items": [
    ]
}

Create repository

Create a repository with the specified name.

Request
Request Body schema: application/json
required
name
required
string

The repository name

sourceLink
string

A URL to access the repository

commitUrlTemplate
string

A template for constructing a valid URL to view the commit

hunkUrlTemplate
string

A template for constructing a valid URL to view the hunk

type
string

The type of repository. If not specified, the default value is custom.

Enum: "bitbucket" "custom" "github" "gitlab"
defaultBranch
string

The repository's default branch. If not specified, the default value is main.

Responses
200

Repository response

400

Invalid request

401

Invalid access token

403

Forbidden

409

Status conflict

429

Rate limited

post/api/v2/code-refs/repositories
Request samples
application/json
Response samples
application/json
{
  • "name": "LaunchDarkly-Docs",
  • "type": "github",
  • "defaultBranch": "main",
  • "enabled": true,
  • "version": 3,
  • "branches": [
    ],
  • "_links": {
    },
  • "_access": {
    }
}

Get repository

Get a single repository by name.

Request
path Parameters
repo
required
string <string>

The repository name

Responses
200

Repository response

400

Invalid request

401

Invalid access token

403

Forbidden

404

Invalid resource identifier

429

Rate limited

get/api/v2/code-refs/repositories/{repo}
Request samples
Response samples
application/json
{
  • "name": "LaunchDarkly-Docs",
  • "type": "github",
  • "defaultBranch": "main",
  • "enabled": true,
  • "version": 3,
  • "branches": [
    ],
  • "_links": {
    },
  • "_access": {
    }
}

Update repository

Update a repository's settings. Updating repository settings uses a JSON patch or JSON merge patch representation of the desired changes. To learn more, read Updates.

Request
path Parameters
repo
required
string <string>

The repository name

Request Body schema: application/json
required
Array
op
required
string

The type of operation to perform

path
required
string

A JSON Pointer string specifying the part of the document to operate on

value
any

A JSON value used in "add", "replace", and "test" operations

Responses
200

Repository response

400

Invalid request

401

Invalid access token

403

Forbidden

404

Invalid resource identifier

429

Rate limited

patch/api/v2/code-refs/repositories/{repo}
Request samples
application/json
[
  • {
    }
]
Response samples
application/json
{
  • "name": "LaunchDarkly-Docs",
  • "type": "github",
  • "defaultBranch": "main",
  • "enabled": true,
  • "version": 3,
  • "branches": [
    ],
  • "_links": {
    },
  • "_access": {
    }
}

Delete repository

Delete a repository with the specified name.

Request
path Parameters
repo
required
string <string>

The repository name

Responses
204

Action succeeded

400

Invalid request

401

Invalid access token

403

Forbidden

404

Invalid resource identifier

429

Rate limited

delete/api/v2/code-refs/repositories/{repo}
Request samples
Response samples
application/json
{
  • "code": "invalid_request",
  • "message": "Invalid request body"
}

Delete branches

Asynchronously delete a number of branches.

Request
path Parameters
repo
required
string <string>

The repository name to delete branches for.

Request Body schema: application/json
required
Array
string
Responses
200

Action succeeded

400

Invalid request

401

Invalid access token

403

Forbidden

404

Invalid resource identifier

429

Rate limited

post/api/v2/code-refs/repositories/{repo}/branch-delete-tasks
Request samples
application/json
[
  • "branch-to-be-deleted",
  • "another-branch-to-be-deleted"
]
Response samples
application/json
{
  • "code": "invalid_request",
  • "message": "Invalid request body"
}

List branches

Get a list of branches.

Request
path Parameters
repo
required
string <string>

The repository name

Responses
200

Branch collection response

400

Invalid request

401

Invalid access token

403

Forbidden

404

Invalid resource identifier

429

Rate limited

get/api/v2/code-refs/repositories/{repo}/branches
Request samples
Response samples
application/json
{
  • "_links": {
    },
  • "items": [
    ]
}

Get branch

Get a specific branch in a repository.

Request
path Parameters
repo
required
string <string>

The repository name

branch
required
string <string>

The url-encoded branch name

query Parameters
projKey
string <string>

Filter results to a specific project

flagKey
string <string>

Filter results to a specific flag key

Responses
200

Branch response

400

Invalid request

401

Invalid access token

403

Forbidden

404

Invalid resource identifier

429

Rate limited

get/api/v2/code-refs/repositories/{repo}/branches/{branch}
Request samples
Response samples
application/json
{
  • "name": "main",
  • "head": "a94a8fe5ccb19ba61c4c0873d391e987982fbbd3",
  • "updateSequenceId": 25,
  • "syncTime": 0,
  • "references": [
    ],
  • "_links": {
    }
}

Upsert branch

Create a new branch if it doesn't exist, or update the branch if it already exists.

Request
path Parameters
repo
required
string <string>

The repository name

branch
required
string <string>

The URL-encoded branch name

Request Body schema: application/json
required
name
required
string

The branch name

head
required
string

An ID representing the branch HEAD. For example, a commit SHA.

updateSequenceId
integer <int64>

An optional ID used to prevent older data from overwriting newer data. If no sequence ID is included, the newly submitted data will always be saved.

syncTime
required
integer <int64> (UnixMillis)
Array of objects (ReferenceRep)

An array of flag references found on the branch

commitTime
integer <int64> (UnixMillis)
Responses
200

Action succeeded

400

Invalid request

401

Invalid access token

403

Forbidden

404

Invalid resource identifier

409

Status conflict

429

Rate limited

put/api/v2/code-refs/repositories/{repo}/branches/{branch}
Request samples
application/json
{
  • "name": "main",
  • "head": "a94a8fe5ccb19ba61c4c0873d391e987982fbbd3",
  • "updateSequenceId": 25,
  • "syncTime": 0,
  • "references": [
    ],
  • "commitTime": 0
}
Response samples
application/json
{
  • "code": "invalid_request",
  • "message": "Invalid request body"
}

Create extinction

Create a new extinction.

Request
path Parameters
repo
required
string <string>

The repository name

branch
required
string <string>

The URL-encoded branch name

Request Body schema: application/json
required
Array
revision
required
string

The identifier for the revision where flag became extinct. For example, a commit SHA.

message
required
string

Description of the extinction. For example, the commit message for the revision.

time
required
integer <int64> (UnixMillis)
flagKey
required
string

The feature flag key

projKey
required
string

The project key

Responses
200

Action succeeded

400

Invalid request

401

Invalid access token

403

Forbidden

404

Invalid resource identifier

429

Rate limited

post/api/v2/code-refs/repositories/{repo}/branches/{branch}/extinction-events
Request samples
application/json
[
  • {
    }
]
Response samples
application/json
{
  • "code": "invalid_request",
  • "message": "Invalid request body"
}

Get links to code reference repositories for each project

Get links for all projects that have code references.

Responses
200

Statistic root response

401

Invalid access token

403

Forbidden

404

Invalid resource identifier

429

Rate limited

get/api/v2/code-refs/statistics
Request samples
Response samples
application/json
{
  • "projects": [
    ],
  • "self": {
    }
}

Get code references statistics for flags

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.

Request
path Parameters
projectKey
required
string <string>

The project key

query Parameters
flagKey
string <string>

Filter results to a specific flag key

Responses
200

Statistic collection response

401

Invalid access token

403

Forbidden

404

Invalid resource identifier

429

Rate limited

get/api/v2/code-refs/statistics/{projectKey}
Request samples
Response samples
application/json
{
  • "flags": {
    },
  • "_links": {
    }
}