Qaynaq LABS · TOOLS

CURL → CODE · GET · BEARER

cURL → 10 languages

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

Source cURL
curl -X GET https://api.notion.com/v1/pages/page_id/children \
  -H "Authorization: Bearer secret_1234567890" \
  -H "Notion-Version: 2022-06-28"

Python · requests

import os
import requests

PAGE_ID = os.environ.get("PAGE_ID")
NOTION_TOKEN = os.environ.get("NOTION_TOKEN")
NOTION_VERSION = "2022-06-28"

url = f"https://api.notion.com/v1/pages/{PAGE_ID}/children"
headers = {
    "Authorization": f"Bearer {NOTION_TOKEN}",
    "Notion-Version": NOTION_VERSION
}

response = requests.get(url, headers=headers)
response.raise_for_status()
print(response.json())

Python · httpx

import os
import httpx

PAGE_ID = os.environ.get("PAGE_ID")
NOTION_TOKEN = os.environ.get("NOTION_TOKEN")
NOTION_VERSION = "2022-06-28"

url = f"https://api.notion.com/v1/pages/{PAGE_ID}/children"
headers = {
    "Authorization": f"Bearer {NOTION_TOKEN}",
    "Notion-Version": NOTION_VERSION
}

with httpx.Client() as client:
    response = client.get(url, headers=headers)
    response.raise_for_status()
    print(response.json())

Node.js · fetch

const fetch = require('node-fetch');

const PAGE_ID = process.env.PAGE_ID;
const NOTION_TOKEN = process.env.NOTION_TOKEN;
const NOTION_VERSION = '2022-06-28';

const url = `https://api.notion.com/v1/pages/${PAGE_ID}/children`;
const headers = {
  'Authorization': `Bearer ${NOTION_TOKEN}`,
  'Notion-Version': NOTION_VERSION
};

fetch(url, { method: 'GET', headers })
  .then(res => {
    if (!res.ok) throw new Error(`HTTP error! status: ${res.status}`);
    return res.json();
  })
  .then(data => console.log(data))
  .catch(err => console.error(err));

Node.js · axios

const axios = require('axios');

const PAGE_ID = process.env.PAGE_ID;
const NOTION_TOKEN = process.env.NOTION_TOKEN;
const NOTION_VERSION = '2022-06-28';

const url = `https://api.notion.com/v1/pages/${PAGE_ID}/children`;
const headers = {
  'Authorization': `Bearer ${NOTION_TOKEN}`,
  'Notion-Version': NOTION_VERSION
};

axios.get(url, { headers })
  .then(response => {
    console.log(response.data);
  })
  .catch(error => {
    console.error(error);
  });

Go · net/http

package main

import (
	"fmt"
	"log"
	"net/http"
	"os"
)

func main() {
	pageID := os.Getenv("PAGE_ID")
	notionToken := os.Getenv("NOTION_TOKEN")
	notionVersion := "2022-06-28"

	url := fmt.Sprintf("https://api.notion.com/v1/pages/%s/children", pageID)
	req, err := http.NewRequest("GET", url, nil)
	if err != nil {
		log.Fatal(err)
	}

	req.Header.Set("Authorization", "Bearer "+notionToken)
	req.Header.Set("Notion-Version", notionVersion)

	client := &http.Client{}
	resp, err := client.Do(req)
	if err != nil {
		log.Fatal(err)
	}
	defer resp.Body.Close()

	if resp.StatusCode != http.StatusOK {
		log.Fatalf("HTTP error! status: %s", resp.Status)
	}

	// Optionally decode JSON response here
	fmt.Println(resp.Body)
}

PHP · cURL

<?php
$pageId = getenv('PAGE_ID');
$notionToken = getenv('NOTION_TOKEN');
$notionVersion = '2022-06-28';

$url = "https://api.notion.com/v1/pages/{$pageId}/children";
$headers = [
    'Authorization: Bearer ' . $notionToken,
    'Notion-Version: ' . $notionVersion
];

$ch = curl_init($url);
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);

$response = curl_exec($ch);
if (curl_errno($ch)) {
    die('Error: ' . curl_error($ch));
}
$httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
if ($httpCode !== 200) {
    die("HTTP error! status: {$httpCode}");
}
curl_close($ch);

$decoded = json_decode($response, true);
print_r($decoded);

Ruby · net/http

require 'net/http'
require 'json'

page_id = ENV['PAGE_ID']
notion_token = ENV['NOTION_TOKEN']
notion_version = '2022-06-28'

uri = URI("https://api.notion.com/v1/pages/#{page_id}/children")
req = Net::HTTP::Get.new(uri)
req['Authorization'] = "Bearer #{notion_token}"
req['Notion-Version'] = notion_version

res = Net::HTTP.start(uri.hostname, uri.port, use_ssl: true) do |http|
  http.request(req)
end

unless res.is_a?(Net::HTTPSuccess)
  raise "HTTP error! status: #{res.code}"
end

puts JSON.parse(res.body)

Swift · URLSession

import Foundation

let pageId = ProcessInfo.processInfo.environment["PAGE_ID"] ?? ""
let notionToken = ProcessInfo.processInfo.environment["NOTION_TOKEN"] ?? ""
let notionVersion = "2022-06-28"

let url = URL(string: "https://api.notion.com/v1/pages/" + pageId + "/children")!
var request = URLRequest(url: url)
request.httpMethod = "GET"
request.setValue("Bearer \(notionToken)", forHTTPHeaderField: "Authorization")
request.setValue(notionVersion, forHTTPHeaderField: "Notion-Version")

let task = URLSession.shared.dataTask(with: request) { data, response, error in
    if let error = error {
        print("Error: \(error)")
        return
    }
    guard let httpResponse = response as? HTTPURLResponse else {
        print("Invalid response")
        return
    }
    guard (200...299).contains(httpResponse.statusCode) else {
        print("HTTP error! status: \(httpResponse.statusCode)")
        return
    }
    if let data = data, let json = try? JSONSerialization.jsonObject(with: data) as? [String: Any] {
        print(json)
    }
}
task.resume()

// Keep the program running to allow async task to complete
RunLoop.main.run()

Rust · reqwest

use std::env;
use reqwest;
use serde_json::Value;

#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
    let page_id = env::var("PAGE_ID")?;
    let notion_token = env::var("NOTION_TOKEN")?;
    let notion_version = "2022-06-28";

    let url = format!("https://api.notion.com/v1/pages/{}/children", page_id);
    let client = reqwest::Client::new();
    let response = client
        .get(&url)
        .header("Authorization", format!("Bearer {}", notion_token))
        .header("Notion-Version", notion_version)
        .send()
        .await?;

    if !response.status().is_success() {
        return Err(format!("HTTP error! status: {}", response.status()).into());
    }

    let json: Value = response.json().await?;
    println!("{}", json);
    Ok(())
}

C# · HttpClient

using System;
using System.Net.Http;
using System.Threading.Tasks;

class Program
{
    static async Task Main()
    {
        var pageId = Environment.GetEnvironmentVariable("PAGE_ID");
        var notionToken = Environment.GetEnvironmentVariable("NOTION_TOKEN");
        var notionVersion = "2022-06-28";

        var url = $"https://api.notion.com/v1/pages/{pageId}/children";
        var client = new HttpClient();
        client.DefaultRequestHeaders.Add("Authorization", $"Bearer {notionToken}");
        client.DefaultRequestHeaders.Add("Notion-Version", notionVersion);

        var response = await client.GetAsync(url);
        if (!response.IsSuccessStatusCode)
        {
            throw new Exception($"HTTP error! status: {response.StatusCode}");
        }

        var content = await response.Content.ReadAsStringAsync();
        Console.WriteLine(content);
    }
}

Translation notes

  • All implementations read secrets from environment variables (PAGE_ID, NOTION_TOKEN).
  • Python uses requests/httpx, Node.js 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 and raises/throws on failure.
  • URLs are constructed with placeholders for PAGE_ID from env vars.
  • Headers are set exactly as in the cURL command.

Common pitfalls when porting

  • Forgetting to set PAGE_ID or NOTION_TOKEN in environment variables will cause runtime errors.
  • In Go, ensure the HTTP client is properly closed or reused (here it's created per request).
  • In Swift, the async task requires the main run loop to keep the program alive for the response.
  • In Rust, the reqwest client requires the tokio runtime for async operations.
  • In PHP, ensure curl is installed and enabled in the PHP environment.
  • In Python, httpx requires Python 3.7+ for async support.

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 prevent secrets from being committed to version control and allow for different configurations across environments (dev, staging, prod).

How do I handle pagination in the response?

The Notion API may return paginated results. Check the response for a 'next_cursor' field and make subsequent requests with the cursor parameter.

Why is the URL constructed with ${PAGE_ID} in Python but PAGE_ID in other languages?

Python uses f-strings for string interpolation, while other languages use different syntax (e.g., Go uses fmt.Sprintf, Node.js uses template literals).

How do I add query parameters to the request?

Append query parameters to the URL (e.g., `https://api.notion.com/v1/pages/{page_id}/children?page_size=100`) or use the appropriate method in the library (e.g., `params` in Python requests).