Feature: API Clients
Relevant source files
The following files were used as context for generating this wiki page:
- api/test/project-client.e2e-spec.ts
- api/src/domain/http.ts
- webapp/src/app/projects/components/api-clients-overview/api-clients-overview.component.ts
- webapp/src/app/projects/components/api-clients-overview/api-clients-overview.component.html
- webapp/src/app/projects/components/add-api-client/add-api-client.component.html
- webapp/src/app/projects/projects.module.ts
- api/test/export.e2e-spec.ts
The API Clients feature provides a mechanism for programmatic access to a project's resources. It allows users to create credentials (a Client ID and a Secret) that can be used to authenticate with the Traduora REST API. This is essential for automating translation workflows, such as importing/exporting translation files, managing terms, and integrating with CI/CD pipelines.
Each API client is scoped to a specific project and assigned a role that dictates its permissions. This ensures that automated processes have only the necessary level of access. The feature includes both a backend API for managing and authenticating clients and a user interface within the project settings for users to create and maintain these clients.
Backend Architecture
The backend is responsible for the full lifecycle of an API client, including creation, management, authentication, and authorization for API requests.
API Endpoints
API clients are managed via a set of RESTful endpoints under a specific project. Access to these endpoints requires a user to be authenticated and have appropriate permissions on the project.
| Method | Path | Description | Required User Role |
|---|---|---|---|
GET | /api/v1/projects/:projectId/clients | Retrieves a list of all API clients for the specified project. The response does not include the client secrets. | Member |
POST | /api/v1/projects/:projectId/clients | Creates a new API client for the project. The response includes the client secret, which is only shown once. | Admin |
PATCH | /api/v1/projects/:projectId/clients/:clientId | Updates the role of an existing API client. | Admin |
DELETE | /api/v1/projects/:projectId/clients/:clientId | Deletes an API client, revoking its access permanently. | Admin |
Sources: api/test/project-client.e2e-spec.ts:43-120, api/test/project-client.e2e-spec.ts:122-153, api/test/project-client.e2e-spec.ts:186-231, api/test/project-client.e2e-spec.ts:233-243
Data Transfer Objects (DTOs)
Several DTOs are used to handle data for API client operations.
AddProjectClientRequest
Used for the body of the POST request to create a new client.
| Field | Type | Description | Validation Rules |
|---|---|---|---|
name | string | A descriptive name for the API client. | string, length(1, 255) |
role | ProjectRole | The role to assign to the client. | enum(ProjectRole) |
Sources: api/src/domain/http.ts:474-483
ProjectClientDTO
The standard representation of an API client, returned when listing clients.
| Field | Type | Description |
|---|---|---|
id | string | The unique identifier (Client ID). |
name | string | The name of the client. |
role | ProjectRole | The role assigned to the client. |
Sources: api/src/domain/http.ts:238-246
ProjectClientWithSecretDTO
A special representation returned only upon client creation, which includes the secret.
| Field | Type | Description |
|---|---|---|
id | string | The unique identifier (Client ID). |
name | string | The name of the client. |
role | ProjectRole | The role assigned to the client. |
secret | string | The client secret. This is only shown once. |
Sources: api/src/domain/http.ts:256-265
Authentication Flow
API clients authenticate using the OAuth 2.0 Client Credentials grant type. The client sends its ID and secret to the token endpoint to receive an access token.
This diagram shows the authentication sequence for an API client.
Permissions and Roles
An API client's access to resources is determined by its assigned ProjectRole. The roles are Admin, Editor, and Viewer.
- A client with the
Viewerrole can read data (e.g., get terms, translations, export files). - A client with the
Editorrole can do everything aViewercan, plus modify data (e.g., add terms, update translations). - An
Adminhas full access within the project scope.
API clients are restricted to project-specific endpoints and cannot access global endpoints like /api/v1/users/me or /api/v1/projects. They also cannot access data from projects other than the one they were created for.
Sources: api/test/project-client.e2e-spec.ts:245-290, api/test/project-client.e2e-spec.ts:292-303, api/test/project-client.e2e-spec.ts:305-316
Frontend UI
The web application provides a user-friendly interface for managing API clients within a project's settings. The UI is located at the route /:projectId/api.
Sources: webapp/src/app/projects/projects.module.ts:51-51
UI Components
ApiClientsOverviewComponent: The main container that lists all existing API clients for the project. It handles fetching the client list and dispatching actions to update or remove clients.
Sources: webapp/src/app/projects/components/api-clients-overview/api-clients-overview.component.tsAddApiClientComponent: A component, typically presented in a modal, that contains a form to create a new API client. It allows the user to specify a name and a role.
Sources: webapp/src/app/projects/components/add-api-client/add-api-client.component.htmlApiClientComponent: A component that displays a single API client's information (name, role) and provides controls for editing its role or deleting it.
Sources: webapp/src/app/projects/components/api-clients-overview/api-clients-overview.component.html:26-32
User Flow for Creating an API Client
The following diagram illustrates the user flow for creating a new API client in the web application.
After a client is created, a modal is displayed showing the Client ID and Secret. The secret is explicitly stated to be shown only once, and the user must acknowledge they have stored it safely.
Sources: webapp/src/app/projects/components/add-api-client/add-api-client.component.html:43-46
Conclusion
The API Clients feature is a cornerstone for integrating Traduora into automated development and localization workflows. By providing role-based, project-scoped programmatic access via a standard Client Credentials flow, it enables teams to build robust CI/CD pipelines for managing translations, synchronize repositories, and automate other repetitive tasks, thereby increasing efficiency and reducing manual effort.