Pular para conteúdo

NOTION_UPDATE_BLOCK - Atualizar Block no Notion

O que é este Node?

O NOTION_UPDATE_BLOCK é o node responsável por modificar blocos de conteúdo existentes no Notion, permitindo editar texto de parágrafos, títulos, listas e outros elementos já criados.

Por que este Node existe?

Atualizar conteúdo existente é diferente de adicionar novo. O NOTION_UPDATE_BLOCK existe para:

  1. Edição de conteúdo: Modificar texto de blocks existentes
  2. Correções: Atualizar informações incorretas em documentos
  3. To-do updates: Marcar/desmarcar checkboxes de tarefas
  4. Revisões: Atualizar documentação mantendo estrutura

Como funciona internamente?

Quando o NOTION_UPDATE_BLOCK é executado, o sistema:

  1. Autentica na Notion API: Usa o apiKey fornecido
  2. Identifica o block: Usa o blockId fornecido
  3. Monta novo conteúdo: Prepara estrutura atualizada do block
  4. Envia PATCH: Faz requisição para https://api.notion.com/v1/blocks/{blockId}
  5. Se erro: Retorna exceção (block não encontrado, tipo incompatível, etc.)
  6. Se sucesso: Retorna block atualizado

Código interno (baseado na Notion API v1):

case 'updateBlock':
  const updateBlockResponse = await firstValueFrom(
    this.httpService.patch(`${notionApiUrl}/blocks/${data.blockId}`,
      {
        [data.blockType]: data.content,
      },
      { headers }
    )
  );
  return {
    success: true,
    blockId: updateBlockResponse.data.id,
    type: updateBlockResponse.data.type,
  };

Quando você DEVE usar este Node?

Use NOTION_UPDATE_BLOCK sempre que precisar de modificar blocks existentes:

Casos de uso

  1. Editar parágrafo: "Corrigir texto do parágrafo X"
  2. Marcar to-do: "Marcar checkbox como concluído"
  3. Atualizar lista: "Modificar item da lista"
  4. Corrigir título: "Atualizar heading com nova informação"
  5. Update code: "Corrigir código em code block"

Quando NÃO usar NOTION_UPDATE_BLOCK

  • Adicionar novo conteúdo: Use NOTION_ADD_BLOCK ao invés
  • Atualizar propriedades da página: Use NOTION_UPDATE_PAGE ao invés
  • Criar nova página: Use NOTION_CREATE_PAGE ao invés

Parâmetros

Campo Tipo Obrigatório Descrição
operation string Sim Deve ser "updateBlock"
apiKey string Sim Token de integração do Notion
blockId string Sim ID do block a atualizar
blockType string Sim Tipo do block (paragraph, heading_1, to_do, etc.)
content object Sim Novo conteúdo do block

Tipos de Block Suportados

Paragraph:

{
  "blockType": "paragraph",
  "content": {
    "rich_text": [
      {
        "type": "text",
        "text": {
          "content": "Novo texto do parágrafo"
        }
      }
    ]
  }
}

Heading 1/2/3:

{
  "blockType": "heading_2",
  "content": {
    "rich_text": [
      {
        "type": "text",
        "text": {
          "content": "Novo título"
        }
      }
    ]
  }
}

To-Do (marcar/desmarcar):

{
  "blockType": "to_do",
  "content": {
    "rich_text": [
      {
        "type": "text",
        "text": {
          "content": "Tarefa atualizada"
        }
      }
    ],
    "checked": true
  }
}

Bulleted/Numbered List:

{
  "blockType": "bulleted_list_item",
  "content": {
    "rich_text": [
      {
        "type": "text",
        "text": {
          "content": "Item modificado"
        }
      }
    ]
  }
}

Code:

{
  "blockType": "code",
  "content": {
    "rich_text": [
      {
        "type": "text",
        "text": {
          "content": "const updated = true;"
        }
      }
    ],
    "language": "javascript"
  }
}

Exemplo 1: Marcar To-Do como Concluído

{
  "name": "Marcar Tarefa Concluída",
  "nodes": [
    {
      "id": "start_1",
      "type": "start",
      "position": { "x": 100, "y": 100 },
      "data": { "label": "Início" }
    },
    {
      "id": "input_1",
      "type": "input",
      "position": { "x": 300, "y": 100 },
      "data": {
        "label": "Block ID",
        "parameters": {
          "message": "ID do block to-do:",
          "variable": "block_id"
        }
      }
    },
    {
      "id": "notion_1",
      "type": "notion",
      "position": { "x": 500, "y": 100 },
      "data": {
        "label": "Marcar Concluído",
        "parameters": {
          "operation": "updateBlock",
          "apiKey": "secret_SEU_TOKEN",
          "blockId": "{{block_id}}",
          "blockType": "to_do",
          "content": {
            "rich_text": [
              {
                "type": "text",
                "text": {
                  "content": "Tarefa concluída"
                }
              }
            ],
            "checked": true
          }
        }
      }
    },
    {
      "id": "message_1",
      "type": "message",
      "position": { "x": 700, "y": 100 },
      "data": {
        "label": "Confirmar",
        "parameters": {
          "message": "✅ Tarefa marcada como concluída!"
        }
      }
    },
    {
      "id": "end_1",
      "type": "end",
      "position": { "x": 900, "y": 100 },
      "data": { "label": "Fim" }
    }
  ],
  "edges": [
    { "source": "start_1", "target": "input_1" },
    { "source": "input_1", "target": "notion_1" },
    { "source": "notion_1", "target": "message_1" },
    { "source": "message_1", "target": "end_1" }
  ]
}

Exemplo 2: Corrigir Parágrafo

{
  "name": "Corrigir Texto de Parágrafo",
  "nodes": [
    {
      "id": "start_1",
      "type": "start",
      "position": { "x": 100, "y": 100 },
      "data": { "label": "Início" }
    },
    {
      "id": "input_1",
      "type": "input",
      "position": { "x": 300, "y": 100 },
      "data": {
        "label": "Block ID",
        "parameters": {
          "message": "ID do parágrafo:",
          "variable": "block_id"
        }
      }
    },
    {
      "id": "input_2",
      "type": "input",
      "position": { "x": 500, "y": 100 },
      "data": {
        "label": "Novo Texto",
        "parameters": {
          "message": "Novo texto do parágrafo:",
          "variable": "novo_texto"
        }
      }
    },
    {
      "id": "notion_1",
      "type": "notion",
      "position": { "x": 700, "y": 100 },
      "data": {
        "label": "Atualizar Parágrafo",
        "parameters": {
          "operation": "updateBlock",
          "apiKey": "secret_SEU_TOKEN",
          "blockId": "{{block_id}}",
          "blockType": "paragraph",
          "content": {
            "rich_text": [
              {
                "type": "text",
                "text": {
                  "content": "{{novo_texto}}"
                }
              }
            ]
          }
        }
      }
    },
    {
      "id": "message_1",
      "type": "message",
      "position": { "x": 900, "y": 100 },
      "data": {
        "label": "Confirmar",
        "parameters": {
          "message": "✅ Parágrafo atualizado com sucesso!"
        }
      }
    },
    {
      "id": "end_1",
      "type": "end",
      "position": { "x": 1100, "y": 100 },
      "data": { "label": "Fim" }
    }
  ],
  "edges": [
    { "source": "start_1", "target": "input_1" },
    { "source": "input_1", "target": "input_2" },
    { "source": "input_2", "target": "notion_1" },
    { "source": "notion_1", "target": "message_1" },
    { "source": "message_1", "target": "end_1" }
  ]
}

Exemplo 3: Atualizar Lista com To-Dos

{
  "name": "Workflow Completo - Buscar e Marcar To-Do",
  "nodes": [
    {
      "id": "start_1",
      "type": "start",
      "position": { "x": 100, "y": 100 },
      "data": { "label": "Início" }
    },
    {
      "id": "input_1",
      "type": "input",
      "position": { "x": 300, "y": 100 },
      "data": {
        "label": "Page ID",
        "parameters": {
          "message": "ID da página com to-dos:",
          "variable": "page_id"
        }
      }
    },
    {
      "id": "notion_get_1",
      "type": "notion",
      "position": { "x": 500, "y": 100 },
      "data": {
        "label": "Obter Página",
        "parameters": {
          "operation": "getPage",
          "apiKey": "secret_SEU_TOKEN",
          "pageId": "{{page_id}}"
        }
      }
    },
    {
      "id": "notion_update_1",
      "type": "notion",
      "position": { "x": 700, "y": 100 },
      "data": {
        "label": "Marcar Primeiro To-Do",
        "parameters": {
          "operation": "updateBlock",
          "apiKey": "secret_SEU_TOKEN",
          "blockId": "BLOCK_ID_DO_TODO",
          "blockType": "to_do",
          "content": {
            "rich_text": [
              {
                "type": "text",
                "text": {
                  "content": "Primeira tarefa - Concluída"
                }
              }
            ],
            "checked": true
          }
        }
      }
    },
    {
      "id": "message_1",
      "type": "message",
      "position": { "x": 900, "y": 100 },
      "data": {
        "label": "Confirmar",
        "parameters": {
          "message": "✅ To-do atualizado na página!"
        }
      }
    },
    {
      "id": "end_1",
      "type": "end",
      "position": { "x": 1100, "y": 100 },
      "data": { "label": "Fim" }
    }
  ],
  "edges": [
    { "source": "start_1", "target": "input_1" },
    { "source": "input_1", "target": "notion_get_1" },
    { "source": "notion_get_1", "target": "notion_update_1" },
    { "source": "notion_update_1", "target": "message_1" },
    { "source": "message_1", "target": "end_1" }
  ]
}

Resposta do Node

{
  "success": true,
  "blockId": "a8aec43c-6f00-4f57-89c9-e2e4aa3e8d9f",
  "type": "to_do"
}

Boas Práticas

SIM: - Verifique o tipo do block antes de atualizar - Use blockType correto correspondente ao block - Mantenha estrutura rich_text mesmo para textos simples - Salve blockIds ao criar para facilitar updates futuros

NÃO: - Não tente mudar o tipo do block (paragraph → heading não funciona) - Não atualize sem verificar se blockId existe - Não esqueça rich_text na estrutura - Não use UPDATE quando deveria usar ADD (novo conteúdo)

Dicas

BlockId: Cada block tem ID único - salve ao criar com ADD_BLOCK Tipo imutável: Não pode mudar tipo do block (crie novo ao invés) To-do checked: Use "checked": true/false para marcar/desmarcar Rich text obrigatório: Mesmo texto simples precisa do formato rich_text Obter blockIds: Use Notion Retrieve block children API para listar blocks de uma página Atomic updates: Cada UPDATE modifica um block por vez

Próximo Node

NOTION_ADD_BLOCK - Adicionar novos blocks → NOTION_UPDATE_PAGE - Atualizar propriedades da página → NOTION_GET_PAGE - Obter informações da página