import os
import requests
response = requests.get(
f"https://api.notion.com/v1/databases/{os.environ['DATABASE_ID']}/query",
headers={
"Authorization": f"Bearer {os.environ['NOTION_API_KEY']}",
"Notion-Version": "2022-06-28"
}
)
response.raise_for_status()
data = response.json()
import os
import httpx
with httpx.Client() as client:
response = client.get(
f"https://api.notion.com/v1/databases/{os.environ['DATABASE_ID']}/query",
headers={
"Authorization": f"Bearer {os.environ['NOTION_API_KEY']}",
"Notion-Version": "2022-06-28"
}
)
response.raise_for_status()
data = response.json()
import fetch from 'node-fetch';
import { config } from 'dotenv';
config();
const response = await fetch(
`https://api.notion.com/v1/databases/${process.env.DATABASE_ID}/query`,
{
method: 'GET',
headers: {
'Authorization': `Bearer ${process.env.NOTION_API_KEY}`,
'Notion-Version': '2022-06-28'
}
}
);
if (!response.ok) {
throw new Error(`HTTP error! status: ${response.status}`);
}
const data = await response.json();
import axios from 'axios';
import { config } from 'dotenv';
config();
const response = await axios.get(
`https://api.notion.com/v1/databases/${process.env.DATABASE_ID}/query`,
{
headers: {
'Authorization': `Bearer ${process.env.NOTION_API_KEY}`,
'Notion-Version': '2022-06-28'
}
}
);
const data = response.data;
package main
import (
"fmt"
"log"
"net/http"
"os"
)
func main() {
databaseID := os.Getenv("DATABASE_ID")
apiKey := os.Getenv("NOTION_API_KEY")
req, err := http.NewRequest(
"GET",
fmt.Sprintf("https://api.notion.com/v1/databases/%s/query", databaseID),
nil,
)
if err != nil {
log.Fatal(err)
}
req.Header.Set("Authorization", fmt.Sprintf("Bearer %s", apiKey))
req.Header.Set("Notion-Version", "2022-06-28")
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)
}
// Handle response body as needed
}
<?php
$databaseId = getenv('DATABASE_ID');
$apiKey = getenv('NOTION_API_KEY');
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, "https://api.notion.com/v1/databases/{$databaseId}/query");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "GET");
curl_setopt($ch, CURLOPT_HTTPHEADER, [
"Authorization: Bearer {$apiKey}",
"Notion-Version: 2022-06-28"
]);
$response = curl_exec($ch);
$httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
curl_close($ch);
if ($httpCode !== 200) {
throw new Exception("HTTP error! status: {$httpCode}");
}
$data = json_decode($response, true);
require 'net/http'
require 'json'
require 'uri'
uri = URI.parse("https://api.notion.com/v1/databases/#{ENV['DATABASE_ID']}/query")
http = Net::HTTP.new(uri.host, uri.port)
http.use_ssl = true
request = Net::HTTP::Get.new(uri)
request['Authorization'] = "Bearer #{ENV['NOTION_API_KEY']}"
request['Notion-Version'] = '2022-06-28'
response = http.request(request)
unless response.is_a?(Net::HTTPSuccess)
raise "HTTP error! status: #{response.code}"
end
data = JSON.parse(response.body)
import Foundation
let databaseId = ProcessInfo.processInfo.environment["DATABASE_ID"] ?? ""
let apiKey = ProcessInfo.processInfo.environment["NOTION_API_KEY"] ?? ""
let url = URL(string: "https://api.notion.com/v1/databases/" + databaseId + "/query")!
var request = URLRequest(url: url)
request.httpMethod = "GET"
request.setValue("Bearer " + apiKey, 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(error.localizedDescription)
}
guard let httpResponse = response as? HTTPURLResponse,
(200...299).contains(httpResponse.statusCode) else {
fatalError("HTTP error! status: \(response?.description ?? "unknown")")
}
if let data = data,
let json = try? JSONSerialization.jsonObject(with: data) as? [String: Any] {
print(json)
}
}
task.resume()
RunLoop.main.run()
use reqwest;
use std::env;
#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
let database_id = env::var("DATABASE_ID")?;
let api_key = env::var("NOTION_API_KEY")?;
let client = reqwest::Client::new();
let response = client
.get(format!("https://api.notion.com/v1/databases/{}/query", database_id))
.header("Authorization", format!("Bearer {}", api_key))
.header("Notion-Version", "2022-06-28")
.send()
.await?;
if !response.status().is_success() {
return Err(format!("HTTP error! status: {}", response.status()).into());
}
let data = response.json::<serde_json::Value>().await?;
println!("{:?}", data);
Ok(())
}
using System;
using System.Net.Http;
using System.Threading.Tasks;
class Program
{
static async Task Main()
{
var databaseId = Environment.GetEnvironmentVariable("DATABASE_ID");
var apiKey = Environment.GetEnvironmentVariable("NOTION_API_KEY");
using var client = new HttpClient();
client.DefaultRequestHeaders.Add("Authorization", $"Bearer {apiKey}");
client.DefaultRequestHeaders.Add("Notion-Version", "2022-06-28");
var response = await client.GetAsync($"https://api.notion.com/v1/databases/{databaseId}/query");
response.EnsureSuccessStatusCode();
var data = await response.Content.ReadAsStringAsync();
Console.WriteLine(data);
}
}