Upsert branch
curl --request PUT \
--url https://app.launchdarkly.com/api/v2/code-refs/repositories/{repo}/branches/{branch} \
--header 'Authorization: <api-key>' \
--header 'Content-Type: application/json' \
--data @- <<EOF
{
"name": "main",
"head": "a94a8fe5ccb19ba61c4c0873d391e987982fbbd3",
"syncTime": "1636558831870",
"updateSequenceId": 25,
"references": [
{
"path": "/main/index.js",
"hunks": [
{
"startingLineNumber": 45,
"lines": "var enableFeature = 'enable-feature';",
"projKey": "default",
"flagKey": "enable-feature",
"aliases": [
"enableFeature",
"EnableFeature"
]
}
],
"hint": "javascript"
}
],
"commitTime": "1636558831870"
}
EOFimport requests
url = "https://app.launchdarkly.com/api/v2/code-refs/repositories/{repo}/branches/{branch}"
payload = {
"name": "main",
"head": "a94a8fe5ccb19ba61c4c0873d391e987982fbbd3",
"syncTime": "1636558831870",
"updateSequenceId": 25,
"references": [
{
"path": "/main/index.js",
"hunks": [
{
"startingLineNumber": 45,
"lines": "var enableFeature = 'enable-feature';",
"projKey": "default",
"flagKey": "enable-feature",
"aliases": ["enableFeature", "EnableFeature"]
}
],
"hint": "javascript"
}
],
"commitTime": "1636558831870"
}
headers = {
"Authorization": "<api-key>",
"Content-Type": "application/json"
}
response = requests.put(url, json=payload, headers=headers)
print(response.text)const options = {
method: 'PUT',
headers: {Authorization: '<api-key>', 'Content-Type': 'application/json'},
body: JSON.stringify({
name: 'main',
head: 'a94a8fe5ccb19ba61c4c0873d391e987982fbbd3',
syncTime: '1636558831870',
updateSequenceId: 25,
references: [
{
path: '/main/index.js',
hunks: [
{
startingLineNumber: 45,
lines: 'var enableFeature = \'enable-feature\';',
projKey: 'default',
flagKey: 'enable-feature',
aliases: ['enableFeature', 'EnableFeature']
}
],
hint: 'javascript'
}
],
commitTime: '1636558831870'
})
};
fetch('https://app.launchdarkly.com/api/v2/code-refs/repositories/{repo}/branches/{branch}', options)
.then(res => res.json())
.then(res => console.log(res))
.catch(err => console.error(err));<?php
$curl = curl_init();
curl_setopt_array($curl, [
CURLOPT_URL => "https://app.launchdarkly.com/api/v2/code-refs/repositories/{repo}/branches/{branch}",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "PUT",
CURLOPT_POSTFIELDS => json_encode([
'name' => 'main',
'head' => 'a94a8fe5ccb19ba61c4c0873d391e987982fbbd3',
'syncTime' => '1636558831870',
'updateSequenceId' => 25,
'references' => [
[
'path' => '/main/index.js',
'hunks' => [
[
'startingLineNumber' => 45,
'lines' => 'var enableFeature = \'enable-feature\';',
'projKey' => 'default',
'flagKey' => 'enable-feature',
'aliases' => [
'enableFeature',
'EnableFeature'
]
]
],
'hint' => 'javascript'
]
],
'commitTime' => '1636558831870'
]),
CURLOPT_HTTPHEADER => [
"Authorization: <api-key>",
"Content-Type: application/json"
],
]);
$response = curl_exec($curl);
$err = curl_error($curl);
curl_close($curl);
if ($err) {
echo "cURL Error #:" . $err;
} else {
echo $response;
}package main
import (
"fmt"
"strings"
"net/http"
"io"
)
func main() {
url := "https://app.launchdarkly.com/api/v2/code-refs/repositories/{repo}/branches/{branch}"
payload := strings.NewReader("{\n \"name\": \"main\",\n \"head\": \"a94a8fe5ccb19ba61c4c0873d391e987982fbbd3\",\n \"syncTime\": \"1636558831870\",\n \"updateSequenceId\": 25,\n \"references\": [\n {\n \"path\": \"/main/index.js\",\n \"hunks\": [\n {\n \"startingLineNumber\": 45,\n \"lines\": \"var enableFeature = 'enable-feature';\",\n \"projKey\": \"default\",\n \"flagKey\": \"enable-feature\",\n \"aliases\": [\n \"enableFeature\",\n \"EnableFeature\"\n ]\n }\n ],\n \"hint\": \"javascript\"\n }\n ],\n \"commitTime\": \"1636558831870\"\n}")
req, _ := http.NewRequest("PUT", url, payload)
req.Header.Add("Authorization", "<api-key>")
req.Header.Add("Content-Type", "application/json")
res, _ := http.DefaultClient.Do(req)
defer res.Body.Close()
body, _ := io.ReadAll(res.Body)
fmt.Println(string(body))
}HttpResponse<String> response = Unirest.put("https://app.launchdarkly.com/api/v2/code-refs/repositories/{repo}/branches/{branch}")
.header("Authorization", "<api-key>")
.header("Content-Type", "application/json")
.body("{\n \"name\": \"main\",\n \"head\": \"a94a8fe5ccb19ba61c4c0873d391e987982fbbd3\",\n \"syncTime\": \"1636558831870\",\n \"updateSequenceId\": 25,\n \"references\": [\n {\n \"path\": \"/main/index.js\",\n \"hunks\": [\n {\n \"startingLineNumber\": 45,\n \"lines\": \"var enableFeature = 'enable-feature';\",\n \"projKey\": \"default\",\n \"flagKey\": \"enable-feature\",\n \"aliases\": [\n \"enableFeature\",\n \"EnableFeature\"\n ]\n }\n ],\n \"hint\": \"javascript\"\n }\n ],\n \"commitTime\": \"1636558831870\"\n}")
.asString();require 'uri'
require 'net/http'
url = URI("https://app.launchdarkly.com/api/v2/code-refs/repositories/{repo}/branches/{branch}")
http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true
request = Net::HTTP::Put.new(url)
request["Authorization"] = '<api-key>'
request["Content-Type"] = 'application/json'
request.body = "{\n \"name\": \"main\",\n \"head\": \"a94a8fe5ccb19ba61c4c0873d391e987982fbbd3\",\n \"syncTime\": \"1636558831870\",\n \"updateSequenceId\": 25,\n \"references\": [\n {\n \"path\": \"/main/index.js\",\n \"hunks\": [\n {\n \"startingLineNumber\": 45,\n \"lines\": \"var enableFeature = 'enable-feature';\",\n \"projKey\": \"default\",\n \"flagKey\": \"enable-feature\",\n \"aliases\": [\n \"enableFeature\",\n \"EnableFeature\"\n ]\n }\n ],\n \"hint\": \"javascript\"\n }\n ],\n \"commitTime\": \"1636558831870\"\n}"
response = http.request(request)
puts response.read_body{
"code": "invalid_request",
"message": "Invalid request body"
}{
"code": "unauthorized",
"message": "Invalid access token"
}{
"code": "forbidden",
"message": "Forbidden. Access to the requested resource was denied."
}{
"code": "not_found",
"message": "Invalid resource identifier"
}{
"code": "optimistic_locking_error",
"message": "Conflict. Optimistic lock error. Try again later."
}{
"code": "rate_limited",
"message": "You've exceeded the API rate limit. Try again later."
}Upsert branch
Create a new branch if it doesn’t exist, or update the branch if it already exists.
PUT
/
api
/
v2
/
code-refs
/
repositories
/
{repo}
/
branches
/
{branch}
Upsert branch
curl --request PUT \
--url https://app.launchdarkly.com/api/v2/code-refs/repositories/{repo}/branches/{branch} \
--header 'Authorization: <api-key>' \
--header 'Content-Type: application/json' \
--data @- <<EOF
{
"name": "main",
"head": "a94a8fe5ccb19ba61c4c0873d391e987982fbbd3",
"syncTime": "1636558831870",
"updateSequenceId": 25,
"references": [
{
"path": "/main/index.js",
"hunks": [
{
"startingLineNumber": 45,
"lines": "var enableFeature = 'enable-feature';",
"projKey": "default",
"flagKey": "enable-feature",
"aliases": [
"enableFeature",
"EnableFeature"
]
}
],
"hint": "javascript"
}
],
"commitTime": "1636558831870"
}
EOFimport requests
url = "https://app.launchdarkly.com/api/v2/code-refs/repositories/{repo}/branches/{branch}"
payload = {
"name": "main",
"head": "a94a8fe5ccb19ba61c4c0873d391e987982fbbd3",
"syncTime": "1636558831870",
"updateSequenceId": 25,
"references": [
{
"path": "/main/index.js",
"hunks": [
{
"startingLineNumber": 45,
"lines": "var enableFeature = 'enable-feature';",
"projKey": "default",
"flagKey": "enable-feature",
"aliases": ["enableFeature", "EnableFeature"]
}
],
"hint": "javascript"
}
],
"commitTime": "1636558831870"
}
headers = {
"Authorization": "<api-key>",
"Content-Type": "application/json"
}
response = requests.put(url, json=payload, headers=headers)
print(response.text)const options = {
method: 'PUT',
headers: {Authorization: '<api-key>', 'Content-Type': 'application/json'},
body: JSON.stringify({
name: 'main',
head: 'a94a8fe5ccb19ba61c4c0873d391e987982fbbd3',
syncTime: '1636558831870',
updateSequenceId: 25,
references: [
{
path: '/main/index.js',
hunks: [
{
startingLineNumber: 45,
lines: 'var enableFeature = \'enable-feature\';',
projKey: 'default',
flagKey: 'enable-feature',
aliases: ['enableFeature', 'EnableFeature']
}
],
hint: 'javascript'
}
],
commitTime: '1636558831870'
})
};
fetch('https://app.launchdarkly.com/api/v2/code-refs/repositories/{repo}/branches/{branch}', options)
.then(res => res.json())
.then(res => console.log(res))
.catch(err => console.error(err));<?php
$curl = curl_init();
curl_setopt_array($curl, [
CURLOPT_URL => "https://app.launchdarkly.com/api/v2/code-refs/repositories/{repo}/branches/{branch}",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "PUT",
CURLOPT_POSTFIELDS => json_encode([
'name' => 'main',
'head' => 'a94a8fe5ccb19ba61c4c0873d391e987982fbbd3',
'syncTime' => '1636558831870',
'updateSequenceId' => 25,
'references' => [
[
'path' => '/main/index.js',
'hunks' => [
[
'startingLineNumber' => 45,
'lines' => 'var enableFeature = \'enable-feature\';',
'projKey' => 'default',
'flagKey' => 'enable-feature',
'aliases' => [
'enableFeature',
'EnableFeature'
]
]
],
'hint' => 'javascript'
]
],
'commitTime' => '1636558831870'
]),
CURLOPT_HTTPHEADER => [
"Authorization: <api-key>",
"Content-Type: application/json"
],
]);
$response = curl_exec($curl);
$err = curl_error($curl);
curl_close($curl);
if ($err) {
echo "cURL Error #:" . $err;
} else {
echo $response;
}package main
import (
"fmt"
"strings"
"net/http"
"io"
)
func main() {
url := "https://app.launchdarkly.com/api/v2/code-refs/repositories/{repo}/branches/{branch}"
payload := strings.NewReader("{\n \"name\": \"main\",\n \"head\": \"a94a8fe5ccb19ba61c4c0873d391e987982fbbd3\",\n \"syncTime\": \"1636558831870\",\n \"updateSequenceId\": 25,\n \"references\": [\n {\n \"path\": \"/main/index.js\",\n \"hunks\": [\n {\n \"startingLineNumber\": 45,\n \"lines\": \"var enableFeature = 'enable-feature';\",\n \"projKey\": \"default\",\n \"flagKey\": \"enable-feature\",\n \"aliases\": [\n \"enableFeature\",\n \"EnableFeature\"\n ]\n }\n ],\n \"hint\": \"javascript\"\n }\n ],\n \"commitTime\": \"1636558831870\"\n}")
req, _ := http.NewRequest("PUT", url, payload)
req.Header.Add("Authorization", "<api-key>")
req.Header.Add("Content-Type", "application/json")
res, _ := http.DefaultClient.Do(req)
defer res.Body.Close()
body, _ := io.ReadAll(res.Body)
fmt.Println(string(body))
}HttpResponse<String> response = Unirest.put("https://app.launchdarkly.com/api/v2/code-refs/repositories/{repo}/branches/{branch}")
.header("Authorization", "<api-key>")
.header("Content-Type", "application/json")
.body("{\n \"name\": \"main\",\n \"head\": \"a94a8fe5ccb19ba61c4c0873d391e987982fbbd3\",\n \"syncTime\": \"1636558831870\",\n \"updateSequenceId\": 25,\n \"references\": [\n {\n \"path\": \"/main/index.js\",\n \"hunks\": [\n {\n \"startingLineNumber\": 45,\n \"lines\": \"var enableFeature = 'enable-feature';\",\n \"projKey\": \"default\",\n \"flagKey\": \"enable-feature\",\n \"aliases\": [\n \"enableFeature\",\n \"EnableFeature\"\n ]\n }\n ],\n \"hint\": \"javascript\"\n }\n ],\n \"commitTime\": \"1636558831870\"\n}")
.asString();require 'uri'
require 'net/http'
url = URI("https://app.launchdarkly.com/api/v2/code-refs/repositories/{repo}/branches/{branch}")
http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true
request = Net::HTTP::Put.new(url)
request["Authorization"] = '<api-key>'
request["Content-Type"] = 'application/json'
request.body = "{\n \"name\": \"main\",\n \"head\": \"a94a8fe5ccb19ba61c4c0873d391e987982fbbd3\",\n \"syncTime\": \"1636558831870\",\n \"updateSequenceId\": 25,\n \"references\": [\n {\n \"path\": \"/main/index.js\",\n \"hunks\": [\n {\n \"startingLineNumber\": 45,\n \"lines\": \"var enableFeature = 'enable-feature';\",\n \"projKey\": \"default\",\n \"flagKey\": \"enable-feature\",\n \"aliases\": [\n \"enableFeature\",\n \"EnableFeature\"\n ]\n }\n ],\n \"hint\": \"javascript\"\n }\n ],\n \"commitTime\": \"1636558831870\"\n}"
response = http.request(request)
puts response.read_body{
"code": "invalid_request",
"message": "Invalid request body"
}{
"code": "unauthorized",
"message": "Invalid access token"
}{
"code": "forbidden",
"message": "Forbidden. Access to the requested resource was denied."
}{
"code": "not_found",
"message": "Invalid resource identifier"
}{
"code": "optimistic_locking_error",
"message": "Conflict. Optimistic lock error. Try again later."
}{
"code": "rate_limited",
"message": "You've exceeded the API rate limit. Try again later."
}Authorizations
Path Parameters
The repository name
The URL-encoded branch name
Body
application/json
The branch name
Example:
"main"
An ID representing the branch HEAD. For example, a commit SHA.
Example:
"a94a8fe5ccb19ba61c4c0873d391e987982fbbd3"
A timestamp indicating when the branch was last synced
Example:
"1636558831870"
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.
Example:
25
An array of flag references found on the branch
Show child attributes
Show child attributes
A timestamp of the current commit
Example:
"1636558831870"
Response
Action succeeded