# Getting Data

### Getting Data from a Bloc

{% hint style="warning" %}
**Please note:** All [Bloc Data User Restrictions](https://manual.blocworx.com/blocworx-documentation/bloc-editor/bloc-settings/data-restriction-settings) will apply in these requests. If you are not getting data back or cannot access the bloc, please ensure the user associated with the Auth token has access to the bloc and is not restricted.
{% endhint %}

***

### Get Data from a Bloc (No Filters)

`GET` `https://example.mydomain.com/api/get-data`

> ⚠️ This endpoint expects a JSON request body even though it uses the GET method.

***

### Request Body

<table><thead><tr><th width="120.0859375">Name</th><th width="88.421875">Type</th><th>Description</th></tr></thead><tbody><tr><td>blocId*</td><td>string</td><td>The ID of the bloc. This may be a UUID (e.g. <code>a1489634-4009-4cc0-8a65-9965f5a1bea7</code>) or numeric ID depending on your instance.</td></tr><tr><td>resultLimit</td><td>integer</td><td>Number of records to return per request. Defaults to <strong>10</strong> if not provided.</td></tr><tr><td>currentPage</td><td>integer</td><td>Pagination index (1-based). Used with <code>resultLimit</code> to retrieve subsequent pages.</td></tr><tr><td>reverse</td><td>boolean</td><td>Controls sort order:• <code>false</code> (default) → newest first• <code>true</code> → oldest first</td></tr><tr><td>fromDate</td><td>string</td><td>Filters records <strong>after</strong> this timestamp. Format: <code>YYYY-MM-DD HH:MM:SS</code></td></tr><tr><td>toDate</td><td>string</td><td>Filters records <strong>before</strong> this timestamp. Format: <code>YYYY-MM-DD HH:MM:SS</code></td></tr></tbody></table>

***

### ⚠️ Date Filtering Behavior (Important)

* `fromDate` **alone** → accepts full datetime (`YYYY-MM-DD HH:MM:SS`)
* `toDate` **alone** → accepts full datetime (`YYYY-MM-DD HH:MM:SS`)
* `fromDate` + `toDate` together:
  * In some cases, it must be provided as a **date-only format (`YYYY-MM-DD`)**

***

### Response Structure

The response returns a **mixed object**, not a pure array.

* Numeric keys (`"0"`, `"1"`, etc.) → records
* Additional keys provide metadata

***

### 200 Response Example

```json
{
  "data": {
    "0": {
      "created_at": "2026-03-19 13:42:13",
      "submitted_status": 1,
      "user_id": "exampleuser",
      "field_1": "value",
      "field_2": "value",
      "cartolytics_entry_row_id": 123456
    },
    "1": {
      "created_at": "2026-03-19 13:42:05",
      "submitted_status": 1,
      "user_id": "exampleuser",
      "field_1": "value",
      "field_2": "value",
      "cartolytics_entry_row_id": 123457
    },
    "count": 14,
    "fieldCounts": {
      "field_1": {
        "value": 2
      }
    },
    "countLimitInfo": {
      "scan_limit": null,
      "scan_limit_time_logged": null,
      "scans_counted": 14,
      "limit_reached": 0
    },
    "fieldNames": {
      "field_1": "Field 1"
    }
  }
}
```

***

### Notes on Response

* `count` → total number of matching records (not just returned page)
* `fieldCounts` → aggregated values across all matching records
* `countLimitInfo` → scan tracking metadata
* `fieldNames` → mapping of field slugs to display names

***

### Error Responses

#### 401 Unauthorized

```json
{
  "error": "You are not authorized to access this bloc"
}
```

#### 400 Bad Request

```json
{
  "error": "Error message"
}
```

> ⚠️ Some errors may return:

```json
{
  "message": "Trailing data"
}
```

(Error response formats are not fully standardized.)

***

### Example Requests

#### cURL

```bash
curl --request GET '{{base_url}}/api/get-data' \
  --header 'Authorization: Bearer {{token}}' \
  --header 'Content-Type: application/json' \
  --data '{
    "blocId": "a1489634-4009-4cc0-8a65-9965f5a1bea7",
    "resultLimit": 2,
    "currentPage": 1,
    "reverse": false
  }'
```

***

#### Node.js (Axios)

```javascript
const axios = require('axios');

axios({
  method: 'get',
  url: '{{base_url}}/api/get-data',
  headers: {
    Authorization: 'Bearer {{token}}',
    'Content-Type': 'application/json'
  },
  data: {
    blocId: 'a1489634-4009-4cc0-8a65-9965f5a1bea7',
    resultLimit: 2,
    currentPage: 1,
    reverse: false
  }
})
.then(res => console.log(res.data))
.catch(err => console.error(err));
```

***

#### Python

```python
import requests

url = "{{base_url}}/api/get-data"

payload = {
    "blocId": "a1489634-4009-4cc0-8a65-9965f5a1bea7",
    "resultLimit": 2,
    "currentPage": 1,
    "reverse": False
}

headers = {
    "Authorization": "Bearer {{token}}",
    "Content-Type": "application/json"
}

response = requests.get(url, json=payload, headers=headers)
print(response.text)
```


---

# 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://manual.blocworx.com/blocworx-api/reference/api-reference/getting-data.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.
