Im using Notions API to print out some data from one of my own pages in notion and im using URLSession to make the request then parsing the unwrapped data but nothing is being returned to my console and I know my endpoint and API key is correct. I've gone through the notion API documentation can't can't seem to find anything in it that I am not doing or doing wrong. Ill provide my code as well as the documentation I've been consulting: https://developers.notion.com/reference/intro
import Foundation
struct Page: Codable {
let id: String
let title: String
}
let endpoint = URL(string: "https://api.notion.com/v1/pages/8efc0ca3d9cc44fbb1f34383b794b817")
let apiKey = "… redacted …"
let session = URLSession.shared
func makeRequest() {
if let endpoint = endpoint {
let task = URLSession.shared.dataTask(with: endpoint) { data, response, error in
if let taskError = error {
print("could not establish url request:\(taskError)")
return
}
if let unwrapData = data { //safely unwrapping the data value using if let
do {
let decoder = JSONDecoder() //JSONDecoder method to decode api data,
let codeUnwrappedData = try decoder.decode(Page.self,from: unwrapData) //type: specifies its a struct, from: passes the data parmeter that contains the api data to be decoded
} catch {
print("could not parse json data")
}
}
if let httpResponse = response as? HTTPURLResponse {
if httpResponse.statusCode == 200 {
if let apiData = data {
print(String(data: apiData, encoding: .utf8)!)
}
} else {
print("unsuccessful http response:\(httpResponse)")
}
makeRequest()
}
}
task.resume()
}
}