# Code Analysis

<table data-full-width="true"><thead><tr><th width="460">API</th><th>Description</th></tr></thead><tbody><tr><td><strong>POST /api/fetchCodeAnalysisApiInfos</strong></td><td>Fetch code-analysis API info for a given traffic collection, returning matched endpoints discovered from source code.</td></tr><tr><td><strong>POST /api/fetchCodeAnalysisRepos</strong></td><td>Fetch all registered source-code repositories, optionally filtered by source-code type.</td></tr><tr><td><strong>POST /api/getSourceCodeCollectionsForDirectories</strong></td><td>Return all code analysis collections that have at least one endpoint under a given backend directory path prefix.</td></tr><tr><td><strong>POST /api/getApisForChosenCollectionForSourceCode</strong></td><td>Fetch request/response schema information for all API endpoints in the specified code analysis collections.</td></tr><tr><td><strong>POST /api/addCodeAnalysisRepo</strong></td><td>Add one or more source-code repositories for code-analysis scanning (upsert — re-adding an existing repo is a no-op).</td></tr><tr><td><strong>POST /api/runCodeAnalysisRepo</strong></td><td>Trigger an immediate scan for one or more registered repositories by setting their schedule time to now.</td></tr><tr><td><strong>POST /api/deleteCodeAnalysisRepo</strong></td><td>Delete a source-code repository registration, removing all documents matching the given project and repo name.</td></tr></tbody></table>

## POST /api/fetchCodeAnalysisApiInfos

> POST request for endpoint /api/fetchCodeAnalysisApiInfos

```json
{"openapi":"3.0.1","info":{"title":"AktoSwagger","version":"1.0.0"},"paths":{"/api/fetchCodeAnalysisApiInfos":{"post":{"summary":"POST request for endpoint /api/fetchCodeAnalysisApiInfos","operationId":"/api/fetchCodeAnalysisApiInfos-POST","requestBody":{"content":{"application/json":{"schema":{"type":"object","properties":{"apiCollectionId":{"type":"integer"}}}}}},"responses":{"200":{"description":"Code analysis API info retrieved successfully","content":{"application/json":{"schema":{"type":"object","properties":{"codeAnalysisCollectionInfo":{"type":"object","properties":{"codeAnalysisCollection":{"type":"object","nullable":true,"description":"Null when no source-code scan has been linked to this collection","properties":{"_id":{"type":"string"},"name":{"type":"string"},"projectDir":{"type":"string"},"apiCollectionId":{"type":"integer"}}},"codeAnalysisApisMap":{"type":"object","description":"Map keyed by 'METHOD /endpoint'. Each value is a CodeAnalysisApiInfo document.","additionalProperties":{"type":"object","properties":{"_id":{"type":"object","properties":{"codeAnalysisCollectionId":{"type":"string"},"method":{"type":"string"},"endpoint":{"type":"string"}}},"location":{"type":"object","properties":{"filePath":{"type":"string"},"fileName":{"type":"string"},"fileLink":{"type":"string"},"lineNo":{"type":"integer"}}},"discoveredTs":{"type":"integer","description":"Unix epoch seconds when the endpoint was first discovered in source code"},"lastSeenTs":{"type":"integer","description":"Unix epoch seconds of the most recent scan that found this endpoint"}}}}}}}}}}}}}}}}
```

## POST /api/fetchCodeAnalysisRepos

> POST request for endpoint /api/fetchCodeAnalysisRepos

```json
{"openapi":"3.0.1","info":{"title":"AktoSwagger","version":"1.0.0"},"paths":{"/api/fetchCodeAnalysisRepos":{"post":{"summary":"POST request for endpoint /api/fetchCodeAnalysisRepos","operationId":"/api/fetchCodeAnalysisRepos-POST","requestBody":{"content":{"application/json":{"schema":{"type":"object","properties":{"sourceCodeType":{"type":"string","enum":["GITHUB","BITBUCKET"],"description":"Filter by SCM provider. Omit or set to BITBUCKET to also match legacy repos without a type field."}}}}}},"responses":{"200":{"description":"Repositories fetched successfully","content":{"application/json":{"schema":{"type":"object","properties":{"codeAnalysisRepos":{"type":"array","items":{"type":"object","properties":{"id":{"type":"object","description":"MongoDB ObjectId of the repo document"},"hexId":{"type":"string","description":"Hex-string representation of the ObjectId"},"projectName":{"type":"string"},"repoName":{"type":"string"},"sourceCodeType":{"type":"string","enum":["GITHUB","BITBUCKET"]},"lastRun":{"type":"integer","description":"Unix epoch seconds of the last completed scan. 0 if never run."},"scheduleTime":{"type":"integer","description":"Unix epoch seconds when the next scan is scheduled"}}}}}}}}}}}}}}
```

## POST /api/getSourceCodeCollectionsForDirectories

> POST request for endpoint /api/getSourceCodeCollectionsForDirectories

```json
{"openapi":"3.0.1","info":{"title":"AktoSwagger","version":"1.0.0"},"paths":{"/api/getSourceCodeCollectionsForDirectories":{"post":{"summary":"POST request for endpoint /api/getSourceCodeCollectionsForDirectories","operationId":"/api/getSourceCodeCollectionsForDirectories-POST","requestBody":{"content":{"application/json":{"schema":{"type":"object","required":["chosenBackendDirectory"],"properties":{"chosenBackendDirectory":{"type":"string","description":"Directory path prefix used as a regex anchor (^prefix.*) to filter CodeAnalysisApiInfo by location.filePath"}}}}}},"responses":{"200":{"description":"Matching collections retrieved successfully","content":{"application/json":{"schema":{"type":"object","properties":{"codeAnalysisCollectionIdList":{"type":"array","items":{"type":"object","properties":{"id":{"type":"string","description":"Hex ObjectId of the CodeAnalysisCollection"},"name":{"type":"string","description":"Collection name (matches the corresponding API collection name)"},"count":{"type":"integer","description":"Number of endpoints whose file path matches the given directory prefix"},"apiCollectionId":{"type":"integer","description":"ID of the linked traffic API collection"}}}}}}}}}}}}}}
```

## POST /api/getApisForChosenCollectionForSourceCode

> POST request for endpoint /api/getApisForChosenCollectionForSourceCode

```json
{"openapi":"3.0.1","info":{"title":"AktoSwagger","version":"1.0.0"},"paths":{"/api/getApisForChosenCollectionForSourceCode":{"post":{"summary":"POST request for endpoint /api/getApisForChosenCollectionForSourceCode","operationId":"/api/getApisForChosenCollectionForSourceCode-POST","requestBody":{"content":{"application/json":{"schema":{"type":"object","required":["chosenCodeAnalysisCollectionIds"],"properties":{"chosenCodeAnalysisCollectionIds":{"type":"array","description":"Hex ObjectId strings of CodeAnalysisCollections to load. Pass an empty array to return an empty result.","items":{"type":"string"}}}}}}},"responses":{"200":{"description":"API endpoints with schemas retrieved successfully","content":{"application/json":{"schema":{"type":"object","properties":{"apiInfoKeysWithSchema":{"type":"array","items":{"type":"object","properties":{"apiCollectionId":{"type":"integer","description":"ID of the linked traffic API collection"},"url":{"type":"string","description":"Endpoint URL path, possibly containing Akto template tokens for parameterised segments"},"method":{"type":"string"},"requestSchema":{"type":"object","description":"Inferred JSON schema for the request body. May be empty if no request body detected."},"responseSchema":{"type":"object","description":"Inferred JSON schema for the response body. May be empty if not yet analysed."}}}}}}}}}}}}}}
```

## POST /api/addCodeAnalysisRepo

> POST request for endpoint /api/addCodeAnalysisRepo

```json
{"openapi":"3.0.1","info":{"title":"AktoSwagger","version":"1.0.0"},"paths":{"/api/addCodeAnalysisRepo":{"post":{"summary":"POST request for endpoint /api/addCodeAnalysisRepo","operationId":"/api/addCodeAnalysisRepo-POST","requestBody":{"content":{"application/json":{"schema":{"type":"object","required":["codeAnalysisRepos"],"properties":{"codeAnalysisRepos":{"type":"array","description":"List of repositories to register. Must not be empty.","items":{"type":"object","required":["projectName","repoName","sourceCodeType"],"properties":{"projectName":{"type":"string"},"repoName":{"type":"string"},"sourceCodeType":{"type":"string","enum":["GITHUB","BITBUCKET"]}}}}}}}}},"responses":{"200":{"description":"Repositories added (or already existed) successfully","content":{"application/json":{"schema":{"type":"object"}}}},"400":{"description":"Validation error — codeAnalysisRepos list was null or empty","content":{"application/json":{"schema":{"type":"object","properties":{"actionErrors":{"type":"array","items":{"type":"string"}}}}}}}}}}}}
```

## POST /api/runCodeAnalysisRepo

> POST request for endpoint /api/runCodeAnalysisRepo

```json
{"openapi":"3.0.1","info":{"title":"AktoSwagger","version":"1.0.0"},"paths":{"/api/runCodeAnalysisRepo":{"post":{"summary":"POST request for endpoint /api/runCodeAnalysisRepo","operationId":"/api/runCodeAnalysisRepo-POST","requestBody":{"content":{"application/json":{"schema":{"type":"object","required":["codeAnalysisRepos"],"properties":{"codeAnalysisRepos":{"type":"array","description":"List of repos to trigger. Only repoName and projectName are required; other fields are ignored.","items":{"type":"object","required":["repoName","projectName"],"properties":{"repoName":{"type":"string"},"projectName":{"type":"string"}}}}}}}}},"responses":{"200":{"description":"Scan triggered successfully — scheduleTime updated to current timestamp","content":{"application/json":{"schema":{"type":"object"}}}},"400":{"description":"Validation error — codeAnalysisRepos list was null or empty","content":{"application/json":{"schema":{"type":"object","properties":{"actionErrors":{"type":"array","items":{"type":"string"}}}}}}}}}}}}
```

## POST /api/deleteCodeAnalysisRepo

> POST request for endpoint /api/deleteCodeAnalysisRepo

```json
{"openapi":"3.0.1","info":{"title":"AktoSwagger","version":"1.0.0"},"paths":{"/api/deleteCodeAnalysisRepo":{"post":{"summary":"POST request for endpoint /api/deleteCodeAnalysisRepo","operationId":"/api/deleteCodeAnalysisRepo-POST","requestBody":{"content":{"application/json":{"schema":{"type":"object","required":["codeAnalysisRepo"],"properties":{"codeAnalysisRepo":{"type":"object","required":["repoName","projectName"],"properties":{"repoName":{"type":"string"},"projectName":{"type":"string"}}}}}}}},"responses":{"200":{"description":"Repository deleted successfully","content":{"application/json":{"schema":{"type":"object"}}}},"400":{"description":"Validation error — codeAnalysisRepo was null","content":{"application/json":{"schema":{"type":"object","properties":{"actionErrors":{"type":"array","items":{"type":"string"}}}}}}}}}}}}
```


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.akto.io/api-reference/code-analysis.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
