# Proxy a single /_edit call through desktop auth (no long-lived edit token on laptop).

POST https://services.leadconnectorhq.com/ai-builder-api/cli/projects/{projectId}/sandbox/edit

Writes or deletes one file in the app's sandbox. Then start a run with `externalAgent: true` to check, build and deploy the edits.

## Authentication

Send `Authorization: Bearer <token>` using:

- **Sub-Account token: OAuth access token or Private Integration Token.** Scopes: `clientportal-ai.write`

## Parameters

### Header Parameters

| Name | Type | Required | Description |
|------|------|----------|-------------|
| `Version` | string | Yes | The API version. |

### Path Parameters

| Name | Type | Required | Description |
|------|------|----------|-------------|
| `projectId` | string | Yes | Project identifier. |

## OpenAPI Specification

```json
{
  "openapi": "3.0.0",
  "info": {
    "title": "HighLevel API",
    "version": "v3"
  },
  "servers": [
    {
      "url": "https://services.leadconnectorhq.com"
    }
  ],
  "paths": {
    "/ai-builder-api/cli/projects/{projectId}/sandbox/edit": {
      "post": {
        "summary": "Proxy a single /_edit call through desktop auth (no long-lived edit token on laptop).",
        "operationId": "proxyASingleEditCallThroughDesktopAuthNoLonglivedEditTokenOnLaptop",
        "description": "Writes or deletes one file in the app's sandbox. Then start a run with `externalAgent: true` to check, build and deploy the edits.",
        "parameters": [
          {
            "name": "projectId",
            "in": "path",
            "required": true,
            "description": "Project identifier.",
            "schema": {
              "type": "string",
              "pattern": "^prj_[A-Za-z0-9]+$",
              "example": "prj_01HXQ8Z6J9K2"
            }
          },
          {
            "name": "Version",
            "in": "header",
            "required": true,
            "description": "The API version.",
            "schema": {
              "type": "string",
              "enum": [
                "v3"
              ]
            }
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/CliSandboxEditRequest"
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "File written in the dev sandbox.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ProxyASingleEditCallThroughDesktopAuthNoLonglivedEditTokenOnLaptopResponse"
                }
              }
            }
          }
        },
        "security": [
          {
            "bearer": [
              "clientportal-ai.write"
            ]
          }
        ]
      }
    }
  },
  "components": {
    "securitySchemes": {
      "bearer": {
        "type": "http",
        "scheme": "bearer",
        "description": "A sub-account access token: a Marketplace app's OAuth token or a Private Integration Token."
      }
    },
    "schemas": {
      "CliSandboxEditRequest": {
        "type": "object",
        "required": [
          "path"
        ],
        "properties": {
          "path": {
            "type": "string",
            "description": "File to write or delete, relative to the workspace root.",
            "example": "apps/clientportal-custom-app/pages/welcome.vue"
          },
          "action": {
            "type": "string",
            "enum": [
              "update",
              "delete"
            ],
            "description": "`update` writes `content` (the default); `delete` removes the file.",
            "example": "update"
          },
          "content": {
            "type": "string",
            "description": "The file's full new content, encoded as `encoding` says.",
            "example": "<template><h1>Welcome</h1></template>\n"
          },
          "encoding": {
            "type": "string",
            "enum": [
              "utf-8",
              "base64"
            ],
            "description": "How `content` is encoded; `utf-8` by default.",
            "example": "utf-8"
          }
        },
        "title": "CliSandboxEditRequest"
      },
      "ProxyASingleEditCallThroughDesktopAuthNoLonglivedEditTokenOnLaptopResponse": {
        "type": "object",
        "required": [
          "ok",
          "path"
        ],
        "properties": {
          "ok": {
            "type": "boolean",
            "enum": [
              true
            ],
            "description": "The file was written or deleted.",
            "example": true
          },
          "path": {
            "type": "string",
            "description": "The file, relative to the workspace root.",
            "example": "apps/clientportal-custom-app/pages/welcome.vue"
          }
        }
      }
    }
  }
}
```

## Code Examples

**cURL**

```bash
curl -L -X POST 'https://services.leadconnectorhq.com/ai-builder-api/cli/projects/<projectId>/sandbox/edit' \
  -H 'Authorization: Bearer <TOKEN>' \
  -H 'Version: v3' \
  -H 'Content-Type: application/json' \
  --data-raw '{
  "path": "apps/clientportal-custom-app/pages/welcome.vue",
  "action": "update",
  "content": "<template><h1>Welcome</h1></template>\n",
  "encoding": "utf-8"
}'
```

**Node.js**

```javascript
const options = {
  method: 'POST',
  headers: {
    Authorization: 'Bearer <TOKEN>',
    Version: 'v3',
    'Content-Type': 'application/json'
  },
  body: JSON.stringify({
      "path": "apps/clientportal-custom-app/pages/welcome.vue",
      "action": "update",
      "content": "<template><h1>Welcome</h1></template>\n",
      "encoding": "utf-8"
  })
};

try {
  const response = await fetch('https://services.leadconnectorhq.com/ai-builder-api/cli/projects/<projectId>/sandbox/edit', options);
  const data = await response.json();
  console.log(data);
} catch (error) {
  console.error(error);
}
```

**Python**

```python
import requests

url = "https://services.leadconnectorhq.com/ai-builder-api/cli/projects/{projectId}/sandbox/edit"

headers = {
    "Authorization": "Bearer <TOKEN>",
    "Version": "v3"
}

payload = {
    "path": "apps/clientportal-custom-app/pages/welcome.vue",
    "action": "update",
    "content": "<template><h1>Welcome</h1></template>\n",
    "encoding": "utf-8"
}

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

**PHP**

```php
<?php
$curl = curl_init();

curl_setopt_array($curl, [
  CURLOPT_URL => 'https://services.leadconnectorhq.com/ai-builder-api/cli/projects/<projectId>/sandbox/edit',
  CURLOPT_RETURNTRANSFER => true,
  CURLOPT_CUSTOMREQUEST => 'POST',
  CURLOPT_HTTPHEADER => [
    'Authorization: Bearer <TOKEN>',
    'Version: v3',
    'Content-Type: application/json',
  ],
  CURLOPT_POSTFIELDS => '{
  "path": "apps/clientportal-custom-app/pages/welcome.vue",
  "action": "update",
  "content": "<template><h1>Welcome</h1></template>\n",
  "encoding": "utf-8"
}',
]);

$response = curl_exec($curl);
curl_close($curl);
echo $response;
```

**Java**

```java
HttpResponse<String> response = Unirest
  .post("https://services.leadconnectorhq.com/ai-builder-api/cli/projects/<projectId>/sandbox/edit")
  .header("Authorization", "Bearer <TOKEN>")
  .header("Version", "v3")
  .header("Content-Type", "application/json")
  .body("{\"path\":\"apps/clientportal-custom-app/pages/welcome.vue\",\"action\":\"update\",\"content\":\"<template><h1>Welcome</h1></template>\\n\",\"encoding\":\"utf-8\"}")
  .asString();
```

**Go**

```go
package main

import (
  "fmt"
  "net/http"
  "io"
  "strings"
)

func main() {
  url := "https://services.leadconnectorhq.com/ai-builder-api/cli/projects/<projectId>/sandbox/edit"
  payload := strings.NewReader(`{
  "path": "apps/clientportal-custom-app/pages/welcome.vue",
  "action": "update",
  "content": "<template><h1>Welcome</h1></template>\n",
  "encoding": "utf-8"
}`)
  req, _ := http.NewRequest("POST", url, payload)
  req.Header.Add("Authorization", "Bearer <TOKEN>")
  req.Header.Add("Version", "v3")

  res, _ := http.DefaultClient.Do(req)
  defer res.Body.Close()
  body, _ := io.ReadAll(res.Body)
  fmt.Println(string(body))
}
```

**Ruby**

```ruby
require 'uri'
require 'net/http'

url = URI("https://services.leadconnectorhq.com/ai-builder-api/cli/projects/<projectId>/sandbox/edit")

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

request = Net::HTTP::Post.new(url)
request["Authorization"] = "Bearer <TOKEN>"
request["Version"] = "v3"
request["Content-Type"] = "application/json"
request.body = '{
  "path": "apps/clientportal-custom-app/pages/welcome.vue",
  "action": "update",
  "content": "<template><h1>Welcome</h1></template>\n",
  "encoding": "utf-8"
}'

response = http.request(request)
puts response.read_body
```

**PowerShell**

```powershell
$headers = @{
  "Authorization" = "Bearer <TOKEN>"
  "Version" = "v3"
}

$body = '{
  "path": "apps/clientportal-custom-app/pages/welcome.vue",
  "action": "update",
  "content": "<template><h1>Welcome</h1></template>\n",
  "encoding": "utf-8"
}'

$response = Invoke-RestMethod -Uri 'https://services.leadconnectorhq.com/ai-builder-api/cli/projects/<projectId>/sandbox/edit' -Method 'POST' -Headers $headers -Body $body -ContentType 'application/json'
$response | ConvertTo-Json
```
