> ## Documentation Index
> Fetch the complete documentation index at: https://developers.leadwaycrm.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Promote to Production

> Promotes a draft version to production.

Promotes a draft version to production.

```http theme={null}
POST https://services.leadconnectorhq.com/agent-studio/agent/versions/{versionId}/publish
```

## Autorización

<ParamField header="Authorization" type="string" required>
  Bearer token generado desde el portal Leadway. Ver [Autenticación](/authentication).
</ParamField>

<ParamField header="Version" type="string" required default="2021-07-28">
  Versión de la API.
</ParamField>

## Path parameters

<ParamField path="versionId" type="string" required default="v1a2b3c4d5e6f7g8h9i0" />

## Query parameters

<ParamField query="source" type="string" default="api" />

## Body

<ParamField body="locationId" type="string" required default="C2QujeCh8ZnC7al2InWR">
  Account ID for authorization
</ParamField>

<ParamField body="userId" type="string" default="usr_abc123def456">
  User ID performing the promotion action
</ParamField>

<ParamField body="userName" type="string" default="John Doe">
  User name performing the promotion action
</ParamField>

<ParamField body="userEmail" type="string" default="john.doe@example.com">
  User email performing the promotion action
</ParamField>

## Respuestas

<Accordion title="200 - Version promoted and published successfully">
  <ResponseField name="success" type="boolean" required default="True">
    Success status
  </ResponseField>

  <ResponseField name="message" type="string" required default="Draft published to production successfully. New draft version created for future edits.">
    Response message
  </ResponseField>

  <ResponseField name="data" type="object" required>
    Result data with production and new draft version details
  </ResponseField>

  ```json theme={null}
  {
    "success": true,
    "message": "Draft published to production successfully. New draft version created for future edits.",
    "data": {
      "productionVersion": {
        "versionId": "v1a2b3c4d5e6f7g8h9i0",
        "agentId": "p1q2r3s4t5u6v7w8x9y0z1a2",
        "versionName": "Customer Support Agent v2",
        "state": "prod",
        "isPublished": true,
        "version": 2,
        "publishedAt": "2024-02-27T12:00:00.000Z",
        "publishedBy": "usr_abc123def456",
        "publishedByName": "John Doe",
        "publishedByEmail": "john.doe@example.com"
      },
      "newDraftVersion": {
        "versionId": "v2b3c4d5e6f7g8h9i0j1",
        "agentId": "p1q2r3s4t5u6v7w8x9y0z1a2",
        "versionName": "Customer Support Agent v3",
        "state": "draft",
        "isPublished": false,
        "version": 3,
        "createdAt": "2024-02-27T12:00:00.000Z"
      }
    }
  }
  ```
</Accordion>

<Accordion title="400 - Bad Request - Only draft versions can be promoted" />

<Accordion title="401 - Unauthorized">
  ```json theme={null}
  {}
  ```
</Accordion>

<Accordion title="404 - Version not found" />

<Accordion title="422 - Unprocessable Entity">
  ```json theme={null}
  {}
  ```
</Accordion>

<Accordion title="500 - Internal Server Error">
  <ResponseField name="statusCode" type="number" default="500" />

  <ResponseField name="message" type="string" default="Internal Server Error" />

  ```json theme={null}
  {
    "statusCode": 500,
    "message": "Internal Server Error"
  }
  ```
</Accordion>

## Ejemplo

<CodeGroup>
  ```bash cURL theme={null}
  curl -X POST 'https://services.leadconnectorhq.com/agent-studio/agent/versions/YOUR_versionId/publish' \
    -H 'Authorization: Bearer YOUR_TOKEN' \
    -H 'Version: 2021-07-28' \
    -H 'Content-Type: application/json' \
    -d '{
    "locationId": "C2QujeCh8ZnC7al2InWR",
    "userId": "usr_abc123def456",
    "userName": "John Doe",
    "userEmail": "john.doe@example.com"
  }'
  ```

  ```javascript Node.js theme={null}
  const response = await fetch('https://services.leadconnectorhq.com/agent-studio/agent/versions/YOUR_versionId/publish', {
    method: 'POST',
    headers: {
      Authorization: `Bearer ${process.env.LEADWAY_TOKEN}`,
      Version: '2021-07-28',
      'Content-Type': 'application/json',
    },
    body: JSON.stringify({"locationId": "C2QujeCh8ZnC7al2InWR", "userId": "usr_abc123def456", "userName": "John Doe", "userEmail": "john.doe@example.com"}),
  });
  const data = await response.json();
  ```

  ```python Python theme={null}
  import os, requests
  response = requests.request(
      'POST',
      'https://services.leadconnectorhq.com/agent-studio/agent/versions/YOUR_versionId/publish',
      headers={
          'Authorization': f"Bearer {os.environ['LEADWAY_TOKEN']}",
          'Version': '2021-07-28',
          'Content-Type': 'application/json',
      },
      json={"locationId": "C2QujeCh8ZnC7al2InWR", "userId": "usr_abc123def456", "userName": "John Doe", "userEmail": "john.doe@example.com"},
  )
  data = response.json()
  ```

  ```php PHP theme={null}
  <?php
  $ch = curl_init('https://services.leadconnectorhq.com/agent-studio/agent/versions/YOUR_versionId/publish');
  curl_setopt_array($ch, [
      CURLOPT_RETURNTRANSFER => true,
      CURLOPT_CUSTOMREQUEST => 'POST',
      CURLOPT_HTTPHEADER => [
          'Authorization: Bearer ' . getenv('LEADWAY_TOKEN'),
          'Version: 2021-07-28',
          'Content-Type: application/json',
      ],
      CURLOPT_POSTFIELDS => json_encode({'locationId': 'C2QujeCh8ZnC7al2InWR', 'userId': 'usr_abc123def456', 'userName': 'John Doe', 'userEmail': 'john.doe@example.com'}),
  ]);
  $data = json_decode(curl_exec($ch), true);
  ```
</CodeGroup>
