Project API
Complete API reference for managing projects — checking linked repositories, linking repos with auto-webhook configuration, listing and creating projects with org scoping, and deleting projects.
Project API
Manage project links between CodeSpar agents and GitHub repositories. When a repository is linked, CodeSpar automatically configures webhooks (if WEBHOOK_BASE_URL is set) to receive push, pull request, and workflow events.
Endpoints Overview
| Method | Path | Description |
|---|---|---|
GET | /api/project?agentId=<id> | Check if an agent has a linked project |
POST | /api/project/link | Link a repository to an agent |
GET | /api/projects | List all projects (scoped by org) |
POST | /api/projects | Create a new project with agent |
DELETE | /api/projects/:id | Delete a project and its agent |
Check Linked Project
Check which repository is linked to a specific agent.
Query Parameters
| Parameter | Type | Required | Description |
|---|---|---|---|
agentId | string | Yes | The agent identifier to check |
Request
Response (linked)
Response (not linked)
ProjectConfig Type
Link a Repository
Link a GitHub repository to an agent. If WEBHOOK_BASE_URL is set and GITHUB_TOKEN has admin permissions, a webhook is automatically created on the repository.
Request Body
| Field | Type | Required | Description |
|---|---|---|---|
agentId | string | Yes | Agent to link the repo to |
repo | string | Yes | GitHub repo in owner/name format, or a full GitHub URL |
Request
Using a full URL:
Response
What Happens During Linking
- CodeSpar validates the repository exists and
GITHUB_TOKENhas access - The repo's default branch is detected
- A project configuration record is created
- If
WEBHOOK_BASE_URLis set and the token hasadmin:repo_hookscope, a GitHub webhook is auto-configured to sendpush,pull_request,workflow_run, andcheck_runevents to{WEBHOOK_BASE_URL}/webhooks/github - The agent is associated with the project
Error Responses
Repository not found or no access (404):
Already linked (409):
Missing GitHub token (400):
List All Projects
Retrieve all projects. When the x-org-id header is provided, results are scoped to that organization.
Headers
| Header | Required | Description |
|---|---|---|
x-org-id | No | Organization ID to scope results. Without this header, all projects across all orgs are returned. |
Request
Response
ProjectListEntry Type
Create Project
Create a new project with an associated agent. If WEBHOOK_BASE_URL and GITHUB_TOKEN are configured, the webhook is automatically set up.
Headers
| Header | Required | Description |
|---|---|---|
x-org-id | No | Organization to create the project in |
Request Body
| Field | Type | Required | Description |
|---|---|---|---|
repo | string | Yes | GitHub repo in owner/name format |
name | string | No | Display name for the project. If omitted, derived from the repo name. |
Request
Minimal request (name auto-derived from repo):
Response
What Happens During Creation
- CodeSpar validates the repository exists and is accessible
- A new Project Agent is spawned for the project
- A project record is created (scoped to the org if
x-org-idis provided) - If
WEBHOOK_BASE_URLis set, a webhook is auto-configured on the GitHub repository - The agent starts monitoring the repository based on its autonomy level
Delete Project
Remove a project, its associated agent, and the GitHub webhook (if one was configured).
Path Parameters
| Parameter | Type | Description |
|---|---|---|
id | string | Project ID to delete |
Headers
| Header | Required | Description |
|---|---|---|
x-org-id | No | Organization scope (ensures you can only delete projects in your org) |
Request
With organization scoping:
Response
What Happens During Deletion
- The associated Project Agent is terminated (and any ephemeral agents it spawned)
- The GitHub webhook is removed from the repository (if it was auto-configured)
- The project record is deleted from storage
- An audit log entry is created for the deletion
Error Response
Next Steps
- Agent API — Manage agent lifecycle
- Webhook API — GitHub webhook processing
- Channel API — Manage messaging channels
- Link a Repository Guide — Step-by-step guide