Keep your Git repositories in perfect harmony with your organization's workspace. This guide walks you through programmatically connecting your Git provider, synchronizing your repositories, and accessing file contents using our API.
Whether you are building a custom dashboard or automating your CI/CD pipelines, our Git Provider API endpoints give you full control over your repository integrations.
To use these endpoints, you will need your organization_id and a valid API Bearer token. Replace {organization_id} and $API_TOKEN in the examples below with your actual credentials.
How the synchronization flow works
Before diving into the code, here is a quick look at the lifecycle of a Git integration, from initial authorization to fetching file contents.
sequenceDiagram
participant Client as Your App
participant API as Our API
participant Git as Git Provider
Client->>API: GET /install-url
API-->>Client: Returns OAuth URL
Client->>Git: User authorizes access
Git-->>API: POST /callback (Background)
Client->>API: POST /repositories/sync
API->>Git: Fetch repository metadata
API-->>Client: Sync Complete
Client->>API: GET /repositories/{id}/content
API-->>Client: Returns file dataStep-by-Step Guide
Follow these steps to establish a connection and start syncing your code.
- 1
Connect your Git provider
First, you need to generate an installation URL. Redirect your users to this URL so they can authorize your application to access their Git provider (like GitHub or GitLab).
curl -X GET "https://api.gitdocai.com/v1/organizations/{organization_id}/git-provider/install-url" -H "Authorization: Bearer $API_TOKEN"Once the user approves the request, the Git provider will automatically hit our OAuth callback endpoint (
POST /v1/organizations/{organization_id}/git-provider/callback) to finalize the installation. - 2
Trigger a repository synchronization
After the installation is complete, you can tell the API to pull in the latest repository data. This endpoint synchronizes the list of repositories available to your organization.
curl -X POST "https://api.gitdocai.com/v1/organizations/{organization_id}/git-provider/repositories/sync" -H "Authorization: Bearer $API_TOKEN"You don't need to sync before every request. We recommend triggering a sync only when a user explicitly requests a refresh or when setting up the integration for the first time.
- 3
List available repositories
To see the repositories you just synchronized, fetch the list of available repositories. This will return the IDs you need for fetching specific files or trees.
curl -X GET "https://api.gitdocai.com/v1/organizations/{organization_id}/git-provider/repositories" -H "Authorization: Bearer $API_TOKEN" - 4
Access repository files and trees
Once you have a
repository_id, you can explore its contents. You can either fetch the entire file structure (the "tree") or grab the contents of a specific file.To get the file tree:
curl -X GET "https://api.gitdocai.com/v1/organizations/{organization_id}/git-provider/repositories/{repository_id}/tree" -H "Authorization: Bearer $API_TOKEN"To get specific file content:
curl -X GET "https://api.gitdocai.com/v1/organizations/{organization_id}/git-provider/repositories/{repository_id}/content" -H "Authorization: Bearer $API_TOKEN"
Managing Installations
Sometimes you need to audit or remove Git provider connections. You can manage active installations using the following endpoints:
| Action | HTTP Method | Endpoint | Description |
|---|---|---|---|
| List | GET | /git-provider/installations | View all active Git provider connections for the organization. |
| Retrieve | GET | /git-provider/installations/{installation_id} | Get details about a specific installation. |
| Remove | DELETE | /git-provider/installations/{installation_id} | Disconnect the Git provider. |
Deleting an installation immediately revokes access to the associated repositories. Any automated workflows relying on this connection will fail until a new installation is authorized.
Frequently Asked Questions
Do I need to handle the OAuth callback manually?
No. Our system automatically handles the POST /git-provider/callback route. You only need to generate the install URL and direct the user to it.
How do I get details for a single repository?
If you already know the repository ID and just need its metadata (rather than listing all repositories), you can use the GET /v1/organizations/{organization_id}/git-provider/repositories/{repository_id} endpoint.