Git & Repository Integrations Retrieving File Trees via API

Learn how to programmatically access and navigate your connected Git repositories. By using the GitDocAI API, you can retrieve complete file trees, explore folder structures, and fetch specific file contents to integrate repository data directly into your own applications or workflows.

flowchart LR
    A["Organization"] --> B["Git Installation"]
    B --> C["Repository"]
    C --> D["File Tree"]
    D --> E["File Content"]

Prerequisites

Before you can retrieve a file tree, ensure you have:

  • An active organization_id.

  • A connected Git provider (such as GitHub or GitLab) installed in your organization.

  • An API key with permissions to read repository data.

If you haven't connected a Git provider yet, you will need to generate an installation URL using the GET /v1/organizations/{organization_id}/git-provider/install-url endpoint and complete the OAuth callback process first.

Fetching a file tree

Follow these steps to retrieve the structure of your repository.

  1. 1

    Find your Repository ID

    To get a file tree, you first need the specific repository_id. You can retrieve a list of all repositories connected to your Git provider installation.

    curl -X GET "https://api.gitdocai.com/v1/organizations/{organization_id}/git-provider/repositories" 
      -H "Authorization: Bearer YOUR_API_KEY"

    Locate the id of the repository you want to inspect in the response.

  2. 2

    Request the File Tree

    Use the repository ID to fetch the complete file and folder structure. This endpoint returns a hierarchical view of your repository's contents.

    curl -X GET "https://api.gitdocai.com/v1/organizations/{organization_id}/git-provider/repositories/{repository_id}/tree" 
      -H "Authorization: Bearer YOUR_API_KEY"
  3. 3

    Fetch specific file content (Optional)

    Once you have the file tree, you might want to read the actual contents of a specific file. You can do this by passing the file path to the content endpoint.

    curl -X GET "https://api.gitdocai.com/v1/organizations/{organization_id}/git-provider/repositories/{repository_id}/content?path=README.md" 
      -H "Authorization: Bearer YOUR_API_KEY"

Cache your file trees locally when possible. Fetching large repository trees frequently can consume API rate limits and slow down your application.

Quick Reference: Repository Endpoints

Here is a summary of the API endpoints available for managing and navigating Git repositories:

ActionMethodEndpoint
Get file treeGET/v1/organizations/{org_id}/git-provider/repositories/{repo_id}/tree
Get file contentGET/v1/organizations/{org_id}/git-provider/repositories/{repo_id}/content
Get repository detailsGET/v1/organizations/{org_id}/git-provider/repositories/{repo_id}
List repositoriesGET/v1/organizations/{org_id}/git-provider/repositories
Sync repositoriesPOST/v1/organizations/{org_id}/git-provider/repositories/sync

Frequently Asked Questions

Why isn't my newly created repository showing up?

If you recently added a repository to your Git provider, GitDocAI might not know about it yet. You can force a synchronization by calling the POST /v1/organizations/{organization_id}/git-provider/repositories/sync endpoint.

How do I manage my Git provider installations?

You can list all active installations using GET /v1/organizations/{organization_id}/git-provider/installations. If you need to remove access, use the DELETE method on the specific {installation_id} endpoint.

Next Steps

Managing Git Installations

Learn how to generate installation URLs and handle OAuth callbacks to connect new Git providers.