Skip to content

Get repository directory tree

GET /api/v5/repos/{owner}/{repo}/git/trees/{sha}

This endpoint retrieves the directory file tree of the specified repository. You can locate the version by branch name, commit, or directory tree SHA. It supports recursively retrieving subdirectories and viewing directory entries with pagination.

Access token support

  • AtomGit user access tokens (AtomGit user access tokens)

Anonymous access

This endpoint allows anonymous access.

Request parameters

Parameter Location Type Required Description
owner path string Yes Namespace address the repository belongs to (organization or personal path)
repo path string Yes Repository path (path)
sha path string Yes Can be a branch name (e.g. master), a commit, or the SHA of a directory tree
page query integer No Current page number
per_page query integer No Number of items per page; maximum 100, default 20
recursive query integer No Recursively retrieves directories when set to 1
file_path query string No File tree path

Response parameters

Field Type Always returned Nullable Description
tree object[] Yes No Directory tree entry list

tree object

Field Type Always returned Nullable Description
tree.sha string Yes No SHA of the directory tree or file object
tree.name string Yes No File or directory name
tree.type string Yes No Object type (tree for a directory, blob for a file)
tree.path string Yes No File or directory path
tree.mode string Yes No File mode (e.g. 040000 for a directory, 100644 for a regular file)
tree.md5 string Yes No MD5 checksum of the file content

Error responses

This endpoint may return the following common error status codes. The field names in the error response body are subject to the actual backend response.

400 Invalid parameters

{
  "message": "Invalid parameters"
}

401 Unauthenticated

{
  "message": "Missing or invalid access token"
}

404 Resource not found

{
  "message": "The repository or directory tree does not exist"
}

HTTP response status codes

Status code Description
200 Success (OK)
304 Not modified
400 Invalid parameters (Bad request)
401 Authentication required (Requires authentication)
404 Resource not found (Not found)
429 Too many requests; rate limit triggered (Too many requests)
500 Internal system error (Internal server error)

Request example

Parameter notes

  • This endpoint allows anonymous access, so the examples do not include authentication information. To access a private repository, you can include an AtomGit user access token.
  • Replace <owner> with the namespace address the repository belongs to (organization or personal path);
  • Replace <repo> with the repository path (path);
  • Replace <sha> with a branch name, a commit, or the SHA of a directory tree.

cURL

curl -X GET 'https://api.atomgit.com/api/v5/repos/<owner>/<repo>/git/trees/<sha>' \
  -H 'Accept: application/json'

To retrieve directories recursively, append the query parameter recursive=1:

curl -X GET 'https://api.atomgit.com/api/v5/repos/<owner>/<repo>/git/trees/<sha>?recursive=1' \
  -H 'Accept: application/json'

JavaScript

// Native fetch (Node.js 18+ / browser)
const response = await fetch(
  "https://api.atomgit.com/api/v5/repos/<owner>/<repo>/git/trees/<sha>",
  {
    headers: {
      "Accept": "application/json",
    },
  },
);

if (!response.ok) {
  throw new Error(`Request failed: ${response.status}`);
}

const data = await response.json();
console.log(data);

Python

import requests

resp = requests.get(
    "https://api.atomgit.com/api/v5/repos/<owner>/<repo>/git/trees/<sha>",
    headers={"Accept": "application/json"},
    timeout=10,
)
resp.raise_for_status()

print(resp.json())

Response example

Status code: 200

{
  "tree": [
    {
      "sha": "5259c4b24f015ffdc3663e81837a730c2a108e1f",
      "name": "b",
      "type": "tree",
      "path": "a/b",
      "mode": "040000",
      "md5": "a7e86136543b019d72468ceebf71fb8e"
    }
  ]
}

Error codes

Error code Description
400 Invalid parameters or the request cannot be parsed
401 Unauthenticated or invalid credentials (missing/invalid access credentials)
404 The requested resource does not exist
429 Too many requests; rate limit triggered
500 Internal system error

Markdown source: View on AtomGit·Content from the open-source project gitcode-dev/atomgit-api-doc