# Create experiment

- Operation ID: `CreateExperimentV2`
- HTTP method: `POST`
- Path: `/optimizer/v2/experiments`
- [Human-readable API reference](https://hub.synerise.com/api-reference/ai-suite#tag/Experiments/operation/CreateExperimentV2)

## Self-contained OpenAPI method

The fenced document below contains this method's documentation and all of its local references. It is self-contained; no category or master specification fetch is required.

```yaml
openapi: 3.0.0
info:
  title: Synerise Public API
  version: 1.9.1
paths:
  /optimizer/v2/experiments:
    post:
      summary: Create experiment
      description: |
        Create a new A/B/X test for recommendations or item search.

        ---

        **API consumers:** <a href="/api-reference/authorization?tag=Authorization&amp;operationId=profileLogin" target="_blank" rel="noopener">Workspace (Business Profile)</a>, <a href="/api-reference/authorization?tag=Authorization&amp;operationId=userLogin" target="_blank" rel="noopener">Synerise User</a>

        **API key permission required:** `OPTIMIZER_MANAGER_TESTOPTIMIZER_CREATE`

        **User role permission required:** `campaigns_test_optimizer: create`
      operationId: CreateExperimentV2
      tags:
        - Experiments
      security:
        - JWT: []
      requestBody:
        required: true
        content:
          application/json:
            schema:
              type: object
              properties:
                name:
                  type: string
                  description: Experiment name
                description:
                  type: string
                  description: Experiment description
                experimentKind:
                  type: string
                  description: The type of the experiment
                  enum:
                    - ITEMS_SEARCH
                    - RECOMMENDATION_CAMPAIGN
                variantsAllocationMethod:
                  type: string
                  enum:
                    - Manual
                  description: The variant allocation method. Currently, only `Manual` is available.
                variants:
                  type: array
                  description: An array of experiment variants
                  items:
                    type: object
                    properties:
                      externalId:
                        type: string
                        description: |
                          Identifier of the resource to request with this variant.

                          - For recommendations, this is the recommendation campaign ID.
                          - For items/suggestion search, this is the search/suggestion index ID.
                      name:
                        type: string
                        description: Variant name
                      weight:
                        type: integer
                        maximum: 10000
                        description: |
                          Importance of the variant. Higher value means higher importance.  
                          The total weight of all variants must be <= 10000.
                      metadata:
                        type: string
                        description: Additional data
                      isBaseline:
                        type: boolean
                        description: "`true` if this is the baseline variant. When making a search/recommendation request, you will use the ID of the baseline index/recommendation and then the system will return a result from one of the variants."
                    required:
                      - externalId
                      - weight
              required:
                - name
                - experimentKind
                - variantsAllocationMethod
                - variants
      responses:
        "200":
          description: ID of the created experiment
          content:
            application/json:
              schema:
                type: object
                properties:
                  experimentId:
                    type: integer
                    description: ID of the experiment
        "400":
          description: Check error message for more details.
          content:
            application/json:
              schema:
                type: object
                properties:
                  error:
                    type: string
                    description: Description of the error
                  errorCode:
                    type: string
                    description: Synerise error code. See [Error Code Reference](https://developers.synerise.com/errors.html).
                  help:
                    type: string
                    description: Link to the error reference page for this error
                  httpStatus:
                    type: integer
                    description: HTTP code of the error
                  message:
                    type: string
                    description: Description of the error
                  path:
                    type: string
                    description: Path of the resource which returned the error
                  requestId:
                    type: string
                    description: Unique request ID
                  status:
                    type: integer
                    description: Internal code for troubleshooting
                  timestamp:
                    type: string
                    format: date-time
                    description: Time when the error occurred
                  traceId:
                    type: string
                    description: Trace ID for troubleshooting
      x-snr-doc-urls:
        - /api-reference/ai-suite#tag/Experiments/operation/CreateExperimentV2
      x-codeSamples:
        - lang: cURL
          label: cURL
          source: |-
            curl --request POST \
              --url https://api.synerise.com/optimizer/v2/experiments \
              --header 'Authorization: Bearer REPLACE_BEARER_TOKEN' \
              --header 'content-type: application/json' \
              --data '{"name":"string","description":"string","experimentKind":"ITEMS_SEARCH","variantsAllocationMethod":"Manual","variants":[{"externalId":"string","name":"string","weight":10000,"metadata":"string","isBaseline":true}]}'
        - lang: Python
          label: Python
          source: |-
            import http.client

            conn = http.client.HTTPSConnection("api.synerise.com")

            payload = "{\"name\":\"string\",\"description\":\"string\",\"experimentKind\":\"ITEMS_SEARCH\",\"variantsAllocationMethod\":\"Manual\",\"variants\":[{\"externalId\":\"string\",\"name\":\"string\",\"weight\":10000,\"metadata\":\"string\",\"isBaseline\":true}]}"

            headers = {
                'Authorization': "Bearer REPLACE_BEARER_TOKEN",
                'content-type': "application/json"
                }

            conn.request("POST", "/optimizer/v2/experiments", payload, headers)

            res = conn.getresponse()
            data = res.read()

            print(data.decode("utf-8"))
        - lang: JavaScript
          label: JavaScript
          source: |-
            const data = JSON.stringify({
              "name": "string",
              "description": "string",
              "experimentKind": "ITEMS_SEARCH",
              "variantsAllocationMethod": "Manual",
              "variants": [
                {
                  "externalId": "string",
                  "name": "string",
                  "weight": 10000,
                  "metadata": "string",
                  "isBaseline": true
                }
              ]
            });

            const xhr = new XMLHttpRequest();
            xhr.withCredentials = true;

            xhr.addEventListener("readystatechange", function () {
              if (this.readyState === this.DONE) {
                console.log(this.responseText);
              }
            });

            xhr.open("POST", "https://api.synerise.com/optimizer/v2/experiments");
            xhr.setRequestHeader("Authorization", "Bearer REPLACE_BEARER_TOKEN");
            xhr.setRequestHeader("content-type", "application/json");

            xhr.send(data);
        - lang: Node.js
          label: Node.js
          source: |-
            const http = require("https");

            const options = {
              "method": "POST",
              "hostname": "api.synerise.com",
              "port": null,
              "path": "/optimizer/v2/experiments",
              "headers": {
                "Authorization": "Bearer REPLACE_BEARER_TOKEN",
                "content-type": "application/json"
              }
            };

            const req = http.request(options, function (res) {
              const chunks = [];

              res.on("data", function (chunk) {
                chunks.push(chunk);
              });

              res.on("end", function () {
                const body = Buffer.concat(chunks);
                console.log(body.toString());
              });
            });

            req.write(JSON.stringify({
              name: 'string',
              description: 'string',
              experimentKind: 'ITEMS_SEARCH',
              variantsAllocationMethod: 'Manual',
              variants: [
                {
                  externalId: 'string',
                  name: 'string',
                  weight: 10000,
                  metadata: 'string',
                  isBaseline: true
                }
              ]
            }));
            req.end();
        - lang: PHP
          label: PHP
          source: |-
            <?php

            $request = new HttpRequest();
            $request->setUrl('https://api.synerise.com/optimizer/v2/experiments');
            $request->setMethod(HTTP_METH_POST);

            $request->setHeaders([
              'Authorization' => 'Bearer REPLACE_BEARER_TOKEN',
              'content-type' => 'application/json'
            ]);

            $request->setBody('{"name":"string","description":"string","experimentKind":"ITEMS_SEARCH","variantsAllocationMethod":"Manual","variants":[{"externalId":"string","name":"string","weight":10000,"metadata":"string","isBaseline":true}]}');

            try {
              $response = $request->send();

              echo $response->getBody();
            } catch (HttpException $ex) {
              echo $ex;
            }
        - lang: Java
          label: Java
          source: |-
            HttpResponse<String> response = Unirest.post("https://api.synerise.com/optimizer/v2/experiments")
              .header("Authorization", "Bearer REPLACE_BEARER_TOKEN")
              .header("content-type", "application/json")
              .body("{\"name\":\"string\",\"description\":\"string\",\"experimentKind\":\"ITEMS_SEARCH\",\"variantsAllocationMethod\":\"Manual\",\"variants\":[{\"externalId\":\"string\",\"name\":\"string\",\"weight\":10000,\"metadata\":\"string\",\"isBaseline\":true}]}")
              .asString();
servers:
  - description: Microsoft Azure EU
    url: https://api.synerise.com
  - description: Microsoft Azure USA
    url: https://api.azu.synerise.com
  - description: Google Cloud Platform
    url: https://api.geb.synerise.com
tags:
  - name: Experiments
components:
  securitySchemes:
    JWT:
      type: http
      scheme: bearer
      description: |-
        JWT Bearer token. The header looks like this: `Bearer {JWT}`

        Remember to include the space between 'Bearer' and the token.

        Generate a token via the **Authorization** endpoints.
```
