> ## 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.

# Create Agent

> Creates a new agent with staging version. The agent will be created with an initial staging version that can later be promoted to production.

Creates a new agent with staging version. The agent will be created with an initial staging version that can later be promoted to production.

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

## 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>

## Query parameters

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

## Body

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

<ParamField body="name" type="string" default="Customer Support Agent">
  Name of the agent
</ParamField>

<ParamField body="description" type="string" default="AI agent specialized in handling customer inquiries and support tickets">
  Description of the agent
</ParamField>

<ParamField body="agencyId" type="string" default="gjL2sFNXJfJYa3d2OYSN">
  Agency ID
</ParamField>

<ParamField body="authorId" type="string" default="usr_abc123def456">
  Author ID
</ParamField>

<ParamField body="authorName" type="string" default="John Doe">
  Author name
</ParamField>

<ParamField body="authorEmail" type="string" default="john@example.com">
  Author email
</ParamField>

<ParamField body="status" type="string" required default="active">
  Status of the agent Posibles valores: 'active', 'inactive', 'archived'
</ParamField>

<ParamField body="version" type="object" required>
  Version data for the agent including nodes, edges, and configuration
</ParamField>

<ParamField body="nodes" type="string[]">
  Nodes array (deprecated, prefer using version.nodes)
</ParamField>

<ParamField body="edges" type="string[]">
  Edges array (deprecated, prefer using version.edges)
</ParamField>

## Respuestas

<Accordion title="201 - Agent created successfully">
  <ResponseField name="success" type="boolean" required default="True">
    Success status
  </ResponseField>

  <ResponseField name="message" type="string" required default="Agent created successfully with staging version.">
    Response message
  </ResponseField>

  <ResponseField name="agent" type="object" required>
    Created agent data with metadata
  </ResponseField>

  <ResponseField name="versions" type="object[]" required>
    Created versions array (initial staging version)
  </ResponseField>

  ```json theme={null}
  {
    "success": true,
    "message": "Agent created successfully with staging version.",
    "agent": {
      "agentId": "p1q2r3s4t5u6v7w8x9y0z1a2",
      "name": "Customer Support Agent",
      "description": "AI agent specialized in handling customer inquiries and support tickets",
      "locationId": "C2QujeCh8ZnC7al2InWR",
      "agencyId": "gjL2sFNXJfJYa3d2OYSN",
      "status": "active",
      "authorId": "usr_abc123def456",
      "folderId": "C2QujeCh8ZnC7al2InWR",
      "folderName": null,
      "createdAt": "2024-02-27T10:30:00.000Z",
      "updatedAt": "2024-02-27T10:30:00.000Z"
    },
    "versions": [
      {
        "versionId": "v1a2b3c4d5e6f7g8h9i0",
        "agentId": "p1q2r3s4t5u6v7w8x9y0z1a2",
        "versionName": "Customer Support Agent v1",
        "state": "staging",
        "isPublished": false,
        "version": 1,
        "createdAt": "2024-02-27T10:30:00.000Z"
      }
    ]
  }
  ```
</Accordion>

<Accordion title="400 - Bad Request">
  ```json theme={null}
  {}
  ```
</Accordion>

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

<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' \
    -H 'Authorization: Bearer YOUR_TOKEN' \
    -H 'Version: 2021-07-28' \
    -H 'Content-Type: application/json' \
    -d '{
    "locationId": "C2QujeCh8ZnC7al2InWR",
    "name": "Customer Support Agent",
    "description": "AI agent specialized in handling customer inquiries and support tickets",
    "agencyId": "gjL2sFNXJfJYa3d2OYSN",
    "authorId": "usr_abc123def456",
    "authorName": "John Doe",
    "authorEmail": "john@example.com",
    "status": "active",
    "version": {
      "versionName": "Version 1",
      "description": "Initial version",
      "nodes": [],
      "edges": [],
      "uiNodes": [],
      "uiEdges": [],
      "globalVariables": [],
      "inputVariables": [],
      "runtimeVariables": [],
      "scopes": []
    },
    "nodes": [],
    "edges": []
  }'
  ```

  ```javascript Node.js theme={null}
  const response = await fetch('https://services.leadconnectorhq.com/agent-studio/agent', {
    method: 'POST',
    headers: {
      Authorization: `Bearer ${process.env.LEADWAY_TOKEN}`,
      Version: '2021-07-28',
      'Content-Type': 'application/json',
    },
    body: JSON.stringify({"locationId": "C2QujeCh8ZnC7al2InWR", "name": "Customer Support Agent", "description": "AI agent specialized in handling customer inquiries and support tickets", "agencyId": "gjL2sFNXJfJYa3d2OYSN", "authorId": "usr_abc123def456", "authorName": "John Doe", "authorEmail": "john@example.com", "status": "active", "version": {"versionName": "Version 1", "description": "Initial version", "nodes": [], "edges": [], "uiNodes": [], "uiEdges": [], "globalVariables": [], "inputVariables": [], "runtimeVariables": [], "scopes": []}, "nodes": [], "edges": []}),
  });
  const data = await response.json();
  ```

  ```python Python theme={null}
  import os, requests
  response = requests.request(
      'POST',
      'https://services.leadconnectorhq.com/agent-studio/agent',
      headers={
          'Authorization': f"Bearer {os.environ['LEADWAY_TOKEN']}",
          'Version': '2021-07-28',
          'Content-Type': 'application/json',
      },
      json={"locationId": "C2QujeCh8ZnC7al2InWR", "name": "Customer Support Agent", "description": "AI agent specialized in handling customer inquiries and support tickets", "agencyId": "gjL2sFNXJfJYa3d2OYSN", "authorId": "usr_abc123def456", "authorName": "John Doe", "authorEmail": "john@example.com", "status": "active", "version": {"versionName": "Version 1", "description": "Initial version", "nodes": [], "edges": [], "uiNodes": [], "uiEdges": [], "globalVariables": [], "inputVariables": [], "runtimeVariables": [], "scopes": []}, "nodes": [], "edges": []},
  )
  data = response.json()
  ```

  ```php PHP theme={null}
  <?php
  $ch = curl_init('https://services.leadconnectorhq.com/agent-studio/agent');
  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', 'name': 'Customer Support Agent', 'description': 'AI agent specialized in handling customer inquiries and support tickets', 'agencyId': 'gjL2sFNXJfJYa3d2OYSN', 'authorId': 'usr_abc123def456', 'authorName': 'John Doe', 'authorEmail': 'john@example.com', 'status': 'active', 'version': {'versionName': 'Version 1', 'description': 'Initial version', 'nodes': [], 'edges': [], 'uiNodes': [], 'uiEdges': [], 'globalVariables': [], 'inputVariables': [], 'runtimeVariables': [], 'scopes': []}, 'nodes': [], 'edges': []}),
  ]);
  $data = json_decode(curl_exec($ch), true);
  ```
</CodeGroup>
