Code references

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 connected repository, and associated feature flag code reference data for all branches.

List extinctions

Get a list of all extinctions.

Request
Security:
ApiKey (readwrite)
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

Responses
200

Extinction collection response

401

Invalid access token

403

Forbidden

429

Rate limited

get/api/v2/code-refs/extinctions
Request samples
curl -i -X GET \
  https://app.launchdarkly.com/api/v2/code-refs/extinctions \
  -H 'Authorization: YOUR_API_KEY_HERE'
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
Security:
ApiKey (readwrite)
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
curl -i -X GET \
  https://app.launchdarkly.com/api/v2/code-refs/repositories \
  -H 'Authorization: YOUR_API_KEY_HERE'
Response samples
application/json
{
  • "_links": {
    },
  • "items": [
    ]
}

Create repository

Create a repository with the specified name.

Request
Security:
ApiKey (readwrite)
Request Body schema: application/json
name
required
string
sourceLink
string
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

Optionally specify a repository type. The default value is custom

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

The default branch, if not specified, is master

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",
  • "commitUrlTemplate": "/commit/${sha}",
  • "hunkUrlTemplate": "/blob/${sha}/${filePath}#L${lineNumber}",
  • "type": "github",
  • "defaultBranch": "main",
  • "enabled": true,
  • "version": 3,
  • "branches": [
    ],
  • "_links": {
    },
  • "_access": {
    }
}

Get repository

Get a single repository by name.

Request
Security:
ApiKey (readwrite)
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
curl -i -X GET \
  https://app.launchdarkly.com/api/v2/code-refs/repositories/:repo \
  -H 'Authorization: YOUR_API_KEY_HERE'
Response samples
application/json
{
  • "name": "LaunchDarkly-Docs",
  • "commitUrlTemplate": "/commit/${sha}",
  • "hunkUrlTemplate": "/blob/${sha}/${filePath}#L${lineNumber}",
  • "type": "github",
  • "defaultBranch": "main",
  • "enabled": true,
  • "version": 3,
  • "branches": [
    ],
  • "_links": {
    },
  • "_access": {
    }
}

Update repository

Update a repository's settings. The request must be a valid JSON Patch document describing the changes to be made to the repository.

Request
Security:
ApiKey (readwrite)
path Parameters
repo
required
string <string>

The repository name

Request Body schema: application/json
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
required
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",
  • "commitUrlTemplate": "/commit/${sha}",
  • "hunkUrlTemplate": "/blob/${sha}/${filePath}#L${lineNumber}",
  • "type": "github",
  • "defaultBranch": "main",
  • "enabled": true,
  • "version": 3,
  • "branches": [
    ],
  • "_links": {
    },
  • "_access": {
    }
}

Delete repository

Delete a repository with the specified name

Request
Security:
ApiKey (readwrite)
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
curl -i -X DELETE \
  https://app.launchdarkly.com/api/v2/code-refs/repositories/:repo \
  -H 'Authorization: YOUR_API_KEY_HERE'
Response samples
application/json
{
  • "code": "invalid_request",
  • "message": "invalid request body"
}

Delete branches

Asynchronously delete a number of branches.

Request
Security:
ApiKey (readwrite)
path Parameters
repo
required
string <string>

The repository name to delete branches for.

Request Body schema: application/json
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
[
  • "string"
]
Response samples
application/json
{
  • "code": "invalid_request",
  • "message": "invalid request body"
}

List branches

Get a list of branches.

Request
Security:
ApiKey (readwrite)
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
curl -i -X GET \
  https://app.launchdarkly.com/api/v2/code-refs/repositories/:repo/branches \
  -H 'Authorization: YOUR_API_KEY_HERE'
Response samples
application/json
{
  • "_links": {
    },
  • "items": [
    ]
}

Get branch

Get a specific branch in a repository

Request
Security:
ApiKey (readwrite)
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
curl -i -X GET \
  https://app.launchdarkly.com/api/v2/code-refs/repositories/:repo/branches/:branch \
  -H 'Authorization: YOUR_API_KEY_HERE'
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 updates the branch if it already exists.

Request
Security:
ApiKey (readwrite)
path Parameters
repo
required
string <string>

The repository name

branch
required
string <string>

The url-encoded branch name

Request Body schema: application/json
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

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": [
    ]
}
Response samples
application/json
{
  • "code": "invalid_request",
  • "message": "invalid request body"
}

Create extinction

Create a new extinction

Request
Security:
ApiKey (readwrite)
path Parameters
repo
required
string <string>

The repository name

branch
required
string <string>

The url-encoded branch name

Request Body schema: application/json
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.

Request
Security:
ApiKey (readwrite)
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
curl -i -X GET \
  https://app.launchdarkly.com/api/v2/code-refs/statistics \
  -H 'Authorization: YOUR_API_KEY_HERE'
Response samples
application/json
{
  • "projects": [
    ],
  • "self": {
    }
}

Get number of code references for flags

Get the number of code references across repositories for all flags in your project that have code references in the default branch (for example: master). You can optionally include the flagKey query parameter to get the number of code references across repositories for a single flag. This endpoint returns the number of times your flag keys are referenced in your repositories. You can filter to a single flag with by passing in a flag key.

Request
Security:
ApiKey (readwrite)
path Parameters
projKey
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/{projKey}
Request samples
curl -i -X GET \
  https://app.launchdarkly.com/api/v2/code-refs/statistics/:projKey \
  -H 'Authorization: YOUR_API_KEY_HERE'
Response samples
application/json
{
  • "flags": {
    },
  • "_links": {
    }
}