# Update layer

PATCH https://app.launchdarkly.com/api/v2/projects/{projectKey}/layers/{layerKey}
Content-Type: application/json

Update a layer by adding, changing, or removing traffic reservations for experiments, or by changing layer name or description.
Updating a layer 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 layers.

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

#### updateName

Updates the layer name.

##### Parameters

- `name`: The new layer name.

Here's an example:

```json
{
  "instructions": [{
      "kind": "updateName",
      "name": "New name"
  }]
}
```

#### updateDescription

Updates the layer description.

##### Parameters

- `description`: The new description.

Here's an example:

```json
{
  "instructions": [{
      "kind": "updateDescription",
      "description": "New description"
  }]
}
```

#### updateExperimentReservation

Adds or updates a traffic reservation for an experiment in a layer.

##### Parameters

- `experimentKey`: The key of the experiment whose reservation you are adding to or updating in the layer.
- `reservationPercent`: The amount of traffic in the layer to reserve. Must be an integer. Zero is allowed until iteration start.

Here's an example:

```json
{
  "environmentKey": "production",
  "instructions": [{
      "kind": "updateExperimentReservation",
      "experimentKey": "exp-key",
      "reservationPercent": 10
  }]
}
```

#### removeExperiment

Removes a traffic reservation for an experiment from a layer.

##### Parameters

- `experimentKey`: The key of the experiment whose reservation you want to remove from the layer.

Here's an example:

```json
{
  "environmentKey": "production",
  "instructions": [{
      "kind": "removeExperiment",
      "experimentKey": "exp-key"
  }]
}
```

</details>


Reference: https://launchdarkly.com/docs/api/layers/update-layer

## OpenAPI Specification

```yaml
openapi: 3.1.0
info:
  title: LaunchDarkly REST API
  version: 1.0.0
paths:
  /api/v2/projects/{projectKey}/layers/{layerKey}:
    patch:
      operationId: update-layer
      summary: Update layer
      description: >
        Update a layer by adding, changing, or removing traffic reservations for
        experiments, or by changing layer name or description.

        Updating a layer 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 layers.


        <details>

        <summary>Click to expand instructions for <strong>updating
        layers</strong></summary>


        #### updateName


        Updates the layer name.


        ##### Parameters


        - `name`: The new layer name.


        Here's an example:


        ```json

        {
          "instructions": [{
              "kind": "updateName",
              "name": "New name"
          }]
        }

        ```


        #### updateDescription


        Updates the layer description.


        ##### Parameters


        - `description`: The new description.


        Here's an example:


        ```json

        {
          "instructions": [{
              "kind": "updateDescription",
              "description": "New description"
          }]
        }

        ```


        #### updateExperimentReservation


        Adds or updates a traffic reservation for an experiment in a layer.


        ##### Parameters


        - `experimentKey`: The key of the experiment whose reservation you are
        adding to or updating in the layer.

        - `reservationPercent`: The amount of traffic in the layer to reserve.
        Must be an integer. Zero is allowed until iteration start.


        Here's an example:


        ```json

        {
          "environmentKey": "production",
          "instructions": [{
              "kind": "updateExperimentReservation",
              "experimentKey": "exp-key",
              "reservationPercent": 10
          }]
        }

        ```


        #### removeExperiment


        Removes a traffic reservation for an experiment from a layer.


        ##### Parameters


        - `experimentKey`: The key of the experiment whose reservation you want
        to remove from the layer.


        Here's an example:


        ```json

        {
          "environmentKey": "production",
          "instructions": [{
              "kind": "removeExperiment",
              "experimentKey": "exp-key"
          }]
        }

        ```


        </details>
      tags:
        - subpackage_layers
      parameters:
        - name: projectKey
          in: path
          description: The project key
          required: true
          schema:
            type: string
            format: string
        - name: layerKey
          in: path
          description: The layer key
          required: true
          schema:
            type: string
            format: string
        - name: Authorization
          in: header
          required: true
          schema:
            type: string
      responses:
        '200':
          description: Layer response
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/LayerRep'
        '400':
          description: Invalid request
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/InvalidRequestErrorRep'
        '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/LayerPatchInput'
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
    LayerPatchInput:
      type: object
      properties:
        comment:
          type: string
          description: Optional comment describing the update
        environmentKey:
          type: string
          description: >-
            The environment key used for making environment specific updates.
            For example, updating the reservation of an experiment
        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: LayerPatchInput
    UnixMillis:
      type: integer
      format: int64
      title: UnixMillis
    LayerReservationRep:
      type: object
      properties:
        experimentKey:
          type: string
          description: The key of the experiment
        flagKey:
          type: string
          description: The key of the flag
        reservationPercent:
          type: integer
          description: The percentage of traffic reserved for the experiment
      required:
        - experimentKey
        - flagKey
        - reservationPercent
      title: LayerReservationRep
    LayerConfigurationRep:
      type: object
      properties:
        reservations:
          type: array
          items:
            $ref: '#/components/schemas/LayerReservationRep'
          description: The experiment reservations for the layer
      required:
        - reservations
      title: LayerConfigurationRep
    LayerRep:
      type: object
      properties:
        key:
          type: string
          description: The key of the layer
        name:
          type: string
          description: The name of the layer
        description:
          type: string
          description: The description of the layer
        createdAt:
          $ref: '#/components/schemas/UnixMillis'
          description: The date and time when the layer was created
        randomizationUnit:
          type: string
          description: The unit of randomization for the layer
        environments:
          type: object
          additionalProperties:
            $ref: '#/components/schemas/LayerConfigurationRep'
          description: The layer configurations for each requested environment
      required:
        - key
        - name
        - description
        - createdAt
      title: LayerRep
    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
    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/projects/projectKey/layers/layerKey"

payload = {
    "instructions": [
        {
            "experimentKey": "checkout-button-color",
            "kind": "updateExperimentReservation",
            "reservationPercent": 25
        }
    ],
    "comment": "Example comment describing the update",
    "environmentKey": "production"
}
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/layers/layerKey';
const options = {
  method: 'PATCH',
  headers: {Authorization: '<apiKey>', 'Content-Type': 'application/json'},
  body: '{"instructions":[{"experimentKey":"checkout-button-color","kind":"updateExperimentReservation","reservationPercent":25}],"comment":"Example comment describing the update","environmentKey":"production"}'
};

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/layers/layerKey"

	payload := strings.NewReader("{\n  \"instructions\": [\n    {\n      \"experimentKey\": \"checkout-button-color\",\n      \"kind\": \"updateExperimentReservation\",\n      \"reservationPercent\": 25\n    }\n  ],\n  \"comment\": \"Example comment describing the update\",\n  \"environmentKey\": \"production\"\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/layers/layerKey")

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      \"experimentKey\": \"checkout-button-color\",\n      \"kind\": \"updateExperimentReservation\",\n      \"reservationPercent\": 25\n    }\n  ],\n  \"comment\": \"Example comment describing the update\",\n  \"environmentKey\": \"production\"\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/layers/layerKey")
  .header("Authorization", "<apiKey>")
  .header("Content-Type", "application/json")
  .body("{\n  \"instructions\": [\n    {\n      \"experimentKey\": \"checkout-button-color\",\n      \"kind\": \"updateExperimentReservation\",\n      \"reservationPercent\": 25\n    }\n  ],\n  \"comment\": \"Example comment describing the update\",\n  \"environmentKey\": \"production\"\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/layers/layerKey', [
  'body' => '{
  "instructions": [
    {
      "experimentKey": "checkout-button-color",
      "kind": "updateExperimentReservation",
      "reservationPercent": 25
    }
  ],
  "comment": "Example comment describing the update",
  "environmentKey": "production"
}',
  '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/layers/layerKey");
var request = new RestRequest(Method.PATCH);
request.AddHeader("Authorization", "<apiKey>");
request.AddHeader("Content-Type", "application/json");
request.AddParameter("application/json", "{\n  \"instructions\": [\n    {\n      \"experimentKey\": \"checkout-button-color\",\n      \"kind\": \"updateExperimentReservation\",\n      \"reservationPercent\": 25\n    }\n  ],\n  \"comment\": \"Example comment describing the update\",\n  \"environmentKey\": \"production\"\n}", ParameterType.RequestBody);
IRestResponse response = client.Execute(request);
```

```swift
import Foundation

let headers = [
  "Authorization": "<apiKey>",
  "Content-Type": "application/json"
]
let parameters = [
  "instructions": [
    [
      "experimentKey": "checkout-button-color",
      "kind": "updateExperimentReservation",
      "reservationPercent": 25
    ]
  ],
  "comment": "Example comment describing the update",
  "environmentKey": "production"
] as [String : Any]

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

let request = NSMutableURLRequest(url: NSURL(string: "https://app.launchdarkly.com/api/v2/projects/projectKey/layers/layerKey")! 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()
```