Qaynaq LABS · TOOLS

CURL → CODE · DELETE · BEARER

cURL → 10 languages

DELETE api.notion.com · secrets replaced with env vars.

Source cURL
curl -X DELETE https://api.notion.com/v1/blocks/block_id \
  --header "Authorization: Bearer secret_1234567890" \
  --header "Notion-Version: 2022-06-28"

Python · requests

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()

Python · httpx

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()

Node.js · fetch

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;
}

Node.js · axios

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;
}

Go · net/http

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 · cURL

<?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}");
}

Ruby · net/http

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

Swift · URLSession

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)

Rust · reqwest

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(())
}

C# · HttpClient

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}");
        }
    }
}

Translation notes

  • All implementations use environment variables for secrets (NOTION_TOKEN, BLOCK_ID)
  • Python uses requests/httpx, Node uses fetch/axios, Go uses net/http, PHP uses cURL, Ruby uses Net::HTTP, Swift uses URLSession, Rust uses reqwest, C# uses HttpClient
  • Error handling checks HTTP status code and raises/throws on failure
  • URLs are constructed with environment variables for dynamic block IDs
  • Headers are set exactly as in the cURL command

Common pitfalls when porting

  • Forgetting to set environment variables (NOTION_TOKEN, BLOCK_ID) will cause runtime errors
  • In Swift, URLSession is asynchronous; the example uses sleep(1) for simplicity but real code should handle async properly
  • In Rust, the reqwest client requires async runtime (tokio in this example)
  • In PHP, curl_setopt must be used carefully to avoid security issues with raw output
  • In Go, http.Client may need custom timeouts for production use

About cURL → code translation

cURL is the lingua franca of API documentation: every vendor docs page ships a cURL snippet you can paste into a terminal and immediately see the API working. Translating that into your actual application code shouldn't be a 20-minute Stack-Overflow safari, but without a good translator it usually is.

Qaynaq Labs' cURL → code tool reads the full command — method, URL, headers, query params, body type, and auth — and emits idiomatic client code in 10 languages. Authentication goes through environment variables by default, request bodies become language-native data structures (not raw JSON strings), and minimal error handling is included.

Frequently asked

Why use environment variables instead of hardcoding secrets?

Environment variables separate configuration from code, reducing the risk of secret leakage in version control or logs. They also allow different configurations across environments (dev, staging, prod).

How do I handle pagination or large responses in these clients?

Most HTTP clients provide streaming or pagination helpers. For example, in Python requests you can use `response.iter_content()`, in Go you can read the response body incrementally, and in Rust you can use `bytes::Bytes` for streaming.

Can I reuse the HTTP client across multiple requests?

Yes, in most languages. For example, in Python httpx you can use a `Client` instance, in Go you can reuse the `http.Client`, and in C# you can reuse the `HttpClient`. Reusing clients improves performance by reusing connections.