import os
import requests
block_id = "block_id"
url = f"https://api.notion.com/v1/blocks/{block_id}/children"
headers = {
"Authorization": f"Bearer {os.environ['NOTION_API_KEY']}",
"Notion-Version": "2022-06-28"
}
data = {
"children": [{
"object": "block",
"type": "paragraph",
"paragraph": {
"rich_text": [{
"type": "text",
"text": {"content": "Updated text"}
}]
}
}]
}
response = requests.put(url, headers=headers, json=data)
if response.status_code >= 400:
print(response.text)
else:
print(response.json())
import os
import httpx
block_id = "block_id"
url = f"https://api.notion.com/v1/blocks/{block_id}/children"
headers = {
"Authorization": f"Bearer {os.environ['NOTION_API_KEY']}",
"Notion-Version": "2022-06-28"
}
data = {
"children": [{
"object": "block",
"type": "paragraph",
"paragraph": {
"rich_text": [{
"type": "text",
"text": {"content": "Updated text"}
}]
}
}]
}
with httpx.Client() as client:
response = client.put(url, headers=headers, json=data)
if response.status_code >= 400:
print(response.text)
else:
print(response.json())
const fetch = require('node-fetch');
const blockId = 'block_id';
const url = `https://api.notion.com/v1/blocks/${blockId}/children`;
const headers = {
'Authorization': `Bearer ${process.env.NOTION_API_KEY}`,
'Notion-Version': '2022-06-28'
};
const data = {
children: [{
object: 'block',
type: 'paragraph',
paragraph: {
rich_text: [{
type: 'text',
text: { content: 'Updated text' }
}]
}
}]
};
fetch(url, {
method: 'PUT',
headers,
body: JSON.stringify(data)
})
.then(res => {
if (res.status >= 400) {
return res.text().then(console.error);
}
return res.json().then(console.log);
})
.catch(console.error);
const axios = require('axios');
const blockId = 'block_id';
const url = `https://api.notion.com/v1/blocks/${blockId}/children`;
const headers = {
'Authorization': `Bearer ${process.env.NOTION_API_KEY}`,
'Notion-Version': '2022-06-28'
};
const data = {
children: [{
object: 'block',
type: 'paragraph',
paragraph: {
rich_text: [{
type: 'text',
text: { content: 'Updated text' }
}]
}
}]
};
axios.put(url, data, { headers })
.then(res => {
if (res.status >= 400) {
console.error(res.data);
} else {
console.log(res.data);
}
})
.catch(console.error);
package main
import (
"bytes"
"encoding/json"
"fmt"
"io"
"net/http"
"os"
)
func main() {
blockID := "block_id"
url := fmt.Sprintf("https://api.notion.com/v1/blocks/%s/children", blockID)
requestBody := map[string]interface{}{
"children": []map[string]interface{}{
{
"object": "block",
"type": "paragraph",
"paragraph": map[string]interface{}{
"rich_text": []map[string]interface{}{
{
"type": "text",
"text": map[string]interface{}{
"content": "Updated text",
},
},
},
},
},
},
}
bodyBytes, _ := json.Marshal(requestBody)
req, _ := http.NewRequest("PUT", url, bytes.NewBuffer(bodyBytes))
req.Header.Set("Authorization", "Bearer "+os.Getenv("NOTION_API_KEY"))
req.Header.Set("Notion-Version", "2022-06-28")
req.Header.Set("Content-Type", "application/json")
client := &http.Client{}
resp, err := client.Do(req)
if err != nil {
fmt.Println("Error:", err)
return
}
defer resp.Body.Close()
if resp.StatusCode >= 400 {
body, _ := io.ReadAll(resp.Body)
fmt.Println(string(body))
} else {
body, _ := io.ReadAll(resp.Body)
fmt.Println(string(body))
}
}
<?php
$blockId = 'block_id';
$url = 'https://api.notion.com/v1/blocks/' . $blockId . '/children';
$headers = [
'Authorization: Bearer ' . getenv('NOTION_API_KEY'),
'Notion-Version: 2022-06-28',
'Content-Type: application/json'
];
$data = [
'children' => [[
'object' => 'block',
'type' => 'paragraph',
'paragraph' => [
'rich_text' => [[
'type' => 'text',
'text' => ['content' => 'Updated text']
]]
]
]]
];
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'PUT');
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($data));
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$response = curl_exec($ch);
$httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
curl_close($ch);
if ($httpCode >= 400) {
echo $response;
} else {
echo $response;
}
require 'net/http'
require 'json'
require 'uri'
block_id = 'block_id'
url = URI.parse("https://api.notion.com/v1/blocks/#{block_id}/children")
headers = {
'Authorization' => "Bearer #{ENV['NOTION_API_KEY']}",
'Notion-Version' => '2022-06-28',
'Content-Type' => 'application/json'
}
data = {
children: [{
object: 'block',
type: 'paragraph',
paragraph: {
rich_text: [{
type: 'text',
text: { content: 'Updated text' }
}]
}
}]
}
http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true
request = Net::HTTP::Put.new(url.request_uri, headers)
request.body = data.to_json
response = http.request(request)
if response.code.to_i >= 400
puts response.body
else
puts response.body
end
import Foundation
let blockId = "block_id"
let url = URL(string: "https://api.notion.com/v1/blocks/" + blockId + "/children")!
var request = URLRequest(url: url)
request.httpMethod = "PUT"
request.setValue("Bearer \(ProcessInfo.processInfo.environment["NOTION_API_KEY"] ?? "")", forHTTPHeaderField: "Authorization")
request.setValue("2022-06-28", forHTTPHeaderField: "Notion-Version")
request.setValue("application/json", forHTTPHeaderField: "Content-Type")
let body: [String: Any] = [
"children": [
[
"object": "block",
"type": "paragraph",
"paragraph": [
"rich_text": [
[
"type": "text",
"text": ["content": "Updated text"]
]
]
]
]
]
]
request.httpBody = try? JSONSerialization.data(withJSONObject: body)
let task = URLSession.shared.dataTask(with: request) { data, response, error in
if let error = error {
print(error)
return
}
guard let httpResponse = response as? HTTPURLResponse else {
print("Invalid response")
return
}
if httpResponse.statusCode >= 400 {
if let data = data, let responseBody = String(data: data, encoding: .utf8) {
print(responseBody)
}
} else {
if let data = data, let responseBody = String(data: data, encoding: .utf8) {
print(responseBody)
}
}
}
task.resume()
RunLoop.main.run()
use std::env;
use reqwest::blocking::Client;
use serde_json::json;
fn main() -> Result<(), Box<dyn std::error::Error>> {
let block_id = "block_id";
let url = format!("https://api.notion.com/v1/blocks/{}/children", block_id);
let client = Client::new();
let response = client
.put(&url)
.header("Authorization", format!("Bearer {}", env::var("NOTION_API_KEY")?))
.header("Notion-Version", "2022-06-28")
.json(&json!({
"children": [{
"object": "block",
"type": "paragraph",
"paragraph": {
"rich_text": [{
"type": "text",
"text": {"content": "Updated text"}
}]
}
}]
}))
.send()?;
if response.status().as_u16() >= 400 {
println!("{}", response.text()?);
} else {
println!("{}", response.text()?);
}
Ok(())
}
using System;
using System.Net.Http;
using System.Net.Http.Headers;
using System.Text.Json;
using System.Threading.Tasks;
class Program
{
static async Task Main()
{
var blockId = "block_id";
var url = new Uri($"https://api.notion.com/v1/blocks/{blockId}/children");
var client = new HttpClient();
client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue(
"Bearer",
Environment.GetEnvironmentVariable("NOTION_API_KEY")
);
client.DefaultRequestHeaders.Add("Notion-Version", "2022-06-28");
var body = new
{
children = new[]
{
new
{
@object = "block",
type = "paragraph",
paragraph = new
{
rich_text = new[]
{
new
{
type = "text",
text = new { content = "Updated text" }
}
}
}
}
}
};
var response = await client.PutAsJsonAsync(url, body);
if (!response.IsSuccessStatusCode)
{
var errorContent = await response.Content.ReadAsStringAsync();
Console.WriteLine(errorContent);
}
else
{
var content = await response.Content.ReadAsStringAsync();
Console.WriteLine(content);
}
}
}