import os
import requests
block_id = os.environ["BLOCK_ID"]
url = f"https://api.notion.com/v1/blocks/{block_id}"
headers = {
"Authorization": f"Bearer {os.environ['NOTION_TOKEN']}",
"Notion-Version": "2022-06-28"
}
response = requests.delete(url, headers=headers)
response.raise_for_status()
import os
import httpx
block_id = os.environ["BLOCK_ID"]
url = f"https://api.notion.com/v1/blocks/{block_id}"
headers = {
"Authorization": f"Bearer {os.environ['NOTION_TOKEN']}",
"Notion-Version": "2022-06-28"
}
with httpx.Client() as client:
response = client.delete(url, headers=headers)
response.raise_for_status()
import fetch from 'node-fetch';
import process from 'process';
const blockId = process.env.BLOCK_ID;
const url = `https://api.notion.com/v1/blocks/${blockId}`;
const headers = {
'Authorization': `Bearer ${process.env.NOTION_TOKEN}`,
'Notion-Version': '2022-06-28'
};
try {
const response = await fetch(url, { method: 'DELETE', headers });
if (!response.ok) throw new Error(`HTTP error! status: ${response.status}`);
} catch (error) {
console.error('Request failed:', error);
throw error;
}
import axios from 'axios';
import process from 'process';
const blockId = process.env.BLOCK_ID;
const url = `https://api.notion.com/v1/blocks/${blockId}`;
const headers = {
'Authorization': `Bearer ${process.env.NOTION_TOKEN}`,
'Notion-Version': '2022-06-28'
};
try {
const response = await axios.delete(url, { headers });
if (response.status !== 200) throw new Error(`HTTP error! status: ${response.status}`);
} catch (error) {
console.error('Request failed:', error);
throw error;
}
package main
import (
"fmt"
"net/http"
"os"
)
func main() {
blockID := os.Getenv("BLOCK_ID")
url := fmt.Sprintf("https://api.notion.com/v1/blocks/%s", blockID)
token := os.Getenv("NOTION_TOKEN")
req, err := http.NewRequest("DELETE", url, nil)
if err != nil {
panic(err)
}
req.Header.Set("Authorization", "Bearer "+token)
req.Header.Set("Notion-Version", "2022-06-28")
client := &http.Client{}
resp, err := client.Do(req)
if err != nil {
panic(err)
}
defer resp.Body.Close()
if resp.StatusCode != http.StatusOK {
panic(fmt.Sprintf("HTTP error! status: %s", resp.Status))
}
}
<?php
$blockId = getenv('BLOCK_ID');
$url = "https://api.notion.com/v1/blocks/{$blockId}";
$token = getenv('NOTION_TOKEN');
$headers = [
'Authorization: Bearer ' . $token,
'Notion-Version: 2022-06-28'
];
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'DELETE');
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$response = curl_exec($ch);
$httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
curl_close($ch);
if ($httpCode !== 200) {
throw new Exception("HTTP error! status: {$httpCode}");
}
require 'net/http'
require 'uri'
block_id = ENV['BLOCK_ID']
url = "https://api.notion.com/v1/blocks/#{block_id}"
token = ENV['NOTION_TOKEN']
uri = URI.parse(url)
http = Net::HTTP.new(uri.host, uri.port)
http.use_ssl = true
request = Net::HTTP::Delete.new(uri.request_uri)
request['Authorization'] = "Bearer #{token}"
request['Notion-Version'] = '2022-06-28'
response = http.request(request)
unless response.code == '200'
raise "HTTP error! status: #{response.code}"
end
import Foundation
let blockId = ProcessInfo.processInfo.environment["BLOCK_ID"] ?? ""
let url = URL(string: "https://api.notion.com/v1/blocks/" + blockId)!
var request = URLRequest(url: url)
request.httpMethod = "DELETE"
request.setValue("Bearer \(ProcessInfo.processInfo.environment["NOTION_TOKEN"] ?? "")", forHTTPHeaderField: "Authorization")
request.setValue("2022-06-28", forHTTPHeaderField: "Notion-Version")
let task = URLSession.shared.dataTask(with: request) { data, response, error in
if let error = error {
fatalError("Request failed: \(error)")
}
guard let httpResponse = response as? HTTPURLResponse, httpResponse.statusCode == 200 else {
fatalError("HTTP error! status: \((response as? HTTPURLResponse)?.statusCode ?? 0)")
}
}
task.resume()
sleep(1)
use std::env;
use reqwest;
#[tokio::main]
async fn main() -> Result<(), reqwest::Error> {
let block_id = env::var("BLOCK_ID").expect("BLOCK_ID must be set");
let token = env::var("NOTION_TOKEN").expect("NOTION_TOKEN must be set");
let url = format!("https://api.notion.com/v1/blocks/{}", block_id);
let client = reqwest::Client::new();
let response = client
.delete(&url)
.header("Authorization", format!("Bearer {}", token))
.header("Notion-Version", "2022-06-28")
.send()
.await?;
if !response.status().is_success() {
panic!("HTTP error! status: {}", response.status());
}
Ok(())
}
using System;
using System.Net.Http;
using System.Threading.Tasks;
class Program
{
static async Task Main()
{
var blockId = Environment.GetEnvironmentVariable("BLOCK_ID");
var token = Environment.GetEnvironmentVariable("NOTION_TOKEN");
var client = new HttpClient();
client.DefaultRequestHeaders.Add("Authorization", $"Bearer {token}");
client.DefaultRequestHeaders.Add("Notion-Version", "2022-06-28");
var url = $"https://api.notion.com/v1/blocks/{blockId}";
var response = await client.DeleteAsync(url);
if (!response.IsSuccessStatusCode)
{
throw new Exception($"HTTP error! status: {response.StatusCode}");
}
}
}