# API communication

The API routes start with `/api/v1`. Send your key in the `Authorization: Bearer <key>` header. **AI Connect** provides a command to save the key in the `CAMPAIGN52_APIKEY` user environment variable on Windows and Markdown instructions to paste into your AI. Use an account key for a project. For a variant, you can also choose a key dedicated to that variant.

A key is linked to the personal space or company displayed at the time of its creation. The key context applies to all its calls, including the creation of a project. Permissions indicate `scopeEnterpriseId` for a business key. The licensee must retain access to this space to use the key.

## Check fees

`GET /api/v1/permissions` returns the actions of the current key. Optional parameter `projectVariantId` evaluates the rights in a specific variant. For a variant key, its variant is used by default. Specify `projectId` to verify the rights to modify or delete the project and create a variant in it.

`enabled` indicates the saved box. `effective` takes into account the scope, role and access of the incumbent to the variant or project requested. `null` indicates that the action requires a variant or project identifier. A provider can also be disabled in administration.

## Projects and variants

A project groups a work initiative and its shared instructions. A variant belongs to a project and represents a deliverable with its own files, folders, favorites, instructions, and settings. For example, **Product presentation** can contain **French version** and **English version**. The language of each variant is optional.

| Method | Road | Operation |
| --- | --- | --- |
| GET | `/api/v1/projects` | List accessible projects |
| GET | `/api/v1/projects/{projectId}` | Read a project |
| POST | `/api/v1/projects` | Create a project |
| PUT, DELETE | `/api/v1/projects/{projectId}` | Edit or remove an empty project |
| GET | `/api/v1/projects/{projectId}/variants` | List accessible variants |
| POST | `/api/v1/projects/{projectId}/variants` | Create a variant in the project |
| GET, PUT, DELETE | `/api/v1/project-variants/{projectVariantId}` | Read, edit or delete a variant |
| GET | `/api/v1/projects/{projectId}/files` | List accessible files in project |

Creation and modification await `name` and `description`. Variants also accept `projectVariantTypeId` and `statusId`. Status is chosen from the authorized list for the type.

Project responses include the `isArchived` and `isClosed` booleans. Set them independently when creating or updating a project. Omit a field during an update to keep its current value. The API list includes all states by default. Use `includeArchived=false` or `includeClosed=false` to exclude the corresponding state.

The optional `languageISO2` field accepts a two-letter code from the language directory, such as `FR`. On update, omit the field to keep the current language or send `null` to clear it.

When creating a variant, the API copies the template folder structure if the project category defines a variant template and the key holder can access it. The API copies the template description and language when those fields are omitted. It also copies the type and status when both values are omitted or null. Files and permissions remain with the source variant.

The optional `aiInstruction` field accepts up to 8,000 characters of multiline instructions when creating or updating a project or variant. On update, omit it to keep the current value, or send `null` or an empty string to clear it. When creating a variant, omitting it uses the variant template’s value if a template is configured.

Details returned by the API contain `aiInstruction` and, where applicable, `projectAIInstruction` and `categoryAIInstruction`.

## Teams, categories and collaboration

Manage teams with `GET/POST /api/v1/teams`, `GET/PUT/DELETE /api/v1/teams/{id}`, and `PUT/DELETE /api/v1/teams/{id}/members/{userId}`. Team permissions require access to company administration.

Manage categories with `GET/POST /api/v1/project-categories` and `GET/PUT/DELETE /api/v1/project-categories/{id}`. The body accepts `name`, `description`, `aiInstruction`, and `templateProjectVariantId`. Find template variants at `/api/v1/project-categories/templates` and choices for a project at `/api/v1/project-category-options`.

Set `projectCategoryId` and `isTemplate` in the project body. Omit either field to preserve its value, or set `projectCategoryId` to `null` to clear it. Use `GET /api/v1/languages` for language codes.

Under `/api/v1/projects/{projectId}`, use `/discussion` for chat and corrections, `/discussion/messages` to post, `/tasks` for tasks, `/outputs` for deliverables, `/favorite` to update the personal favorite, and `/access` to manage sharing. These actions also require `ReadProject` and access to the specific project. `GET /api/v1/permissions?projectId={projectId}` evaluates the key’s access.

## Variant files

Use prefix `/api/v1/project-variants/{projectVariantId}/files`.

| Method | Suffix | Operation |
| --- | --- | --- |
| GET | none | List files, with favorites first |
| POST | none | Upload File |
| POST | `/attach` | Attach a storage file with an authorized account key, via `storedFileId` |
| GET, PUT | `/{fileId}` | Read or update `name` and `description` |
| GET, PUT | `/{fileId}/content` | Download or replace content |
| DELETE | `/{fileId}` | Remove attachment from variant |
| PUT, DELETE | `/{fileId}/favorite` | Save or Remove Favorite |

To read the favourite files, add `?favorites=true` to a list of variant or project files. The paginated lists accept `page` and `search`. The upload and replacement await a field `file` in `multipart/form-data` of maximum 512 Mio. The replacement retains the identifier, metadata and the favorite of the connection. The removal of a variant keeps the original file in storage.

Add the optional multipart field `isOutput=true` when uploading or replacing a deliverable to show it under **Output files** on the project page. Omitting the field on replacement keeps the existing setting.

```bash
curl -H "Authorization: Bearer $GATEWAY_KEY" \
     -F "file=@sortie.mp4" \
     "$BASE_URL/api/v1/project-variants/$PROJECT_VARIANT_ID/files"
```

To define a favourite, see `GET /api/v1/project-variant-types`. The answer contains the types, the ordered statutes and their descriptions, including `descriptionAI`. Send a JSON containing `projectVariantTypeId`, possibly `statusId` and `comment`. Both follow-up sheets highlight the favorites.

## Variant Arborescence

The prefix is `/api/v1/project-variants/{projectVariantId}`.

| Method | Suffix | Operation |
| --- | --- | --- |
| GET | `/entries` | Browse the folder, with `parentId` optional |
| POST | `/directories` | Create a file with `name`, `description` and `parentId` |
| PUT | `/directories/{id}` | Change the name and description of a folder |
| DELETE | `/directories/{id}` | Remove a folder, with `recursive=true` to also remove its contents |
| PUT | `/entries/{id}/parent` | Move a file or folder with `parentId` |

A destination `parentId: null` is the virtual root of the variant. To upload or attach a file to a folder, also provide `parentId` on Route `/files` or `/files/attach`. Historical file lists continue to include files from all folders. Explorer's search `search` covers the variant. Filter with `kind=1` for files and `kind=2` for folders. Sorts accept `name`, `name-desc`, `size` and `date`.

Table `ProjectVariantEntry` stores the elements. View SQL `ProjectVariantEntryTree` shows their path, depth and the identifiers of the path records.

## Levels of access

The highest access level granted by the groups applies. A `User` can browse and download. A `Manager` can manage files and favourites. An `Admin` can also manage the variant and its permissions. Site administrators create projects and variants with an account key that has the relevant actions enabled. A key created by **AI Connect** is restricted to its variant and can have at most the `Manager` level.

Codes `401`, `403` and `404` indicate, respectively, an invalid key, an unauthorized action or a resource that is inaccessible within the current perimeter.

Operations are recorded in the call log under **API of the site**, with the holder, the recognized key, the result HTTP and the duration.
