---
updatedAt: 2026-04-23T13:29:19.000Z
agentTools:
  projectIndex: https://developer.xentral.com/llms.txt
---

# Execute query

Execute a query synchronously on the Analytics platform and get result table (Redshift dialect). The number of records that you receive as results is limited to a reasonable amount. This endpoint is mainly for viewing the data. Use the export endpoints in order to fetch all results.

# OpenAPI definition

```json
{
  "openapi": "3.0.0",
  "info": {
    "title": "Xentral API",
    "version": "v0.1",
    "description": "Xentral is an ERP platform.",
    "contact": {
      "name": "Xentral",
      "url": "https://xentral.com",
      "email": "api@xentral.com"
    }
  },
  "tags": [
    {
      "name": "Query",
      "description": "Create, manage and export reports and report results based on SQL queries against your data."
    }
  ],
  "components": {
    "securitySchemes": {
      "BearerAuth": {
        "type": "http",
        "scheme": "bearer",
        "description": "Bearer token obtained in POST /tokens endpoint or pregenerated in the system."
      }
    }
  },
  "security": [
    {
      "BearerAuth": []
    }
  ],
  "servers": [
    {
      "url": "https://{xentralId}.xentral.biz",
      "description": "Your Xentral Instance",
      "variables": {
        "xentralId": {
          "default": "xentral"
        }
      }
    },
    {
      "url": "https://{domain}",
      "description": "Xentral at a custom domain",
      "variables": {
        "domain": {
          "default": "xentral.com"
        }
      }
    }
  ],
  "x-readme": {
    "samples-languages": []
  },
  "paths": {
    "/api/v1/analytics/query": {
      "post": {
        "tags": [
          "Query"
        ],
        "operationId": "analytics.query",
        "summary": "Execute query",
        "description": "Execute a query synchronously on the Analytics platform and get result table (Redshift dialect). The number of records that you receive as results is limited to a reasonable amount. This endpoint is mainly for viewing the data. Use the export endpoints in order to fetch all results.",
        "requestBody": {
          "description": "Query payload",
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "additionalProperties": false,
                "required": [
                  "query"
                ],
                "example": {
                  "query": "SELECT * FROM users",
                  "settings": {
                    "exportFormat": "csv",
                    "delimiter": ","
                  },
                  "parameters": [
                    {
                      "name": "date",
                      "type": "string",
                      "defaultValue": "2021-01-01"
                    }
                  ]
                },
                "properties": {
                  "query": {
                    "type": "string",
                    "description": "SQL query to execute",
                    "example": "SELECT * FROM users"
                  },
                  "settings": {
                    "type": "object",
                    "nullable": true,
                    "additionalProperties": false,
                    "properties": {
                      "delimiter": {
                        "type": "string",
                        "description": "The delimiter character used for CSV or TXT exports",
                        "example": ",",
                        "minLength": 1,
                        "maxLength": 1
                      },
                      "escapeSpecialCharacters": {
                        "type": "boolean",
                        "description": "Whether to escape special characters in TXT exports (e.g. quotes, newlines)",
                        "example": true,
                        "default": false
                      },
                      "disableQuotes": {
                        "type": "boolean",
                        "description": "Whether to disable enclosing all values with double quotes in TXT exports. This is useful for handling special characters or values that contain the delimiter character. It's problematic if values contain double quotes themselves.",
                        "example": false,
                        "default": false
                      },
                      "exportFormat": {
                        "type": "string",
                        "description": "Export format for reports",
                        "example": "txt",
                        "enum": [
                          "csv",
                          "xlsx",
                          "json",
                          "txt",
                          "parquet",
                          "pdf"
                        ],
                        "default": "txt"
                      },
                      "numberFormattingMode": {
                        "type": "string",
                        "description": "Number formatting mode that should be applied when visualizing numbers (does not affect exports)",
                        "example": "locale",
                        "enum": [
                          "locale",
                          "raw"
                        ],
                        "default": "raw"
                      }
                    }
                  },
                  "parameters": {
                    "type": "array",
                    "nullable": true,
                    "items": {
                      "type": "object",
                      "additionalProperties": false,
                      "required": [
                        "name",
                        "type",
                        "defaultValue"
                      ],
                      "example": {
                        "name": "date",
                        "type": "string",
                        "defaultValue": "2021-01-01"
                      },
                      "properties": {
                        "name": {
                          "type": "string",
                          "description": "Parameter name",
                          "example": "date"
                        },
                        "type": {
                          "type": "string",
                          "description": "Parameter type",
                          "example": "string"
                        },
                        "defaultValue": {
                          "type": "string",
                          "description": "Default value for parameter you want to store",
                          "example": "2021-01-01"
                        },
                        "valueMap": {
                          "type": "array",
                          "description": "Array of dropdown options with label and value properties. Values will be rendered in the query, labels are displayed in the dropdown.",
                          "items": {
                            "type": "object",
                            "required": [
                              "label",
                              "value"
                            ],
                            "properties": {
                              "label": {
                                "type": "string",
                                "description": "Display label shown in the dropdown"
                              },
                              "value": {
                                "type": "string",
                                "description": "Value used in the query"
                              }
                            }
                          },
                          "example": [
                            {
                              "label": "Option 1",
                              "value": "option1"
                            },
                            {
                              "label": "Option 2",
                              "value": "option2"
                            }
                          ]
                        }
                      }
                    }
                  }
                }
              },
              "examples": {
                "example": {
                  "summary": "Example SQL query payload",
                  "value": {
                    "query": "SELECT * FROM users",
                    "parameters": [
                      {
                        "name": "date",
                        "type": "string",
                        "defaultValue": "2021-01-01"
                      }
                    ]
                  }
                }
              }
            }
          }
        },
        "parameters": [
          {
            "name": "preview",
            "in": "query",
            "style": "deepObject",
            "schema": {
              "type": "object",
              "additionalProperties": false,
              "properties": {
                "preview": {
                  "type": "boolean",
                  "example": false,
                  "default": false,
                  "description": "If true, only a limited amount of records will be returned, but the request does not cost any credits. If true, all results are returned up to a max number of 500 rows."
                }
              }
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Query response",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "additionalProperties": false,
                  "required": [
                    "data",
                    "meta"
                  ],
                  "properties": {
                    "data": {
                      "description": "Generic result response for a query in a table-like structure.",
                      "type": "object",
                      "nullable": true,
                      "additionalProperties": false,
                      "required": [
                        "header",
                        "rows"
                      ],
                      "properties": {
                        "header": {
                          "type": "array",
                          "items": {
                            "type": "string"
                          }
                        },
                        "rows": {
                          "type": "array",
                          "items": {
                            "type": "array",
                            "items": {
                              "type": "string"
                            }
                          }
                        }
                      },
                      "example": {
                        "header": [
                          "id",
                          "name"
                        ],
                        "rows": [
                          [
                            "1",
                            "Alice"
                          ],
                          [
                            "2",
                            "Bob"
                          ]
                        ]
                      }
                    },
                    "meta": {
                      "description": "Query meta information.",
                      "type": "object",
                      "additionalProperties": false,
                      "nullable": true,
                      "example": {
                        "query": "SELECT * FROM users",
                        "executionTime": 0.123,
                        "totalResults": 2,
                        "columnTypes": [
                          "integer",
                          "string"
                        ]
                      },
                      "properties": {
                        "columnTypes": {
                          "type": "array",
                          "nullable": true,
                          "items": {
                            "type": "string"
                          },
                          "description": "Derived column types for each column in the result table.",
                          "example": [
                            "integer",
                            "string"
                          ]
                        },
                        "executionTime": {
                          "description": "Execution time of the query in seconds.",
                          "example": 0.123,
                          "type": "number",
                          "nullable": true
                        },
                        "query": {
                          "description": "SQL query that was executed.",
                          "type": "string",
                          "nullable": false,
                          "example": "SELECT * FROM users"
                        },
                        "totalResults": {
                          "description": "Total number of rows og the result (the returned result is always limited).",
                          "type": "number",
                          "nullable": true,
                          "example": 2
                        }
                      }
                    }
                  }
                }
              }
            }
          },
          "400": {
            "description": "Error response with message",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "additionalProperties": false,
                  "required": [
                    "message"
                  ],
                  "properties": {
                    "message": {
                      "description": "Error message",
                      "type": "string",
                      "example": "SQL statement is invalid"
                    }
                  }
                }
              }
            }
          },
          "401": {
            "description": "Unable to authenticate the client",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "message": {
                      "type": "string",
                      "description": "Error message explaining why the request failed.",
                      "example": "Missing required scopes: customer:create."
                    }
                  }
                },
                "example": {
                  "message": "Missing required scopes: customer:create."
                }
              },
              "text/html": {
                "schema": {
                  "type": "string",
                  "example": "Unauthorized"
                }
              }
            }
          },
          "402": {
            "description": "Resource can not be accessed because you exceeded the credit limit."
          },
          "403": {
            "description": "Unable to authorize the client"
          },
          "404": {
            "description": "Resource was not found or not enough access privileges"
          },
          "415": {
            "description": "Resource representation send in the request is not supported."
          },
          "429": {
            "description": "Too many API calls made."
          }
        }
      }
    }
  }
}
```