# Create iteration

POST https://app.launchdarkly.com/api/v2/projects/{projectKey}/environments/{environmentKey}/experiments/{experimentKey}/iterations
Content-Type: application/json

Create an experiment iteration.

Experiment iterations let you record experiments in individual blocks of time. Initially, iterations are created with a status of `not_started` and appear in the `draftIteration` field of an experiment. To start or stop an iteration, [update the experiment](https://launchdarkly.com/docs/api/experiments/patch-experiment) with the `startIteration` or `stopIteration` instruction.

To learn more, read [Start experiment iterations](https://launchdarkly.com/docs/home/experimentation/create#start-an-experiment-iteration).


Reference: https://launchdarkly.com/docs/api/experiments/create-iteration

## OpenAPI Specification

```yaml
openapi: 3.1.0
info:
  title: LaunchDarkly REST API
  version: 1.0.0
paths:
  /api/v2/projects/{projectKey}/environments/{environmentKey}/experiments/{experimentKey}/iterations:
    post:
      operationId: create-iteration
      summary: Create iteration
      description: >
        Create an experiment iteration.


        Experiment iterations let you record experiments in individual blocks of
        time. Initially, iterations are created with a status of `not_started`
        and appear in the `draftIteration` field of an experiment. To start or
        stop an iteration, [update the
        experiment](https://launchdarkly.com/docs/api/experiments/patch-experiment)
        with the `startIteration` or `stopIteration` instruction.


        To learn more, read [Start experiment
        iterations](https://launchdarkly.com/docs/home/experimentation/create#start-an-experiment-iteration).
      tags:
        - subpackage_experiments
      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: experimentKey
          in: path
          description: The experiment key
          required: true
          schema:
            type: string
            format: string
        - name: Authorization
          in: header
          required: true
          schema:
            type: string
      responses:
        '200':
          description: Iteration response
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/IterationRep'
        '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/IterationInput'
servers:
  - url: https://app.launchdarkly.com
  - url: https://app.launchdarkly.us
components:
  schemas:
    MetricInput:
      type: object
      properties:
        key:
          type: string
          description: The metric key
        isGroup:
          type: boolean
          description: >-
            Whether this is a metric group (true) or a metric (false). Defaults
            to false
        primary:
          type: boolean
          description: >-
            Deprecated, use <code>primarySingleMetricKey</code> and
            <code>primaryFunnelKey</code>. Whether this is a primary metric
            (true) or a secondary metric (false)
      required:
        - key
      title: MetricInput
    MetricsInput:
      type: array
      items:
        $ref: '#/components/schemas/MetricInput'
      title: MetricsInput
    TreatmentParameterInput:
      type: object
      properties:
        flagKey:
          type: string
          description: The flag key
        variationId:
          type: string
          description: The ID of the flag variation
      required:
        - flagKey
        - variationId
      title: TreatmentParameterInput
    TreatmentInput:
      type: object
      properties:
        name:
          type: string
          description: The treatment name
        baseline:
          type: boolean
          description: >-
            Whether this treatment is the baseline to compare other treatments
            against
        allocationPercent:
          type: string
          description: >-
            The percentage of traffic allocated to this treatment during the
            iteration
        parameters:
          type: array
          items:
            $ref: '#/components/schemas/TreatmentParameterInput'
          description: Details on the flag and variation to use for this treatment
      required:
        - name
        - baseline
        - allocationPercent
        - parameters
      title: TreatmentInput
    TreatmentsInput:
      type: array
      items:
        $ref: '#/components/schemas/TreatmentInput'
      title: TreatmentsInput
    FlagInput:
      type: object
      properties:
        ruleId:
          type: string
          description: >-
            The ID of the variation or rollout of the flag to use. Use
            "fallthrough" for the default targeting behavior when the flag is
            on.
        flagConfigVersion:
          type: integer
          description: The flag version
        notInExperimentVariationId:
          type: string
          description: >-
            The ID of the variation to route traffic not part of the experiment
            analysis to. Defaults to variation ID of baseline treatment, if set.
      required:
        - ruleId
        - flagConfigVersion
      title: FlagInput
    FlagsInput:
      type: object
      additionalProperties:
        $ref: '#/components/schemas/FlagInput'
      title: FlagsInput
    IterationInput:
      type: object
      properties:
        hypothesis:
          type: string
          description: The expected outcome of this experiment
        canReshuffleTraffic:
          type: boolean
          description: >-
            Whether to allow the experiment to reassign traffic to different
            variations when you increase or decrease the traffic in your
            experiment audience (true) or keep all traffic assigned to its
            initial variation (false). Defaults to true.
        metrics:
          $ref: '#/components/schemas/MetricsInput'
          description: Details on the metrics for this experiment
        primarySingleMetricKey:
          type: string
          description: >-
            The key of the primary metric for this experiment. Either
            <code>primarySingleMetricKey</code> or <code>primaryFunnelKey</code>
            must be present.
        primaryFunnelKey:
          type: string
          description: >-
            The key of the primary funnel group for this experiment. Either
            <code>primarySingleMetricKey</code> or <code>primaryFunnelKey</code>
            must be present.
        treatments:
          $ref: '#/components/schemas/TreatmentsInput'
          description: >-
            Details on the variations you are testing in the experiment. You
            establish these variations in feature flags, and then reuse them in
            experiments.
        flags:
          $ref: '#/components/schemas/FlagsInput'
          description: Details on the feature flag and targeting rules for this iteration
        randomizationUnit:
          type: string
          description: The unit of randomization for this iteration. Defaults to user.
        reallocationFrequencyMillis:
          type: integer
          description: The cadence (in milliseconds) to update the allocation.
        covariateId:
          type: string
          description: The ID of the covariate CSV
        attributes:
          type: array
          items:
            type: string
          description: The attributes that this iteration's results can be sliced by
      required:
        - hypothesis
        - metrics
        - treatments
        - flags
      title: IterationInput
    IterationRepStatus:
      type: string
      enum:
        - not_started
        - running
        - stopped
      description: >-
        The status of the iteration: <code>not_started</code>,
        <code>running</code>, <code>stopped</code>
      title: IterationRepStatus
    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
    FlagRep:
      type: object
      properties:
        targetingRule:
          type: string
          description: The targeting rule
        targetingRuleDescription:
          type: string
          description: The rule description
        targetingRuleClauses:
          type: array
          items:
            description: Any type
          description: >-
            An array of clauses used for individual targeting based on
            attributes
        flagConfigVersion:
          type: integer
          description: The flag version
        notInExperimentVariationId:
          type: string
          description: >-
            The ID of the variation to route traffic not part of the experiment
            analysis to
        _links:
          type: object
          additionalProperties:
            $ref: '#/components/schemas/Link'
          description: The location and content type of related resources
      required:
        - _links
      title: FlagRep
    DependentMetricOrMetricGroupRepKind:
      type: string
      enum:
        - pageview
        - click
        - custom
        - funnel
        - standard
      description: >-
        If this is a metric, then it represents the kind of event the metric
        tracks. If this is a metric group, then it represents the group type
      title: DependentMetricOrMetricGroupRepKind
    MetricInGroupRepKind:
      type: string
      enum:
        - pageview
        - click
        - custom
      description: The kind of event the metric tracks
      title: MetricInGroupRepKind
    MetricInGroupRepUnitAggregationType:
      type: string
      enum:
        - sum
        - average
      description: The type of unit aggregation to use for the metric
      title: MetricInGroupRepUnitAggregationType
    MetricInGroupRep:
      type: object
      properties:
        key:
          type: string
          description: The metric key
        _versionId:
          type: string
          description: The version ID of the metric
        name:
          type: string
          description: The metric name
        kind:
          $ref: '#/components/schemas/MetricInGroupRepKind'
          description: The kind of event the metric tracks
        isNumeric:
          type: boolean
          description: >-
            For custom metrics, whether to track numeric changes in value
            against a baseline (<code>true</code>) or to track a conversion when
            an end user takes an action (<code>false</code>).
        unitAggregationType:
          $ref: '#/components/schemas/MetricInGroupRepUnitAggregationType'
          description: The type of unit aggregation to use for the metric
        eventKey:
          type: string
          description: >-
            The event key sent with the metric. Only relevant for custom
            metrics.
        _links:
          type: object
          additionalProperties:
            $ref: '#/components/schemas/Link'
          description: The location and content type of related resources
        nameInGroup:
          type: string
          description: >-
            Name of the metric when used within the associated metric group. Can
            be different from the original name of the metric. Required if and
            only if the metric group is a <code>funnel</code>.
        randomizationUnits:
          type: array
          items:
            type: string
          description: The randomization units for the metric
      required:
        - key
        - name
        - kind
        - _links
      title: MetricInGroupRep
    DependentMetricOrMetricGroupRep:
      type: object
      properties:
        key:
          type: string
          description: A unique key to reference the metric or metric group
        _versionId:
          type: string
          description: The version ID of the metric or metric group
        name:
          type: string
          description: A human-friendly name for the metric or metric group
        kind:
          $ref: '#/components/schemas/DependentMetricOrMetricGroupRepKind'
          description: >-
            If this is a metric, then it represents the kind of event the metric
            tracks. If this is a metric group, then it represents the group type
        isNumeric:
          type: boolean
          description: >-
            For custom metrics, whether to track numeric changes in value
            against a baseline (<code>true</code>) or to track a conversion when
            an end user takes an action (<code>false</code>).
        eventKey:
          type: string
          description: >-
            The event key sent with the metric. Only relevant for custom
            metrics.
        _links:
          type: object
          additionalProperties:
            $ref: '#/components/schemas/Link'
          description: The location and content type of related resources
        isGroup:
          type: boolean
          description: Whether this is a metric group or a metric
        metrics:
          type: array
          items:
            $ref: '#/components/schemas/MetricInGroupRep'
          description: An ordered list of the metrics in this metric group
      required:
        - key
        - _versionId
        - name
        - kind
        - _links
        - isGroup
      title: DependentMetricOrMetricGroupRep
    MetricV2RepKind:
      type: string
      enum:
        - pageview
        - click
        - custom
      description: The kind of event the metric tracks
      title: MetricV2RepKind
    MetricV2RepUnitAggregationType:
      type: string
      enum:
        - sum
        - average
      description: The type of unit aggregation to use for the metric
      title: MetricV2RepUnitAggregationType
    MetricV2Rep:
      type: object
      properties:
        key:
          type: string
          description: The metric key
        _versionId:
          type: string
          description: The version ID of the metric
        name:
          type: string
          description: The metric name
        kind:
          $ref: '#/components/schemas/MetricV2RepKind'
          description: The kind of event the metric tracks
        isNumeric:
          type: boolean
          description: >-
            For custom metrics, whether to track numeric changes in value
            against a baseline (<code>true</code>) or to track a conversion when
            an end user takes an action (<code>false</code>).
        unitAggregationType:
          $ref: '#/components/schemas/MetricV2RepUnitAggregationType'
          description: The type of unit aggregation to use for the metric
        eventKey:
          type: string
          description: >-
            The event key sent with the metric. Only relevant for custom
            metrics.
        _links:
          type: object
          additionalProperties:
            $ref: '#/components/schemas/Link'
          description: The location and content type of related resources
      required:
        - key
        - name
        - kind
        - _links
      title: MetricV2Rep
    DependentMetricGroupRepWithMetricsKind:
      type: string
      enum:
        - funnel
        - standard
      description: The type of the metric group
      title: DependentMetricGroupRepWithMetricsKind
    DependentMetricGroupRepWithMetrics:
      type: object
      properties:
        key:
          type: string
          description: A unique key to reference the metric group
        name:
          type: string
          description: A human-friendly name for the metric group
        kind:
          $ref: '#/components/schemas/DependentMetricGroupRepWithMetricsKind'
          description: The type of the metric group
        _links:
          type: object
          additionalProperties:
            $ref: '#/components/schemas/Link'
          description: The location and content type of related resources
        metrics:
          type: array
          items:
            $ref: '#/components/schemas/MetricInGroupRep'
          description: The metrics in the metric group
      required:
        - key
        - name
        - kind
        - _links
      title: DependentMetricGroupRepWithMetrics
    ParameterRep:
      type: object
      properties:
        variationId:
          type: string
        flagKey:
          type: string
      title: ParameterRep
    TreatmentRep:
      type: object
      properties:
        _id:
          type: string
          description: The treatment ID. This is the variation ID from the flag.
        name:
          type: string
          description: The treatment name. This is the variation name from the flag.
        allocationPercent:
          type: string
          description: >-
            The percentage of traffic allocated to this treatment during the
            iteration
        baseline:
          type: boolean
          description: >-
            Whether this treatment is the baseline to compare other treatments
            against
        parameters:
          type: array
          items:
            $ref: '#/components/schemas/ParameterRep'
          description: Details on the flag and variation used for this treatment
      required:
        - name
        - allocationPercent
      title: TreatmentRep
    LayerSnapshotRep:
      type: object
      properties:
        key:
          type: string
          description: Key of the layer the experiment was part of
        name:
          type: string
          description: Layer name at the time this experiment iteration was stopped
        reservationPercent:
          type: integer
          description: >-
            Percent of layer traffic that was reserved in the layer for this
            experiment iteration
        otherReservationPercent:
          type: integer
          description: >-
            Percent of layer traffic that was reserved for other experiments in
            the same environment, when this experiment iteration was stopped
      required:
        - key
        - name
        - reservationPercent
        - otherReservationPercent
      title: LayerSnapshotRep
    CovariateInfoRep:
      type: object
      properties:
        id:
          type: string
          description: The ID of the covariate matrix
        fileName:
          type: string
          description: The file name of the uploaded covariate matrix
        createdAt:
          $ref: '#/components/schemas/UnixMillis'
          description: Timestamp of when the covariate was uploaded
      required:
        - id
        - fileName
        - createdAt
      title: CovariateInfoRep
    IterationRep:
      type: object
      properties:
        _id:
          type: string
          description: The iteration ID
        hypothesis:
          type: string
          description: The expected outcome of this experiment
        status:
          $ref: '#/components/schemas/IterationRepStatus'
          description: >-
            The status of the iteration: <code>not_started</code>,
            <code>running</code>, <code>stopped</code>
        createdAt:
          $ref: '#/components/schemas/UnixMillis'
          description: Timestamp of when the iteration was created
        startedAt:
          $ref: '#/components/schemas/UnixMillis'
          description: Timestamp of when the iteration started
        endedAt:
          $ref: '#/components/schemas/UnixMillis'
          description: Timestamp of when the iteration ended
        winningTreatmentId:
          type: string
          description: The ID of the treatment chosen when the experiment stopped
        winningReason:
          type: string
          description: The reason you stopped the experiment
        canReshuffleTraffic:
          type: boolean
          description: >-
            Whether the experiment may reassign traffic to different variations
            when the experiment audience changes (true) or must keep all traffic
            assigned to its initial variation (false).
        flags:
          type: object
          additionalProperties:
            $ref: '#/components/schemas/FlagRep'
          description: Details on the flag used in this experiment
        reallocationFrequencyMillis:
          type: integer
          description: >-
            The cadence (in milliseconds) to update the allocation. Only present
            for multi-armed bandits.
        version:
          type: integer
          description: The current version that the iteration is on
        primaryMetric:
          $ref: '#/components/schemas/DependentMetricOrMetricGroupRep'
          description: >-
            Deprecated, use <code>primarySingleMetric</code> and
            <code>primaryFunnel</code> instead. Details on the primary metric
            for this experiment.
        primarySingleMetric:
          $ref: '#/components/schemas/MetricV2Rep'
          description: Details on the primary metric for this experiment
        primaryFunnel:
          $ref: '#/components/schemas/DependentMetricGroupRepWithMetrics'
          description: Details on the primary funnel group for this experiment
        randomizationUnit:
          type: string
          description: The unit of randomization for this iteration
        attributes:
          type: array
          items:
            type: string
          description: The available attribute filters for this iteration
        treatments:
          type: array
          items:
            $ref: '#/components/schemas/TreatmentRep'
          description: Details on the variations you are testing in the experiment
        secondaryMetrics:
          type: array
          items:
            $ref: '#/components/schemas/MetricV2Rep'
          description: >-
            Deprecated, use <code>metrics</code> instead. Details on the
            secondary metrics for this experiment.
        metrics:
          type: array
          items:
            $ref: '#/components/schemas/DependentMetricOrMetricGroupRep'
          description: Details on the metrics for this experiment
        layerSnapshot:
          $ref: '#/components/schemas/LayerSnapshotRep'
          description: >-
            Snapshot of the layer state on iteration stop, if part of a layer.
            Otherwise omitted.
        covariateInfo:
          $ref: '#/components/schemas/CovariateInfoRep'
          description: Details of the covariate file for stratified sampling
      required:
        - hypothesis
        - status
        - createdAt
      title: IterationRep
    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/projects/projectKey/environments/environmentKey/experiments/experimentKey/iterations"

payload = {
    "hypothesis": "Example hypothesis, the new button placement will increase conversion",
    "metrics": [{ "key": "metric-key-123abc" }],
    "treatments": [
        {
            "name": "Treatment 1",
            "baseline": True,
            "allocationPercent": "10",
            "parameters": [
                {
                    "flagKey": "example-flag-for-experiment",
                    "variationId": "e432f62b-55f6-49dd-a02f-eb24acf39d05"
                }
            ]
        }
    ],
    "flags": "{\"example-flag-key\": { \"ruleId\": \"e432f62b-55f6-49dd-a02f-eb24acf39d05\", \"flagConfigVersion\": 12, \"notInExperimentVariationId\": \"e432f62b-55f6-49dd-a02f-eb24acf39d05\" }}"
}
headers = {
    "Authorization": "<apiKey>",
    "Content-Type": "application/json"
}

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

print(response.json())
```

```javascript
const url = 'https://app.launchdarkly.com/api/v2/projects/projectKey/environments/environmentKey/experiments/experimentKey/iterations';
const options = {
  method: 'POST',
  headers: {Authorization: '<apiKey>', 'Content-Type': 'application/json'},
  body: '{"hypothesis":"Example hypothesis, the new button placement will increase conversion","metrics":[{"key":"metric-key-123abc"}],"treatments":[{"name":"Treatment 1","baseline":true,"allocationPercent":"10","parameters":[{"flagKey":"example-flag-for-experiment","variationId":"e432f62b-55f6-49dd-a02f-eb24acf39d05"}]}],"flags":"{\"example-flag-key\": { \"ruleId\": \"e432f62b-55f6-49dd-a02f-eb24acf39d05\", \"flagConfigVersion\": 12, \"notInExperimentVariationId\": \"e432f62b-55f6-49dd-a02f-eb24acf39d05\" }}"}'
};

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/environments/environmentKey/experiments/experimentKey/iterations"

	payload := strings.NewReader("{\n  \"hypothesis\": \"Example hypothesis, the new button placement will increase conversion\",\n  \"metrics\": [\n    {\n      \"key\": \"metric-key-123abc\"\n    }\n  ],\n  \"treatments\": [\n    {\n      \"name\": \"Treatment 1\",\n      \"baseline\": true,\n      \"allocationPercent\": \"10\",\n      \"parameters\": [\n        {\n          \"flagKey\": \"example-flag-for-experiment\",\n          \"variationId\": \"e432f62b-55f6-49dd-a02f-eb24acf39d05\"\n        }\n      ]\n    }\n  ],\n  \"flags\": \"{\\\"example-flag-key\\\": { \\\"ruleId\\\": \\\"e432f62b-55f6-49dd-a02f-eb24acf39d05\\\", \\\"flagConfigVersion\\\": 12, \\\"notInExperimentVariationId\\\": \\\"e432f62b-55f6-49dd-a02f-eb24acf39d05\\\" }}\"\n}")

	req, _ := http.NewRequest("POST", 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/environments/environmentKey/experiments/experimentKey/iterations")

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

request = Net::HTTP::Post.new(url)
request["Authorization"] = '<apiKey>'
request["Content-Type"] = 'application/json'
request.body = "{\n  \"hypothesis\": \"Example hypothesis, the new button placement will increase conversion\",\n  \"metrics\": [\n    {\n      \"key\": \"metric-key-123abc\"\n    }\n  ],\n  \"treatments\": [\n    {\n      \"name\": \"Treatment 1\",\n      \"baseline\": true,\n      \"allocationPercent\": \"10\",\n      \"parameters\": [\n        {\n          \"flagKey\": \"example-flag-for-experiment\",\n          \"variationId\": \"e432f62b-55f6-49dd-a02f-eb24acf39d05\"\n        }\n      ]\n    }\n  ],\n  \"flags\": \"{\\\"example-flag-key\\\": { \\\"ruleId\\\": \\\"e432f62b-55f6-49dd-a02f-eb24acf39d05\\\", \\\"flagConfigVersion\\\": 12, \\\"notInExperimentVariationId\\\": \\\"e432f62b-55f6-49dd-a02f-eb24acf39d05\\\" }}\"\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.post("https://app.launchdarkly.com/api/v2/projects/projectKey/environments/environmentKey/experiments/experimentKey/iterations")
  .header("Authorization", "<apiKey>")
  .header("Content-Type", "application/json")
  .body("{\n  \"hypothesis\": \"Example hypothesis, the new button placement will increase conversion\",\n  \"metrics\": [\n    {\n      \"key\": \"metric-key-123abc\"\n    }\n  ],\n  \"treatments\": [\n    {\n      \"name\": \"Treatment 1\",\n      \"baseline\": true,\n      \"allocationPercent\": \"10\",\n      \"parameters\": [\n        {\n          \"flagKey\": \"example-flag-for-experiment\",\n          \"variationId\": \"e432f62b-55f6-49dd-a02f-eb24acf39d05\"\n        }\n      ]\n    }\n  ],\n  \"flags\": \"{\\\"example-flag-key\\\": { \\\"ruleId\\\": \\\"e432f62b-55f6-49dd-a02f-eb24acf39d05\\\", \\\"flagConfigVersion\\\": 12, \\\"notInExperimentVariationId\\\": \\\"e432f62b-55f6-49dd-a02f-eb24acf39d05\\\" }}\"\n}")
  .asString();
```

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

$client = new \GuzzleHttp\Client();

$response = $client->request('POST', 'https://app.launchdarkly.com/api/v2/projects/projectKey/environments/environmentKey/experiments/experimentKey/iterations', [
  'body' => '{
  "hypothesis": "Example hypothesis, the new button placement will increase conversion",
  "metrics": [
    {
      "key": "metric-key-123abc"
    }
  ],
  "treatments": [
    {
      "name": "Treatment 1",
      "baseline": true,
      "allocationPercent": "10",
      "parameters": [
        {
          "flagKey": "example-flag-for-experiment",
          "variationId": "e432f62b-55f6-49dd-a02f-eb24acf39d05"
        }
      ]
    }
  ],
  "flags": "{\\"example-flag-key\\": { \\"ruleId\\": \\"e432f62b-55f6-49dd-a02f-eb24acf39d05\\", \\"flagConfigVersion\\": 12, \\"notInExperimentVariationId\\": \\"e432f62b-55f6-49dd-a02f-eb24acf39d05\\" }}"
}',
  '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/environments/environmentKey/experiments/experimentKey/iterations");
var request = new RestRequest(Method.POST);
request.AddHeader("Authorization", "<apiKey>");
request.AddHeader("Content-Type", "application/json");
request.AddParameter("application/json", "{\n  \"hypothesis\": \"Example hypothesis, the new button placement will increase conversion\",\n  \"metrics\": [\n    {\n      \"key\": \"metric-key-123abc\"\n    }\n  ],\n  \"treatments\": [\n    {\n      \"name\": \"Treatment 1\",\n      \"baseline\": true,\n      \"allocationPercent\": \"10\",\n      \"parameters\": [\n        {\n          \"flagKey\": \"example-flag-for-experiment\",\n          \"variationId\": \"e432f62b-55f6-49dd-a02f-eb24acf39d05\"\n        }\n      ]\n    }\n  ],\n  \"flags\": \"{\\\"example-flag-key\\\": { \\\"ruleId\\\": \\\"e432f62b-55f6-49dd-a02f-eb24acf39d05\\\", \\\"flagConfigVersion\\\": 12, \\\"notInExperimentVariationId\\\": \\\"e432f62b-55f6-49dd-a02f-eb24acf39d05\\\" }}\"\n}", ParameterType.RequestBody);
IRestResponse response = client.Execute(request);
```

```swift
import Foundation

let headers = [
  "Authorization": "<apiKey>",
  "Content-Type": "application/json"
]
let parameters = [
  "hypothesis": "Example hypothesis, the new button placement will increase conversion",
  "metrics": [["key": "metric-key-123abc"]],
  "treatments": [
    [
      "name": "Treatment 1",
      "baseline": true,
      "allocationPercent": "10",
      "parameters": [
        [
          "flagKey": "example-flag-for-experiment",
          "variationId": "e432f62b-55f6-49dd-a02f-eb24acf39d05"
        ]
      ]
    ]
  ],
  "flags": "{\"example-flag-key\": { \"ruleId\": \"e432f62b-55f6-49dd-a02f-eb24acf39d05\", \"flagConfigVersion\": 12, \"notInExperimentVariationId\": \"e432f62b-55f6-49dd-a02f-eb24acf39d05\" }}"
] as [String : Any]

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

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