# Update flag trigger

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

Update a flag trigger. Updating a flag trigger 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 flag triggers.

<details>
<summary>Click to expand instructions for <strong>updating flag triggers</strong></summary>

#### replaceTriggerActionInstructions

Removes the existing trigger action and replaces it with the new instructions.

##### Parameters

- `value`: An array of the new `kind`s of actions to perform when triggering. Supported flag actions are `turnFlagOn` and `turnFlagOff`.

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

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

#### cycleTriggerUrl

Generates a new URL for this trigger. You must update any clients using the trigger to use this new URL.

Here's an example:

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

#### disableTrigger

Disables the trigger. This saves the trigger configuration, but the trigger stops running. To re-enable, use `enableTrigger`.

Here's an example:

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

#### enableTrigger

Enables the trigger. If you previously disabled the trigger, it begins running again.

Here's an example:

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

</details>


Reference: https://launchdarkly.com/docs/api/flag-triggers/patch-trigger-workflow

## OpenAPI Specification

```yaml
openapi: 3.1.0
info:
  title: LaunchDarkly REST API
  version: 1.0.0
paths:
  /api/v2/flags/{projectKey}/{featureFlagKey}/triggers/{environmentKey}/{id}:
    patch:
      operationId: patch-trigger-workflow
      summary: Update flag trigger
      description: >
        Update a flag trigger. Updating a flag trigger 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 flag triggers.


        <details>

        <summary>Click to expand instructions for <strong>updating flag
        triggers</strong></summary>


        #### replaceTriggerActionInstructions


        Removes the existing trigger action and replaces it with the new
        instructions.


        ##### Parameters


        - `value`: An array of the new `kind`s of actions to perform when
        triggering. Supported flag actions are `turnFlagOn` and `turnFlagOff`.


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


        ```json

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

        ```


        #### cycleTriggerUrl


        Generates a new URL for this trigger. You must update any clients using
        the trigger to use this new URL.


        Here's an example:


        ```json

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

        ```


        #### disableTrigger


        Disables the trigger. This saves the trigger configuration, but the
        trigger stops running. To re-enable, use `enableTrigger`.


        Here's an example:


        ```json

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

        ```


        #### enableTrigger


        Enables the trigger. If you previously disabled the trigger, it begins
        running again.


        Here's an example:


        ```json

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

        ```


        </details>
      tags:
        - subpackage_flagTriggers
      parameters:
        - name: projectKey
          in: path
          description: The project key
          required: true
          schema:
            type: string
            format: string
        - name: environmentKey
          in: path
          description: The environment 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: id
          in: path
          description: The flag trigger ID
          required: true
          schema:
            type: string
            format: string
        - name: Authorization
          in: header
          required: true
          schema:
            type: string
      responses:
        '200':
          description: Flag trigger response
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/TriggerWorkflowRep'
        '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'
        '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/FlagTriggerInput'
servers:
  - url: https://app.launchdarkly.com
  - url: https://app.launchdarkly.us
components:
  schemas:
    Instruction:
      type: object
      additionalProperties:
        description: Any type
      title: Instruction
    FlagTriggerInput:
      type: object
      properties:
        comment:
          type: string
          description: Optional comment describing the update
        instructions:
          type: array
          items:
            $ref: '#/components/schemas/Instruction'
          description: >-
            The instructions to perform when updating. This should be an array
            with objects that look like <code>{"kind": "trigger_action"}</code>.
      title: FlagTriggerInput
    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
    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
    Instructions:
      type: array
      items:
        $ref: '#/components/schemas/Instruction'
      title: Instructions
    RecentTriggerBody:
      type: object
      properties:
        timestamp:
          $ref: '#/components/schemas/UnixMillis'
          description: Timestamp of the incoming trigger webhook
        jsonBody:
          type: object
          additionalProperties:
            description: Any type
          description: >-
            The marshalled JSON request body for the incoming trigger webhook.
            If this is empty or contains invalid JSON, the timestamp is recorded
            but this field will be empty.
      title: RecentTriggerBody
    TriggerWorkflowRep:
      type: object
      properties:
        _id:
          $ref: '#/components/schemas/FeatureWorkflowId'
          description: The ID of this flag trigger
        _version:
          type: integer
          description: The flag trigger version
        _creationDate:
          $ref: '#/components/schemas/UnixMillis'
          description: Timestamp of when the flag trigger was created
        _maintainerId:
          type: string
          description: The ID of the flag trigger maintainer
        _maintainer:
          $ref: '#/components/schemas/MemberSummary'
          description: Details on the member who maintains this flag trigger
        enabled:
          type: boolean
          description: Whether the flag trigger is currently enabled
        _integrationKey:
          type: string
          description: The unique identifier of the integration for your trigger
        instructions:
          $ref: '#/components/schemas/Instructions'
          description: Details on the action to perform when triggering
        _lastTriggeredAt:
          $ref: '#/components/schemas/UnixMillis'
          description: Timestamp of when the trigger was most recently executed
        _recentTriggerBodies:
          type: array
          items:
            $ref: '#/components/schemas/RecentTriggerBody'
          description: Details on recent flag trigger requests.
        _triggerCount:
          type: integer
          description: Number of times the trigger has been executed
        triggerURL:
          type: string
          description: The unguessable URL for this flag trigger
        _links:
          type: object
          additionalProperties:
            $ref: '#/components/schemas/Link'
          description: The location and content type of related resources
      title: TriggerWorkflowRep
    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
    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/flags/projectKey/featureFlagKey/triggers/environmentKey/id"

payload = {}
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/featureFlagKey/triggers/environmentKey/id';
const options = {
  method: 'PATCH',
  headers: {Authorization: '<apiKey>', 'Content-Type': 'application/json'},
  body: '{}'
};

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/featureFlagKey/triggers/environmentKey/id"

	payload := strings.NewReader("{}")

	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/featureFlagKey/triggers/environmentKey/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 = "{}"

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/featureFlagKey/triggers/environmentKey/id")
  .header("Authorization", "<apiKey>")
  .header("Content-Type", "application/json")
  .body("{}")
  .asString();
```

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

$client = new \GuzzleHttp\Client();

$response = $client->request('PATCH', 'https://app.launchdarkly.com/api/v2/flags/projectKey/featureFlagKey/triggers/environmentKey/id', [
  'body' => '{}',
  '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/featureFlagKey/triggers/environmentKey/id");
var request = new RestRequest(Method.PATCH);
request.AddHeader("Authorization", "<apiKey>");
request.AddHeader("Content-Type", "application/json");
request.AddParameter("application/json", "{}", ParameterType.RequestBody);
IRestResponse response = client.Execute(request);
```

```swift
import Foundation

let headers = [
  "Authorization": "<apiKey>",
  "Content-Type": "application/json"
]
let parameters = [] as [String : Any]

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

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