---
title: "Search repository code"
method: POST
path: "/api/v2/code/search"
tags: ["Code"]
---

# Search repository code

`POST /api/v2/code/search`

## Request

- Base URL: `https://zeropath.com`
- URL: `https://zeropath.com/api/v2/code/search`
- Auth: API key in header `X-ZeroPath-API-Token-Id` and API key in header `X-ZeroPath-API-Token-Secret`

Search for text patterns in a repository's source code using the underlying provider's code search API (GitHub or GitLab). Returns matching file paths, line numbers, and preview snippets. Supports GitHub and GitLab repositories only (Bitbucket is not supported). Note: the `ref` parameter is supported only for GitLab -- GitHub always searches the default branch. Use `pathPrefix` to narrow results to a specific directory.

## Request body

- CodeSearchRequest
  - `organizationId` string: Organization that owns the repository.
  - `repositoryId` string, required: Repository to search within.
  - `query` string, required: Text search query to match against file contents. This is a literal text search (not regex) performed via the repository provider's code search API (GitHub or GitLab).
  - `ref` string: Branch, tag, or commit ref to search. Only supported for GitLab repositories; the request will be rejected if provided for a GitHub repository. Omit to search the default branch.
  - `pathPrefix` string: Restrict search results to files under this directory path prefix (e.g. "src/services/"). Useful for narrowing results in large repositories.
  - `limit` integer: Maximum number of search results to return. Defaults to 10.

## Response `200`

Search results

- CodeSearchResponse
  - `provider` 'github' | 'gitlab', required: Repository provider that served the request. Only providers with native code-inspection APIs are supported.
  - `repositoryId` string, required
  - `query` string, required
  - `ref` string, nullable, required: Effective ref searched. Null when provider does not support explicit ref search.
  - `pathPrefix` string, nullable, required
  - `hasNextPage` boolean, required: True when the provider indicates an additional search page is available.
  - `totalMatches` integer, nullable, required
  - `items` CodeSearchResultItem[], required
    - `path` string, required
    - `line` integer, nullable, required
    - `preview` string, nullable, required
    - `url` string, nullable, required

## Other responses

- `400`: Error Response
- `401`: Error Response
- `403`: Error Response
- `404`: Error Response

---

[API](https://skmtc.dev/zeropath/apis/zeropath-api.md) - [All operations](https://skmtc.dev/zeropath/apis/zeropath-api/llms.txt) - [OpenAPI document](https://skmtc.dev/zeropath/apis/zeropath-api/revisions/126e9c80ba0d?raw)
