gastownhall/beads · error

parse create page response: %w

Error message

parse create page response: %w

What it means

CreatePage POSTs to /pages and unmarshals the response into a Page struct; this error wraps unmarshal failure. The API accepted the request (HTTP layer passed) but the returned page JSON does not fit the Page struct.

Source

Thrown at internal/notion/client.go:163

	}
	return nil, fmt.Errorf("query pagination exceeded %d pages", maxQueryPages)
}

func (c *Client) CreatePage(ctx context.Context, dataSourceID string, properties map[string]interface{}) (*Page, error) {
	request := map[string]interface{}{
		"parent": map[string]interface{}{
			"type":           "data_source_id",
			"data_source_id": dataSourceID,
		},
		"properties": properties,
	}
	body, err := c.doRequest(ctx, http.MethodPost, "/pages", request)
	if err != nil {
		return nil, err
	}
	var page Page
	if err := json.Unmarshal(body, &page); err != nil {
		return nil, fmt.Errorf("parse create page response: %w", err)
	}
	return &page, nil
}

func (c *Client) UpdatePage(ctx context.Context, pageID string, properties map[string]interface{}) (*Page, error) {
	request := map[string]interface{}{"properties": properties}
	body, err := c.doRequest(ctx, http.MethodPatch, "/pages/"+url.PathEscape(pageID), request)
	if err != nil {
		return nil, err
	}
	var page Page
	if err := json.Unmarshal(body, &page); err != nil {
		return nil, fmt.Errorf("parse update page response: %w", err)
	}
	return &page, nil
}

func (c *Client) ArchivePage(ctx context.Context, pageID string, inTrash bool) (*Page, error) {

View on GitHub (pinned to 71377f2769)

Solutions

  1. Log the raw body on failure to see whether it is JSON and where the shape differs.
  2. Upgrade the notion client library so Page matches the current API schema.
  3. Verify the Notion-Version header is pinned to a version compatible with the structs.
  4. If only the ID is needed, consider decoding into a minimal struct with just json:"id" to tolerate unknown property shapes.

Example fix

// before
var page Page
if err := json.Unmarshal(body, &page); err != nil {
    return nil, fmt.Errorf("parse create page response: %w", err)
}
// after
var page Page
if err := json.Unmarshal(body, &page); err != nil {
    return nil, fmt.Errorf("parse create page response: %w (body: %.200s)", err, body)
}
Defensive patterns

Strategy: try-catch

Try / catch

page, err := client.CreatePage(ctx, dsID, props)
if err != nil {
    if strings.Contains(err.Error(), "parse create page response") {
        // check whether the page was actually created (re-query) before retrying
    }
    return err
}

Prevention

When it happens

Trigger: Calling Client.CreatePage when the response body is not valid JSON or its shape (properties, parent, id fields) no longer matches the Page struct — typically after a Notion API schema change or a non-JSON body from an intermediary.

Common situations: Notion changing page property value shapes (e.g. rich_text arrays, new property types) so Unmarshal errors on typed fields; misconfigured API gateway returning HTML; stale library version against a newer API.

Related errors


AI-assisted analysis of gastownhall/beads@71377f2769 (2026-08-30). Data as JSON: /api/errors/d45778cf2c6b8c0e. Report an issue: GitHub.