mapResponse
mapResponse
is a utility function that transforms raw Notion API responses into simplified, developer-friendly JavaScript objects.
It recursively maps pages, databases, and blocks, extracting only the most relevant fields and values.
Parameters
Name | Type | Description |
---|---|---|
notionResponse |
object |
The raw response object from the Notion API (page, database, block, or list). |
Returns
A simplified JavaScript object (or array of objects) representing the Notion entity.
The structure depends on the input type (page, database, block, or list).
Example
import { mapResponse } from 'notionbridge/extras/responseMapping';
const raw = await fetchNotionApiSomehow();
const mapped = mapResponse(raw);
console.log(mapped);
Mapping Behavior
- Pages: Returns an object with
id
,url
, and all properties as plain values. - Databases: Returns an object with
id
,title
, and a simplifiedproperties
map. - Blocks: Returns an object with
id
,type
,has_children
,text
(if present), and other relevant fields. - Lists: Recursively maps each item in
results
usingmapResponse
.
Notes
- Unknown or unsupported types are returned as-is or with a
raw
field containing the original content. - For lists,
mapResponse
returns an array of mapped objects. - Nested children (blocks) are recursively mapped.
Example Response
{
"id": "abc123",
"url": "https://www.notion.so/abc123",
"Name": "Demo",
"Status": "In Progress"
}
{
"id": "block123",
"type": "to_do",
"has_children": false,
"text": "Check this",
"checked": true,
"children": []
}
{
"id": "db123",
"title": "My Database",
"properties": {
"Name": { "id": "title", "type": "title" },
"Status": { "id": "status", "type": "status" }
}
}