---
title: "Get AST for source code"
method: POST
path: "/api/v2/static-analysis/static-analysis-server/get-ast"
tags: ["Security Monitoring"]
---

# Get AST for source code

`POST /api/v2/static-analysis/static-analysis-server/get-ast`

## Request

- Base URL: `https://api.datadoghq.com`
- URL: `https://api.datadoghq.com/api/v2/static-analysis/static-analysis-server/get-ast`
- Auth: one of:
  - API key in header `DD-API-KEY` and API key in header `DD-APPLICATION-KEY`
  - OAuth 2
    - Authorization code: `/oauth2/v1/authorize`
    - Token URL: `/oauth2/v1/token` scopes: `code_analysis_read`

Parse source code into an abstract syntax tree (AST) for the specified language.

## Request body

- GetAstRequest: The request payload for parsing source code into an abstract syntax tree.
  - `data` GetAstRequestData, required: The primary data object in the get-AST request.
    - `attributes` GetAstRequestDataAttributes, required: The attributes of the get-AST request, containing the source code to parse.
      - `code` string, required: The base64-encoded source code to parse into an abstract syntax tree.
      - `file_encoding` string, required: The encoding of the source code file (must be utf-8).
      - `language` string, required: The programming language of the source code to parse.
    - `id` string: An optional identifier for the get-AST request resource.
    - `type` 'get_ast_request', required: Get AST request resource type.

## Response `200`

OK

- GetAstResponse: The response payload containing the parsed abstract syntax tree.
  - `data` GetAstResponseData, required: The primary data object in the get-AST response.
    - `attributes` GetAstResponseDataAttributes, required: The attributes of the get-AST response, containing the parsed abstract syntax tree.
      - `ast` object, required: The parsed abstract syntax tree as a JSON object.
    - `id` string: The identifier of the get-AST response resource.
    - `type` 'get_ast_response', required: Get AST response resource type.

## Other responses

- `400`: Bad Request
- `401`: Unauthorized
- `429`: Too many requests

---

[API](https://skmtc.dev/datadog/apis/datadog-api-v2-collection.md) - [All operations](https://skmtc.dev/datadog/apis/datadog-api-v2-collection/llms.txt) - [OpenAPI document](https://skmtc.dev/datadog/apis/datadog-api-v2-collection/revisions/da68bf029e4c?raw)
