# Register, rename or remove a React Native app's screens.

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

Changes the screen list of a React Native app (`react_native_app_kernel_v1`) once its screen files are written with `POST .../sandbox/edit`: `app-extensions/routes.ts` is generated from these changes, never written as text. Send several changes as one `batch`: all of them apply or none does, and a resent batch that is already in effect changes nothing (a repeated single `add` is refused as `duplicate_id`). The run started next with `externalAgent: true` checks the screens, saves them as a mobile revision and deploys the preview.

## 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/extension-routes": {
      "post": {
        "summary": "Register, rename or remove a React Native app's screens.",
        "operationId": "registerRenameOrRemoveAReactNativeAppsScreens",
        "description": "Changes the screen list of a React Native app (`react_native_app_kernel_v1`) once its screen files are written with `POST .../sandbox/edit`: `app-extensions/routes.ts` is generated from these changes, never written as text. Send several changes as one `batch`: all of them apply or none does, and a resent batch that is already in effect changes nothing (a repeated single `add` is refused as `duplicate_id`). The run started next with `externalAgent: true` checks the screens, saves them as a mobile revision and deploys the preview.",
        "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/RegisterRenameOrRemoveAReactNativeAppsScreensDto"
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "The route change, or why it was refused (ok false with reason and error).",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/CliExtensionRouteResult"
                }
              }
            }
          },
          "409": {
            "description": "Not a React Native project, or a cloud build owns the sandbox."
          },
          "503": {
            "description": "The app's sandbox was asleep and is starting (`sandbox_starting`). Retry in about a minute; the app's context reports `ready` once it is up."
          }
        },
        "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": {
      "RegisterRenameOrRemoveAReactNativeAppsScreensDto": {
        "type": "object",
        "additionalProperties": false,
        "required": [
          "action"
        ],
        "properties": {
          "action": {
            "type": "object",
            "description": "One change, or several as `{ \"action\": \"batch\", \"changes\": [...] }`. A change is `{ \"action\": \"add\", \"route\": { \"id\", \"label\", \"icon\", \"requires\"?, \"parent\"?, \"copyKey\"?, \"filledIcon\"? } }`, `{ \"action\": \"rename\", \"id\", \"newId\", \"label\"? }` or `{ \"action\": \"remove\", \"id\" }`. `id` is kebab-case and names the screen file; `icon` is one of the kernel's icon names, and an unknown one is refused; `parent` makes the screen a detail pushed from that route.",
            "additionalProperties": true,
            "example": {
              "action": "batch",
              "changes": [
                {
                  "action": "add",
                  "route": {
                    "id": "class-schedule",
                    "label": "Schedule",
                    "icon": "Calendar"
                  }
                }
              ]
            }
          }
        }
      },
      "CliExtensionRouteResult": {
        "type": "object",
        "required": [
          "ok"
        ],
        "properties": {
          "ok": {
            "type": "boolean",
            "description": "Whether the change applied. False changes nothing; `reason`, `error` and `problems` say why.",
            "example": true
          },
          "action": {
            "type": "string",
            "enum": [
              "add",
              "rename",
              "remove",
              "batch"
            ],
            "description": "The action that applied.",
            "example": "batch"
          },
          "changed": {
            "description": "The route id a single change added, renamed to or removed; for a batch, every such id.",
            "example": [
              "class-schedule"
            ],
            "oneOf": [
              {
                "type": "string"
              },
              {
                "type": "array",
                "items": {
                  "type": "string"
                }
              }
            ]
          },
          "unchanged": {
            "type": "array",
            "items": {
              "type": "string"
            },
            "description": "Ids whose change in the batch was already in effect.",
            "example": []
          },
          "routes": {
            "type": "array",
            "description": "The app's routes after the change.",
            "example": [
              {
                "id": "class-schedule",
                "href": "/(app)/ext/class-schedule",
                "label": "Schedule"
              }
            ],
            "items": {
              "type": "object",
              "required": [
                "id",
                "href",
                "label"
              ],
              "properties": {
                "id": {
                  "type": "string",
                  "description": "The route id, which is the screen's file name.",
                  "example": "class-schedule"
                },
                "href": {
                  "type": "string",
                  "description": "The route's path in the app, derived from its id.",
                  "example": "/(app)/ext/class-schedule"
                },
                "label": {
                  "type": "string",
                  "description": "The name the app shows for the screen.",
                  "example": "Schedule"
                }
              }
            }
          },
          "summary": {
            "type": "string",
            "description": "What changed, in one sentence.",
            "example": "Added class-schedule."
          },
          "reason": {
            "type": "string",
            "description": "Why the change was refused, as a code.",
            "example": "duplicate_id"
          },
          "error": {
            "type": "string",
            "description": "Why the change was refused, in words.",
            "example": "change 0: screen id \"class-schedule\" is already registered"
          },
          "problems": {
            "type": "array",
            "description": "Every problem a refused batch found, so one answer fixes them all.",
            "example": [
              {
                "reason": "duplicate_id",
                "message": "change 0: screen id \"class-schedule\" is already registered"
              }
            ],
            "items": {
              "type": "object",
              "required": [
                "reason",
                "message"
              ],
              "properties": {
                "reason": {
                  "type": "string",
                  "description": "The problem, as a code.",
                  "example": "duplicate_id"
                },
                "message": {
                  "type": "string",
                  "description": "The problem, in words.",
                  "example": "change 0: screen id \"class-schedule\" is already registered"
                }
              }
            }
          }
        },
        "title": "CliExtensionRouteResult"
      }
    }
  }
}
```

## Code Examples

**cURL**

```bash
curl -L -X POST 'https://services.leadconnectorhq.com/ai-builder-api/cli/projects/<projectId>/sandbox/extension-routes' \
  -H 'Authorization: Bearer <TOKEN>' \
  -H 'Version: v3' \
  -H 'Content-Type: application/json' \
  --data-raw '{
  "action": {
    "action": "batch",
    "changes": [
      {
        "action": "add",
        "route": {
          "id": "class-schedule",
          "label": "Schedule",
          "icon": "Calendar"
        }
      }
    ]
  }
}'
```

**Node.js**

```javascript
const options = {
  method: 'POST',
  headers: {
    Authorization: 'Bearer <TOKEN>',
    Version: 'v3',
    'Content-Type': 'application/json'
  },
  body: JSON.stringify({
      "action": {
        "action": "batch",
        "changes": [
          {
            "action": "add",
            "route": {
              "id": "class-schedule",
              "label": "Schedule",
              "icon": "Calendar"
            }
          }
        ]
      }
  })
};

try {
  const response = await fetch('https://services.leadconnectorhq.com/ai-builder-api/cli/projects/<projectId>/sandbox/extension-routes', 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/extension-routes"

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

payload = {
    "action": {
        "action": "batch",
        "changes": [
            {
                "action": "add",
                "route": {
                    "id": "class-schedule",
                    "label": "Schedule",
                    "icon": "Calendar"
                }
            }
        ]
    }
}

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/extension-routes',
  CURLOPT_RETURNTRANSFER => true,
  CURLOPT_CUSTOMREQUEST => 'POST',
  CURLOPT_HTTPHEADER => [
    'Authorization: Bearer <TOKEN>',
    'Version: v3',
    'Content-Type: application/json',
  ],
  CURLOPT_POSTFIELDS => '{
  "action": {
    "action": "batch",
    "changes": [
      {
        "action": "add",
        "route": {
          "id": "class-schedule",
          "label": "Schedule",
          "icon": "Calendar"
        }
      }
    ]
  }
}',
]);

$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/extension-routes")
  .header("Authorization", "Bearer <TOKEN>")
  .header("Version", "v3")
  .header("Content-Type", "application/json")
  .body("{\"action\":{\"action\":\"batch\",\"changes\":[{\"action\":\"add\",\"route\":{\"id\":\"class-schedule\",\"label\":\"Schedule\",\"icon\":\"Calendar\"}}]}}")
  .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/extension-routes"
  payload := strings.NewReader(`{
  "action": {
    "action": "batch",
    "changes": [
      {
        "action": "add",
        "route": {
          "id": "class-schedule",
          "label": "Schedule",
          "icon": "Calendar"
        }
      }
    ]
  }
}`)
  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/extension-routes")

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 = '{
  "action": {
    "action": "batch",
    "changes": [
      {
        "action": "add",
        "route": {
          "id": "class-schedule",
          "label": "Schedule",
          "icon": "Calendar"
        }
      }
    ]
  }
}'

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

**PowerShell**

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

$body = '{
  "action": {
    "action": "batch",
    "changes": [
      {
        "action": "add",
        "route": {
          "id": "class-schedule",
          "label": "Schedule",
          "icon": "Calendar"
        }
      }
    ]
  }
}'

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