# Update experimentation settings

PUT https://app.launchdarkly.com/api/v2/projects/{projectKey}/experimentation-settings
Content-Type: application/json

Update experimentation settings for the given project

Reference: https://launchdarkly.com/docs/api/experiments/put-experimentation-settings

## OpenAPI Specification

```yaml
openapi: 3.1.0
info:
  title: LaunchDarkly REST API
  version: 1.0.0
paths:
  /api/v2/projects/{projectKey}/experimentation-settings:
    put:
      operationId: put-experimentation-settings
      summary: Update experimentation settings
      description: Update experimentation settings for the given project
      tags:
        - subpackage_experiments
      parameters:
        - name: projectKey
          in: path
          description: The project key
          required: true
          schema:
            type: string
            format: string
        - name: Authorization
          in: header
          required: true
          schema:
            type: string
      responses:
        '200':
          description: Experimentation settings response
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/RandomizationSettingsRep'
        '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'
        '429':
          description: Rate limited
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/RateLimitedErrorRep'
      requestBody:
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/RandomizationSettingsPut'
servers:
  - url: https://app.launchdarkly.com
  - url: https://app.launchdarkly.us
components:
  schemas:
    RandomizationUnitInput:
      type: object
      properties:
        randomizationUnit:
          type: string
          description: >-
            The unit of randomization. Must match the key of an existing context
            kind in this project.
        default:
          type: boolean
          description: >-
            If true, any experiment iterations created within this project will
            default to using this randomization unit. A project can only have
            one default randomization unit.
        standardRandomizationUnit:
          type: string
          description: >-
            (deprecated) This field is deprecated and will be removed. Use
            randomizationUnit instead.
      required:
        - randomizationUnit
      title: RandomizationUnitInput
    RandomizationSettingsPut:
      type: object
      properties:
        randomizationUnits:
          type: array
          items:
            $ref: '#/components/schemas/RandomizationUnitInput'
          description: An array of randomization units allowed for this project.
      required:
        - randomizationUnits
      title: RandomizationSettingsPut
    RandomizationUnitRep:
      type: object
      properties:
        randomizationUnit:
          type: string
          description: The unit of randomization. Defaults to user.
        default:
          type: boolean
          description: Whether this randomization unit is the default for experiments
        _hidden:
          type: boolean
        _displayName:
          type: string
          description: >-
            The display name for the randomization unit, displayed in the
            LaunchDarkly user interface.
      title: RandomizationUnitRep
    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
    RandomizationSettingsRep:
      type: object
      properties:
        _projectId:
          type: string
          description: The project ID
        _projectKey:
          type: string
          description: The project key
        randomizationUnits:
          type: array
          items:
            $ref: '#/components/schemas/RandomizationUnitRep'
          description: An array of the randomization units in this project
        _creationDate:
          $ref: '#/components/schemas/UnixMillis'
          description: Timestamp of when the experiment was created
        _links:
          type: object
          additionalProperties:
            $ref: '#/components/schemas/Link'
          description: The location and content type of related resources
      title: RandomizationSettingsRep
    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
    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/experimentation-settings"

payload = { "randomizationUnits": [{ "randomizationUnit": "user" }] }
headers = {
    "Authorization": "<apiKey>",
    "Content-Type": "application/json"
}

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

print(response.json())
```

```javascript
const url = 'https://app.launchdarkly.com/api/v2/projects/projectKey/experimentation-settings';
const options = {
  method: 'PUT',
  headers: {Authorization: '<apiKey>', 'Content-Type': 'application/json'},
  body: '{"randomizationUnits":[{"randomizationUnit":"user"}]}'
};

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/experimentation-settings"

	payload := strings.NewReader("{\n  \"randomizationUnits\": [\n    {\n      \"randomizationUnit\": \"user\"\n    }\n  ]\n}")

	req, _ := http.NewRequest("PUT", 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/experimentation-settings")

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

request = Net::HTTP::Put.new(url)
request["Authorization"] = '<apiKey>'
request["Content-Type"] = 'application/json'
request.body = "{\n  \"randomizationUnits\": [\n    {\n      \"randomizationUnit\": \"user\"\n    }\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.put("https://app.launchdarkly.com/api/v2/projects/projectKey/experimentation-settings")
  .header("Authorization", "<apiKey>")
  .header("Content-Type", "application/json")
  .body("{\n  \"randomizationUnits\": [\n    {\n      \"randomizationUnit\": \"user\"\n    }\n  ]\n}")
  .asString();
```

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

$client = new \GuzzleHttp\Client();

$response = $client->request('PUT', 'https://app.launchdarkly.com/api/v2/projects/projectKey/experimentation-settings', [
  'body' => '{
  "randomizationUnits": [
    {
      "randomizationUnit": "user"
    }
  ]
}',
  '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/experimentation-settings");
var request = new RestRequest(Method.PUT);
request.AddHeader("Authorization", "<apiKey>");
request.AddHeader("Content-Type", "application/json");
request.AddParameter("application/json", "{\n  \"randomizationUnits\": [\n    {\n      \"randomizationUnit\": \"user\"\n    }\n  ]\n}", ParameterType.RequestBody);
IRestResponse response = client.Execute(request);
```

```swift
import Foundation

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

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

let request = NSMutableURLRequest(url: NSURL(string: "https://app.launchdarkly.com/api/v2/projects/projectKey/experimentation-settings")! as URL,
                                        cachePolicy: .useProtocolCachePolicy,
                                    timeoutInterval: 10.0)
request.httpMethod = "PUT"
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()
```