# Update scheduled changes workflow

PATCH https://app.launchdarkly.com/api/v2/projects/{projectKey}/flags/{featureFlagKey}/environments/{environmentKey}/scheduled-changes/{id}
Content-Type: application/json


Update a scheduled change, overriding existing instructions with the new ones. Updating a scheduled change uses the semantic patch format.

To make a semantic patch request, you must append `domain-model=launchdarkly.semanticpatch` to your `Content-Type` header. To learn more, read [Updates using semantic patch](https://launchdarkly.com/docs/api#updates-using-semantic-patch).

### Instructions

Semantic patch requests support the following `kind` instructions for updating scheduled changes.

<details>
<summary>Click to expand instructions for <strong>updating scheduled changes</strong></summary>

#### deleteScheduledChange

Removes the scheduled change.

Here's an example:

```json
{
  "instructions": [{ "kind": "deleteScheduledChange" }]
}
```

#### replaceScheduledChangesInstructions

Removes the existing scheduled changes and replaces them with the new instructions.

##### Parameters

- `value`: An array of the new actions to perform when the execution date for these scheduled changes arrives. Supported scheduled actions are `turnFlagOn` and `turnFlagOff`.

Here's an example that replaces the scheduled changes with new instructions to turn flag targeting off:

```json
{
  "instructions": [
    {
      "kind": "replaceScheduledChangesInstructions",
      "value": [ {"kind": "turnFlagOff"} ]
    }
  ]
}
```

#### updateScheduledChangesExecutionDate

Updates the execution date for the scheduled changes.

##### Parameters

- `value`: the new execution date, in Unix milliseconds.

Here's an example:

```json
{
  "instructions": [
    {
      "kind": "updateScheduledChangesExecutionDate",
      "value": 1754092860000
    }
  ]
}
```

</details>


Reference: https://launchdarkly.com/docs/api/scheduled-changes/patch-flag-config-scheduled-change

## OpenAPI Specification

```yaml
openapi: 3.1.0
info:
  title: LaunchDarkly REST API
  version: 1.0.0
paths:
  /api/v2/projects/{projectKey}/flags/{featureFlagKey}/environments/{environmentKey}/scheduled-changes/{id}:
    patch:
      operationId: patch-flag-config-scheduled-change
      summary: Update scheduled changes workflow
      description: >

        Update a scheduled change, overriding existing instructions with the new
        ones. Updating a scheduled change uses the semantic patch format.


        To make a semantic patch request, you must append
        `domain-model=launchdarkly.semanticpatch` to your `Content-Type` header.
        To learn more, read [Updates using semantic
        patch](https://launchdarkly.com/docs/api#updates-using-semantic-patch).


        ### Instructions


        Semantic patch requests support the following `kind` instructions for
        updating scheduled changes.


        <details>

        <summary>Click to expand instructions for <strong>updating scheduled
        changes</strong></summary>


        #### deleteScheduledChange


        Removes the scheduled change.


        Here's an example:


        ```json

        {
          "instructions": [{ "kind": "deleteScheduledChange" }]
        }

        ```


        #### replaceScheduledChangesInstructions


        Removes the existing scheduled changes and replaces them with the new
        instructions.


        ##### Parameters


        - `value`: An array of the new actions to perform when the execution
        date for these scheduled changes arrives. Supported scheduled actions
        are `turnFlagOn` and `turnFlagOff`.


        Here's an example that replaces the scheduled changes with new
        instructions to turn flag targeting off:


        ```json

        {
          "instructions": [
            {
              "kind": "replaceScheduledChangesInstructions",
              "value": [ {"kind": "turnFlagOff"} ]
            }
          ]
        }

        ```


        #### updateScheduledChangesExecutionDate


        Updates the execution date for the scheduled changes.


        ##### Parameters


        - `value`: the new execution date, in Unix milliseconds.


        Here's an example:


        ```json

        {
          "instructions": [
            {
              "kind": "updateScheduledChangesExecutionDate",
              "value": 1754092860000
            }
          ]
        }

        ```


        </details>
      tags:
        - subpackage_scheduledChanges
      parameters:
        - name: projectKey
          in: path
          description: The project key
          required: true
          schema:
            type: string
            format: string
        - name: featureFlagKey
          in: path
          description: The feature flag key
          required: true
          schema:
            type: string
            format: string
        - name: environmentKey
          in: path
          description: The environment key
          required: true
          schema:
            type: string
            format: string
        - name: id
          in: path
          description: The scheduled change ID
          required: true
          schema:
            type: string
            format: string
        - name: ignoreConflicts
          in: query
          description: >-
            Whether to succeed (`true`) or fail (`false`) when these new
            instructions conflict with existing scheduled changes
          required: false
          schema:
            type: boolean
        - name: Authorization
          in: header
          required: true
          schema:
            type: string
      responses:
        '200':
          description: Scheduled changes response
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/FeatureFlagScheduledChange'
        '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'
        '405':
          description: Method not allowed
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/MethodNotAllowedErrorRep'
        '409':
          description: Status conflict
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/StatusConflictErrorRep'
        '429':
          description: Rate limited
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/RateLimitedErrorRep'
      requestBody:
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/FlagScheduledChangesInput'
servers:
  - url: https://app.launchdarkly.com
  - url: https://app.launchdarkly.us
components:
  schemas:
    Instruction:
      type: object
      additionalProperties:
        description: Any type
      title: Instruction
    Instructions:
      type: array
      items:
        $ref: '#/components/schemas/Instruction'
      title: Instructions
    FlagScheduledChangesInput:
      type: object
      properties:
        comment:
          type: string
          description: Optional comment describing the update to the scheduled changes
        instructions:
          $ref: '#/components/schemas/Instructions'
          description: >-
            The instructions to perform when updating. This should be an array
            with objects that look like <code>{"kind": "update_action"}</code>.
            Some instructions also require a <code>value</code> field in the
            array element.
      required:
        - instructions
      title: FlagScheduledChangesInput
    FeatureWorkflowId:
      type: string
      title: FeatureWorkflowId
    UnixMillis:
      type: integer
      format: int64
      title: UnixMillis
    Link:
      type: object
      properties:
        href:
          type: string
          description: The URL of the link
        type:
          type: string
          description: The type of the link
      title: Link
    FeatureFlagScheduledChange:
      type: object
      properties:
        _id:
          $ref: '#/components/schemas/FeatureWorkflowId'
          description: The ID of this scheduled change
        _creationDate:
          $ref: '#/components/schemas/UnixMillis'
          description: Timestamp of when the scheduled change was created
        _maintainerId:
          type: string
          description: The ID of the scheduled change maintainer
        _version:
          type: integer
          description: Version of the scheduled change
        executionDate:
          $ref: '#/components/schemas/UnixMillis'
          description: When the scheduled changes should be executed
        instructions:
          $ref: '#/components/schemas/Instructions'
          description: >-
            The actions to perform on the execution date for these scheduled
            changes
        conflicts:
          description: Details on any conflicting scheduled changes
        _links:
          type: object
          additionalProperties:
            $ref: '#/components/schemas/Link'
          description: The location and content type of related resources
      required:
        - _id
        - _creationDate
        - _maintainerId
        - _version
        - executionDate
        - instructions
      title: FeatureFlagScheduledChange
    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
    MethodNotAllowedErrorRep:
      type: object
      properties:
        code:
          type: string
          description: Specific error code encountered
        message:
          type: string
          description: Description of the error
      required:
        - code
        - message
      title: MethodNotAllowedErrorRep
    StatusConflictErrorRep:
      type: object
      properties:
        code:
          type: string
          description: Specific error code encountered
        message:
          type: string
          description: Description of the error
      required:
        - code
        - message
      title: StatusConflictErrorRep
    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/projects/projectKey/flags/featureFlagKey/environments/environmentKey/scheduled-changes/id"

payload = {
    "instructions": [
        {
            "kind": "replaceScheduledChangesInstructions",
            "value": [{ "kind": "turnFlagOff" }]
        }
    ],
    "comment": "Optional comment describing the update to the scheduled changes"
}
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/projects/projectKey/flags/featureFlagKey/environments/environmentKey/scheduled-changes/id';
const options = {
  method: 'PATCH',
  headers: {Authorization: '<apiKey>', 'Content-Type': 'application/json'},
  body: '{"instructions":[{"kind":"replaceScheduledChangesInstructions","value":[{"kind":"turnFlagOff"}]}],"comment":"Optional comment describing the update to the scheduled changes"}'
};

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/projects/projectKey/flags/featureFlagKey/environments/environmentKey/scheduled-changes/id"

	payload := strings.NewReader("{\n  \"instructions\": [\n    {\n      \"kind\": \"replaceScheduledChangesInstructions\",\n      \"value\": [\n        {\n          \"kind\": \"turnFlagOff\"\n        }\n      ]\n    }\n  ],\n  \"comment\": \"Optional comment describing the update to the scheduled changes\"\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/projects/projectKey/flags/featureFlagKey/environments/environmentKey/scheduled-changes/id")

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  \"instructions\": [\n    {\n      \"kind\": \"replaceScheduledChangesInstructions\",\n      \"value\": [\n        {\n          \"kind\": \"turnFlagOff\"\n        }\n      ]\n    }\n  ],\n  \"comment\": \"Optional comment describing the update to the scheduled changes\"\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/projects/projectKey/flags/featureFlagKey/environments/environmentKey/scheduled-changes/id")
  .header("Authorization", "<apiKey>")
  .header("Content-Type", "application/json")
  .body("{\n  \"instructions\": [\n    {\n      \"kind\": \"replaceScheduledChangesInstructions\",\n      \"value\": [\n        {\n          \"kind\": \"turnFlagOff\"\n        }\n      ]\n    }\n  ],\n  \"comment\": \"Optional comment describing the update to the scheduled changes\"\n}")
  .asString();
```

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

$client = new \GuzzleHttp\Client();

$response = $client->request('PATCH', 'https://app.launchdarkly.com/api/v2/projects/projectKey/flags/featureFlagKey/environments/environmentKey/scheduled-changes/id', [
  'body' => '{
  "instructions": [
    {
      "kind": "replaceScheduledChangesInstructions",
      "value": [
        {
          "kind": "turnFlagOff"
        }
      ]
    }
  ],
  "comment": "Optional comment describing the update to the scheduled changes"
}',
  'headers' => [
    'Authorization' => '<apiKey>',
    'Content-Type' => 'application/json',
  ],
]);

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

```csharp
using RestSharp;

var client = new RestClient("https://app.launchdarkly.com/api/v2/projects/projectKey/flags/featureFlagKey/environments/environmentKey/scheduled-changes/id");
var request = new RestRequest(Method.PATCH);
request.AddHeader("Authorization", "<apiKey>");
request.AddHeader("Content-Type", "application/json");
request.AddParameter("application/json", "{\n  \"instructions\": [\n    {\n      \"kind\": \"replaceScheduledChangesInstructions\",\n      \"value\": [\n        {\n          \"kind\": \"turnFlagOff\"\n        }\n      ]\n    }\n  ],\n  \"comment\": \"Optional comment describing the update to the scheduled changes\"\n}", ParameterType.RequestBody);
IRestResponse response = client.Execute(request);
```

```swift
import Foundation

let headers = [
  "Authorization": "<apiKey>",
  "Content-Type": "application/json"
]
let parameters = [
  "instructions": [
    [
      "kind": "replaceScheduledChangesInstructions",
      "value": [["kind": "turnFlagOff"]]
    ]
  ],
  "comment": "Optional comment describing the update to the scheduled changes"
] as [String : Any]

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

let request = NSMutableURLRequest(url: NSURL(string: "https://app.launchdarkly.com/api/v2/projects/projectKey/flags/featureFlagKey/environments/environmentKey/scheduled-changes/id")! 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()
```