# Patch release for flag

PATCH https://app.launchdarkly.com/api/v2/flags/{projectKey}/{flagKey}/release
Content-Type: application/json

This endpoint is only available for releases that are part of a legacy release pipeline. Releases for new release pipelines should use the [Update phase status for release](https://launchdarkly.com/docs/api/releases-beta/update-phase-status) endpoint.

Update currently active release for a flag. Updating releases requires the [JSON patch](https://datatracker.ietf.org/doc/html/rfc6902) format. To learn more, read [Updates](https://launchdarkly.com/docs/api#updates).

You can only use this endpoint to mark a release phase complete or incomplete. To indicate which phase to update, use the array index in the `path`. For example, to mark the first phase of a release as complete, use the following request body:

```
  [
    {
      "op": "replace",
      "path": "/phase/0/complete",
      "value": true
    }
  ]
```


Reference: https://launchdarkly.com/docs/api/releases-beta/patch-release-by-flag-key

## OpenAPI Specification

```yaml
openapi: 3.1.0
info:
  title: LaunchDarkly REST API
  version: 1.0.0
paths:
  /api/v2/flags/{projectKey}/{flagKey}/release:
    patch:
      operationId: patch-release-by-flag-key
      summary: Patch release for flag
      description: >
        This endpoint is only available for releases that are part of a legacy
        release pipeline. Releases for new release pipelines should use the
        [Update phase status for
        release](https://launchdarkly.com/docs/api/releases-beta/update-phase-status)
        endpoint.


        Update currently active release for a flag. Updating releases requires
        the [JSON patch](https://datatracker.ietf.org/doc/html/rfc6902) format.
        To learn more, read
        [Updates](https://launchdarkly.com/docs/api#updates).


        You can only use this endpoint to mark a release phase complete or
        incomplete. To indicate which phase to update, use the array index in
        the `path`. For example, to mark the first phase of a release as
        complete, use the following request body:


        ```
          [
            {
              "op": "replace",
              "path": "/phase/0/complete",
              "value": true
            }
          ]
        ```
      tags:
        - subpackage_releasesBeta
      parameters:
        - name: projectKey
          in: path
          description: The project key
          required: true
          schema:
            type: string
            format: string
        - name: flagKey
          in: path
          description: The flag key
          required: true
          schema:
            type: string
            format: string
        - name: Authorization
          in: header
          required: true
          schema:
            type: string
      responses:
        '200':
          description: Release response
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Release'
        '400':
          description: Invalid request
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/InvalidRequestErrorRep'
        '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'
      requestBody:
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/JSONPatch'
servers:
  - url: https://app.launchdarkly.com
  - url: https://app.launchdarkly.us
components:
  schemas:
    PatchOperation:
      type: object
      properties:
        op:
          type: string
          description: The type of operation to perform
        path:
          type: string
          description: >-
            A JSON Pointer string specifying the part of the document to operate
            on
        value:
          description: A JSON value used in "add", "replace", and "test" operations
      required:
        - op
        - path
      title: PatchOperation
    JSONPatch:
      type: array
      items:
        $ref: '#/components/schemas/PatchOperation'
      title: JSONPatch
    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
    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
    TokenSummary:
      type: object
      properties:
        _links:
          type: object
          additionalProperties:
            $ref: '#/components/schemas/Link'
        _id:
          type: string
        name:
          type: string
          description: The name of the token
        ending:
          type: string
          description: The last few characters of the token
        serviceToken:
          type: boolean
          description: Whether this is a service token
      title: TokenSummary
    CompletedBy:
      type: object
      properties:
        member:
          $ref: '#/components/schemas/MemberSummary'
          description: The LaunchDarkly member who marked this phase as complete
        token:
          $ref: '#/components/schemas/TokenSummary'
          description: The service token used to mark this phase as complete
      title: CompletedBy
    EnvironmentSummary:
      type: object
      properties:
        _links:
          type: object
          additionalProperties:
            $ref: '#/components/schemas/Link'
          description: The location and content type of related resources
        key:
          type: string
          description: A project-unique key for the environment
        name:
          type: string
          description: A human-friendly name for the environment
        color:
          type: string
          description: The color used to indicate this environment in the UI
      required:
        - _links
        - key
        - name
        - color
      title: EnvironmentSummary
    ReleaseStrategy:
      type: string
      title: ReleaseStrategy
    ReleaseGuardianConfiguration:
      type: object
      properties:
        monitoringWindowMilliseconds:
          type: integer
          format: int64
          description: The monitoring window in milliseconds
        rolloutWeight:
          type: integer
          description: The rollout weight percentage
        rollbackOnRegression:
          type: boolean
          description: Whether or not to roll back on regression
        randomizationUnit:
          type: string
          description: The randomization unit for the measured rollout
      required:
        - monitoringWindowMilliseconds
        - rolloutWeight
        - rollbackOnRegression
      title: ReleaseGuardianConfiguration
    AudienceConfiguration:
      type: object
      properties:
        releaseStrategy:
          $ref: '#/components/schemas/ReleaseStrategy'
          description: The release strategy
        requireApproval:
          type: boolean
          description: Whether or not the audience requires approval
        notifyMemberIds:
          type: array
          items:
            type: string
          description: >-
            An array of member IDs. These members are notified to review the
            approval request.
        notifyTeamKeys:
          type: array
          items:
            type: string
          description: >-
            An array of team keys. The members of these teams are notified to
            review the approval request.
        releaseGuardianConfiguration:
          $ref: '#/components/schemas/ReleaseGuardianConfiguration'
          description: The configuration for the release guardian.
      required:
        - releaseStrategy
        - requireApproval
      title: AudienceConfiguration
    AudienceStatus:
      type: string
      title: AudienceStatus
    ReleaseAudience:
      type: object
      properties:
        _id:
          type: string
          description: The audience ID
        _links:
          type: object
          additionalProperties:
            $ref: '#/components/schemas/Link'
          description: The location and content type of related resources
        environment:
          $ref: '#/components/schemas/EnvironmentSummary'
          description: >-
            Details about the environment. If the environment is deleted, this
            field will be omitted.
        name:
          type: string
          description: The release phase name
        configuration:
          $ref: '#/components/schemas/AudienceConfiguration'
          description: The audience configuration
        segmentKeys:
          type: array
          items:
            type: string
          description: A list of segment keys
        status:
          $ref: '#/components/schemas/AudienceStatus'
          description: The audience status
        _ruleIds:
          type: array
          items:
            type: string
          description: The rules IDs added or updated by this audience
      required:
        - _id
        - name
      title: ReleaseAudience
    PhaseStatus:
      type: string
      title: PhaseStatus
    PhaseConfiguration:
      type: object
      properties: {}
      title: PhaseConfiguration
    ReleasePhase:
      type: object
      properties:
        _id:
          type: string
          description: The phase ID
        _name:
          type: string
          description: The release phase name
        complete:
          type: boolean
          description: Whether this phase is complete
        _creationDate:
          $ref: '#/components/schemas/UnixMillis'
          description: Timestamp of when the release phase was created
        _completionDate:
          $ref: '#/components/schemas/UnixMillis'
          description: Timestamp of when the release phase was completed
        _completedBy:
          $ref: '#/components/schemas/CompletedBy'
          description: Details about how this phase was marked as complete
        _audiences:
          type: array
          items:
            $ref: '#/components/schemas/ReleaseAudience'
          description: >-
            A logical grouping of one or more environments that share attributes
            for rolling out changes
        status:
          $ref: '#/components/schemas/PhaseStatus'
          description: Status of the phase
        started:
          type: boolean
          description: Whether or not this phase has started
        _startedDate:
          $ref: '#/components/schemas/UnixMillis'
          description: Timestamp of when the release phase was started
        configuration:
          $ref: '#/components/schemas/PhaseConfiguration'
          description: The phase configuration
      required:
        - _id
        - _name
        - complete
        - _creationDate
        - _audiences
      title: ReleasePhase
    Release:
      type: object
      properties:
        _links:
          type: object
          additionalProperties:
            $ref: '#/components/schemas/Link'
          description: The location and content type of related resources
        name:
          type: string
          description: The release pipeline name
        releasePipelineKey:
          type: string
          description: The release pipeline key
        releasePipelineDescription:
          type: string
          description: The release pipeline description
        phases:
          type: array
          items:
            $ref: '#/components/schemas/ReleasePhase'
          description: An ordered list of the release pipeline phases
        _version:
          type: integer
          description: The release version
        _releaseVariationId:
          type: string
          description: >-
            The chosen release variation ID to use across all phases of a
            release
        _canceledAt:
          $ref: '#/components/schemas/UnixMillis'
          description: Timestamp of when the release was canceled
      required:
        - name
        - releasePipelineKey
        - releasePipelineDescription
        - phases
        - _version
      title: Release
    InvalidRequestErrorRep:
      type: object
      properties:
        code:
          type: string
          description: Specific error code encountered
        message:
          type: string
          description: Description of the error
      required:
        - code
        - message
      title: InvalidRequestErrorRep
    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/flags/projectKey/flagKey/release"

payload = [
    {
        "op": "replace",
        "path": "/phases/0/complete"
    }
]
headers = {
    "Authorization": "<apiKey>",
    "Content-Type": "application/json"
}

response = requests.patch(url, json=payload, headers=headers)

print(response.json())
```

```javascript
const url = 'https://app.launchdarkly.com/api/v2/flags/projectKey/flagKey/release';
const options = {
  method: 'PATCH',
  headers: {Authorization: '<apiKey>', 'Content-Type': 'application/json'},
  body: '[{"op":"replace","path":"/phases/0/complete"}]'
};

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"
	"strings"
	"net/http"
	"io"
)

func main() {

	url := "https://app.launchdarkly.com/api/v2/flags/projectKey/flagKey/release"

	payload := strings.NewReader("[\n  {\n    \"op\": \"replace\",\n    \"path\": \"/phases/0/complete\"\n  }\n]")

	req, _ := http.NewRequest("PATCH", url, payload)

	req.Header.Add("Authorization", "<apiKey>")
	req.Header.Add("Content-Type", "application/json")

	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/flags/projectKey/flagKey/release")

http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true

request = Net::HTTP::Patch.new(url)
request["Authorization"] = '<apiKey>'
request["Content-Type"] = 'application/json'
request.body = "[\n  {\n    \"op\": \"replace\",\n    \"path\": \"/phases/0/complete\"\n  }\n]"

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.patch("https://app.launchdarkly.com/api/v2/flags/projectKey/flagKey/release")
  .header("Authorization", "<apiKey>")
  .header("Content-Type", "application/json")
  .body("[\n  {\n    \"op\": \"replace\",\n    \"path\": \"/phases/0/complete\"\n  }\n]")
  .asString();
```

```php
<?php
require_once('vendor/autoload.php');

$client = new \GuzzleHttp\Client();

$response = $client->request('PATCH', 'https://app.launchdarkly.com/api/v2/flags/projectKey/flagKey/release', [
  'body' => '[
  {
    "op": "replace",
    "path": "/phases/0/complete"
  }
]',
  'headers' => [
    'Authorization' => '<apiKey>',
    'Content-Type' => 'application/json',
  ],
]);

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

```csharp
using RestSharp;

var client = new RestClient("https://app.launchdarkly.com/api/v2/flags/projectKey/flagKey/release");
var request = new RestRequest(Method.PATCH);
request.AddHeader("Authorization", "<apiKey>");
request.AddHeader("Content-Type", "application/json");
request.AddParameter("application/json", "[\n  {\n    \"op\": \"replace\",\n    \"path\": \"/phases/0/complete\"\n  }\n]", ParameterType.RequestBody);
IRestResponse response = client.Execute(request);
```

```swift
import Foundation

let headers = [
  "Authorization": "<apiKey>",
  "Content-Type": "application/json"
]
let parameters = [
  [
    "op": "replace",
    "path": "/phases/0/complete"
  ]
] as [String : Any]

let postData = JSONSerialization.data(withJSONObject: parameters, options: [])

let request = NSMutableURLRequest(url: NSURL(string: "https://app.launchdarkly.com/api/v2/flags/projectKey/flagKey/release")! as URL,
                                        cachePolicy: .useProtocolCachePolicy,
                                    timeoutInterval: 10.0)
request.httpMethod = "PATCH"
request.allHTTPHeaderFields = headers
request.httpBody = postData as Data

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()
```