# Read an app's stack and open its sandbox for editing.

GET https://services.leadconnectorhq.com/ai-builder-api/cli/projects/{projectId}/context

Returns the app's stack, which decides how its code is written, and its kernel bundle, and opens the app's sandbox: read and edit it once `sandbox.status` is `ready`. A `react_native_app_kernel_v1` app is a phone app: its screens are files under `apps/mobile/app-extensions/`, registered with `POST .../sandbox/extension-routes`. Every other stack is a web portal.

## 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": "LeadConnector API",
    "version": "v3"
  },
  "servers": [
    {
      "url": "https://services.leadconnectorhq.com"
    }
  ],
  "paths": {
    "/ai-builder-api/cli/projects/{projectId}/context": {
      "get": {
        "summary": "Read an app's stack and open its sandbox for editing.",
        "operationId": "readAnAppsStackAndOpenItsSandboxForEditing",
        "description": "Returns the app's stack, which decides how its code is written, and its kernel bundle, and opens the app's sandbox: read and edit it once `sandbox.status` is `ready`. A `react_native_app_kernel_v1` app is a phone app: its screens are files under `apps/mobile/app-extensions/`, registered with `POST .../sandbox/extension-routes`. Every other stack is a web portal.",
        "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"
              ]
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Resolved stack manifest and kernel bundle hint.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/CliProjectContext"
                }
              }
            }
          }
        },
        "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": {
      "CliProjectContext": {
        "type": "object",
        "required": [
          "projectId",
          "productTarget",
          "stackTemplate",
          "stackManifestId",
          "kernelBundleHint",
          "sandbox"
        ],
        "properties": {
          "projectId": {
            "type": "string",
            "description": "The project.",
            "example": "prj_5f0c2a3e"
          },
          "productTarget": {
            "type": "string",
            "description": "What the project builds: `full_stack` (a web portal), `mobile` or `landing_page`.",
            "example": "full_stack"
          },
          "stackTemplate": {
            "type": "string",
            "description": "The kernel the project is built on.",
            "example": "nuxt_clientportal_app_v1"
          },
          "templateId": {
            "type": "string",
            "description": "The starter template the project was created from, when it had one.",
            "example": "learning-community"
          },
          "stackManifestId": {
            "type": "string",
            "description": "The stack manifest the project's sandbox follows.",
            "example": "nuxt_clientportal_app_v1"
          },
          "kernelBundleHint": {
            "type": "string",
            "description": "File name of this stack's kernel bundle.",
            "example": "kernel-nuxt_clientportal_app_v1.tgz"
          },
          "sandbox": {
            "type": "object",
            "required": [
              "status"
            ],
            "description": "The sandbox this call opened. Edit and read once it is `ready`; call again while it is `provisioning` (a sandbox reclaimed while the app sat idle is restored from its last save). `no_history`: a web app was never built, and its first run (`externalAgent: true`) creates it; a never-built phone app is opened here, so its screens are written before its first build.",
            "example": {
              "status": "ready",
              "devUrl": "https://prj-5f0c2a3e-sbx.app.clientclub.net"
            },
            "properties": {
              "status": {
                "type": "string",
                "enum": [
                  "ready",
                  "provisioning",
                  "failed",
                  "no_history",
                  "unsupported"
                ],
                "description": "Whether the sandbox can be edited now.",
                "example": "ready"
              },
              "devUrl": {
                "type": "string",
                "format": "uri",
                "description": "The sandbox's live preview, when ready.",
                "example": "https://prj-5f0c2a3e-sbx.app.clientclub.net"
              },
              "failure": {
                "type": "object",
                "description": "Why the sandbox did not open, when `failed`.",
                "example": {
                  "code": "SANDBOX_WAKE_FAILED",
                  "message": "Unable to start the preview workload.",
                  "retryable": true
                },
                "properties": {
                  "code": {
                    "type": "string",
                    "description": "The failure, as a code.",
                    "example": "SANDBOX_WAKE_FAILED"
                  },
                  "message": {
                    "type": "string",
                    "description": "The failure, in words.",
                    "example": "Unable to start the preview workload."
                  },
                  "retryable": {
                    "type": "boolean",
                    "description": "Whether calling again can succeed.",
                    "example": true
                  }
                }
              }
            }
          }
        },
        "title": "CliProjectContext"
      }
    }
  }
}
```

## Code Examples

**cURL**

```bash
curl -L -X GET 'https://services.leadconnectorhq.com/ai-builder-api/cli/projects/<projectId>/context' \
  -H 'Authorization: Bearer <TOKEN>' \
  -H 'Version: v3'
```

**Node.js**

```javascript
const options = {
  method: 'GET',
  headers: {
    Authorization: 'Bearer <TOKEN>',
    Version: 'v3'
  }
};

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

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

response = requests.get(url, 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>/context',
  CURLOPT_RETURNTRANSFER => true,
  CURLOPT_CUSTOMREQUEST => 'GET',
  CURLOPT_HTTPHEADER => [
    'Authorization: Bearer <TOKEN>',
    'Version: v3',
  ],
]);

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

**Java**

```java
HttpResponse<String> response = Unirest
  .get("https://services.leadconnectorhq.com/ai-builder-api/cli/projects/<projectId>/context")
  .header("Authorization", "Bearer <TOKEN>")
  .header("Version", "v3")
  .asString();
```

**Go**

```go
package main

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

func main() {
  url := "https://services.leadconnectorhq.com/ai-builder-api/cli/projects/<projectId>/context"
  req, _ := http.NewRequest("GET", url, nil)
  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>/context")

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

request = Net::HTTP::Get.new(url)
request["Authorization"] = "Bearer <TOKEN>"
request["Version"] = "v3"

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

**PowerShell**

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

$response = Invoke-RestMethod -Uri 'https://services.leadconnectorhq.com/ai-builder-api/cli/projects/<projectId>/context' -Method 'GET' -Headers $headers
$response | ConvertTo-Json
```
