I’m working with the Notion API to fetch content from my workspace page. My setup includes proper authentication headers and the correct page ID, but when I run my Swift code, nothing prints to the console. The URLSession request seems to execute without throwing errors, but I’m not getting any visible output.
import Foundation
struct NotionPage: Codable {
let object: String
let id: String
}
let pageURL = URL(string: "https://api.notion.com/v1/pages/your-page-id-here")
let authToken = "secret_your_token_here"
func fetchNotionData() {
guard let url = pageURL else { return }
var request = URLRequest(url: url)
request.setValue("Bearer \(authToken)", forHTTPHeaderField: "Authorization")
request.setValue("2022-06-28", forHTTPHeaderField: "Notion-Version")
let dataTask = URLSession.shared.dataTask(with: request) { responseData, urlResponse, requestError in
if let error = requestError {
print("Network error occurred: \(error.localizedDescription)")
return
}
guard let httpResponse = urlResponse as? HTTPURLResponse else {
print("Invalid response type")
return
}
print("Status code: \(httpResponse.statusCode)")
if let data = responseData {
if let jsonString = String(data: data, encoding: .utf8) {
print("Raw response: \(jsonString)")
}
do {
let decodedPage = try JSONDecoder().decode(NotionPage.self, from: data)
print("Page ID: \(decodedPage.id)")
} catch {
print("JSON parsing failed: \(error)")
}
}
}
dataTask.resume()
}
fetchNotionData()
I’ve double-checked my integration token permissions and page access rights. The request should work according to the official API docs but I’m not seeing any console output. Has anyone encountered similar issues with Notion API calls in Swift?