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