---
title: Get AST for source code
description: Datadog, the leading service for cloud-scale monitoring.
breadcrumbs: Docs > API Reference > Security Monitoring
---

# Get AST for source code{% #get-ast-for-source-code %}
Copy pageCopied
{% tab title="v2" %}
**Note**: This endpoint is in preview and is subject to change. If you have any feedback, contact [Datadog support](https://docs.datadoghq.com/help/).
| Datadog site      | API endpoint                                                                             |
| ----------------- | ---------------------------------------------------------------------------------------- |
| ap1.datadoghq.com | POST https://api.ap1.datadoghq.com/api/v2/static-analysis/static-analysis-server/get-ast |
| ap2.datadoghq.com | POST https://api.ap2.datadoghq.com/api/v2/static-analysis/static-analysis-server/get-ast |
| app.datadoghq.eu  | POST https://api.datadoghq.eu/api/v2/static-analysis/static-analysis-server/get-ast      |
| app.ddog-gov.com  | POST https://api.ddog-gov.com/api/v2/static-analysis/static-analysis-server/get-ast      |
| us2.ddog-gov.com  | POST https://api.us2.ddog-gov.com/api/v2/static-analysis/static-analysis-server/get-ast  |
| app.datadoghq.com | POST https://api.datadoghq.com/api/v2/static-analysis/static-analysis-server/get-ast     |
| us3.datadoghq.com | POST https://api.us3.datadoghq.com/api/v2/static-analysis/static-analysis-server/get-ast |
| us5.datadoghq.com | POST https://api.us5.datadoghq.com/api/v2/static-analysis/static-analysis-server/get-ast |

### Overview

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

OAuth apps require the `code_analysis_read` authorization [scope](https://docs.datadoghq.com/api/latest/scopes.md#security-monitoring) to access this endpoint.



### Request

#### Body Data (required)



{% tab title="Model" %}

| Parent field | Field                           | Type   | Description                                                                 |
| ------------ | ------------------------------- | ------ | --------------------------------------------------------------------------- |
|              | data [*required*]          | object | The primary data object in the get-AST request.                             |
| data         | attributes [*required*]    | object | The attributes of the get-AST request, containing the source code to parse. |
| attributes   | code [*required*]          | string | The base64-encoded source code to parse into an abstract syntax tree.       |
| attributes   | file_encoding [*required*] | string | The encoding of the source code file (must be utf-8).                       |
| attributes   | language [*required*]      | string | The programming language of the source code to parse.                       |
| data         | id                              | string | An optional identifier for the get-AST request resource.                    |
| data         | type [*required*]          | enum   | Get AST request resource type. Allowed enum values: `get_ast_request`       |

{% /tab %}

{% tab title="Example" %}

```json
{
  "data": {
    "attributes": {
      "code": "aW1wb3J0IHN5cw==",
      "file_encoding": "utf-8",
      "language": "python"
    },
    "id": "string",
    "type": "get_ast_request"
  }
}
```

{% /tab %}

### Response

{% tab title="200" %}
OK
{% tab title="Model" %}
The response payload containing the parsed abstract syntax tree.

| Parent field | Field                        | Type   | Description                                                                         |
| ------------ | ---------------------------- | ------ | ----------------------------------------------------------------------------------- |
|              | data [*required*]       | object | The primary data object in the get-AST response.                                    |
| data         | attributes [*required*] | object | The attributes of the get-AST response, containing the parsed abstract syntax tree. |
| attributes   | ast [*required*]        | object | The parsed abstract syntax tree as a JSON object.                                   |
| data         | id                           | string | The identifier of the get-AST response resource.                                    |
| data         | type [*required*]       | enum   | Get AST response resource type. Allowed enum values: `get_ast_response`             |

{% /tab %}

{% tab title="Example" %}

```json
{
  "data": {
    "attributes": {
      "ast": {}
    },
    "id": "string",
    "type": "get_ast_response"
  }
}
```

{% /tab %}

{% /tab %}

{% tab title="400" %}
Bad Request
{% tab title="Model" %}
API error response.

| Parent field | Field                    | Type     | Description                                                                     |
| ------------ | ------------------------ | -------- | ------------------------------------------------------------------------------- |
|              | errors [*required*] | [object] | A list of errors.                                                               |
| errors       | detail                   | string   | A human-readable explanation specific to this occurrence of the error.          |
| errors       | meta                     | object   | Non-standard meta-information about the error                                   |
| errors       | source                   | object   | References to the source of the error.                                          |
| source       | header                   | string   | A string indicating the name of a single request header which caused the error. |
| source       | parameter                | string   | A string indicating which URI query parameter caused the error.                 |
| source       | pointer                  | string   | A JSON pointer to the value in the request document that caused the error.      |
| errors       | status                   | string   | Status code of the response.                                                    |
| errors       | title                    | string   | Short human-readable summary of the error.                                      |

{% /tab %}

{% tab title="Example" %}

```json
{
  "errors": [
    {
      "detail": "Missing required attribute in body",
      "meta": {},
      "source": {
        "header": "Authorization",
        "parameter": "limit",
        "pointer": "/data/attributes/title"
      },
      "status": "400",
      "title": "Bad Request"
    }
  ]
}
```

{% /tab %}

{% /tab %}

{% tab title="401" %}
Unauthorized
{% tab title="Model" %}
API error response.

| Parent field | Field                    | Type     | Description                                                                     |
| ------------ | ------------------------ | -------- | ------------------------------------------------------------------------------- |
|              | errors [*required*] | [object] | A list of errors.                                                               |
| errors       | detail                   | string   | A human-readable explanation specific to this occurrence of the error.          |
| errors       | meta                     | object   | Non-standard meta-information about the error                                   |
| errors       | source                   | object   | References to the source of the error.                                          |
| source       | header                   | string   | A string indicating the name of a single request header which caused the error. |
| source       | parameter                | string   | A string indicating which URI query parameter caused the error.                 |
| source       | pointer                  | string   | A JSON pointer to the value in the request document that caused the error.      |
| errors       | status                   | string   | Status code of the response.                                                    |
| errors       | title                    | string   | Short human-readable summary of the error.                                      |

{% /tab %}

{% tab title="Example" %}

```json
{
  "errors": [
    {
      "detail": "Missing required attribute in body",
      "meta": {},
      "source": {
        "header": "Authorization",
        "parameter": "limit",
        "pointer": "/data/attributes/title"
      },
      "status": "400",
      "title": "Bad Request"
    }
  ]
}
```

{% /tab %}

{% /tab %}

{% tab title="429" %}
Too many requests
{% tab title="Model" %}
API error response.

| Field                    | Type     | Description       |
| ------------------------ | -------- | ----------------- |
| errors [*required*] | [string] | A list of errors. |

{% /tab %}

{% tab title="Example" %}

```json
{
  "errors": [
    "Bad Request"
  ]
}
```

{% /tab %}

{% /tab %}

### Code Example

##### 
                  \## default
# 
 \# Curl command curl -X POST "https://api.datadoghq.com/api/v2/static-analysis/static-analysis-server/get-ast" \
-H "Accept: application/json" \
-H "Content-Type: application/json" \
-H "DD-API-KEY: ${DD_API_KEY}" \
-H "DD-APPLICATION-KEY: ${DD_APP_KEY}" \
-d @- << EOF
{
  "data": {
    "attributes": {
      "code": "aW1wb3J0IHN5cw==",
      "file_encoding": "utf-8",
      "language": "python"
    },
    "type": "get_ast_request"
  }
}
EOF 
                
{% /tab %}
