# ApiProvider

**Kind:** Class

**Source:** [`atloria-monorepo/apps/cli/src/providers/api.provider.ts`](https://github.com/sherkety/atloria/blob/main/atloria-monorepo/apps/cli/src/providers/api.provider.ts#L54)

API data provider
Fetches from Atloria REST API

**Implements:** `DataProvider`

## Methods

| Method | Signature | Returns |
|---|---|---|
| `initialize` | `initialize(config: DataProviderConfig)` | `Promise<void>` |
| `getProjectMetadata` | `getProjectMetadata()` | `Promise<ProjectMetadata>` |
| `getEntities` | `getEntities()` | `Promise<Entity[]>` |
| `getEntitiesByType` | `getEntitiesByType(type: string)` | `Promise<Entity[]>` |
| `getEntityById` | `getEntityById(id: string)` | `Promise<Entity | null>` |
| `getRelationships` | `getRelationships()` | `Promise<Relationship[]>` |
| `getRelationshipsForEntity` | `getRelationshipsForEntity(entityId: string)` | `Promise<Relationship[]>` |
| `saveParseResults` | `saveParseResults(results: ParseResult[], project: DetectedProject, workflowSignals: WorkflowSignals, workflowOptions: {
      enableAiWorkflows?: boolean;
      aiModel?: string;
      forceWorkflowDiscovery?: boolean;
    }, businessContextText: string)` | `Promise<void>` |
| `saveDocumentation` | `saveDocumentation(pages: Array<{
      slug: string;
      title: string;
      description: string;
      type: string;
      content: string;
      order: number;
      parentSlug?: string;
      entityId?: string;
    }>, _navigation: Array<{
      title: string;
      href: string;
      children?: Array<{ title: string; href: string }>;
    }>)` | `Promise<void>` |
| `destroy` | `destroy()` | `Promise<void>` |

## Where it refuses work

- `ApiProvider` stops the work with `Error` when `!response.ok`, in 2 places.
- `ApiProvider` stops the work with `Error` when `!config.apiUrl` — “API URL is required for dynamic mode”.
- `ApiProvider` stops the work with `Error` when `!config.projectId` — “Project ID is required for dynamic mode”.
- `ApiProvider` stops the work with an early return when `this.entitiesCache`.
- `ApiProvider` stops the work with an early return when `this.relationshipsCache`.

## When something fails

- `ApiProvider` handles failure in 1 place: it turns it into a return value in all 1.
