Notion API: I can't figure out how to create a page?

So I’m making a bug reporting system with the Notion API, but their API is overcomplicated and their documentation is lacking.

So how would I create a page please?

Here’s my current code:

function nuuh.newPage(parent_id: string, properties: {title: string, username: string, status: "to review" | "in progress" | "accepted" | nil, description: string})
	local success, response = pcall(function() -- requests data
		return HttpService:RequestAsync(
			{Url = string.format("%s/pages/", settings.API.Link),
				Method = "POST",
				Headers = {
					["Content-Type"] = "application/json",
					["Authorization"] = "Bearer " .. settings.auth.token,
					["Notion-Version"] = settings.API.Version},
				Body = HttpService:JSONEncode({
					parent = {
						database_id = parent_id
					},
					properties = {
						title = {
							title = {{
								text = {
									content = properties.title
								}
							}}
						},
						username = {
							rich_text = {{
								text = {
									content = properties.username
								}
							}}
						},
						status = {
							status = {{
								text = {
									content = properties.status
								}
							}}
						},
						description = {
							rich_text = {{
								text = {
									content = properties.description
								}
							}}
						}
					}
				})
			})
	end)
	print(response)

	if response.StatusCode ~= 200 then -- If it fails error
		error(string.format("Cannot create page: Error code %s: %s", response.StatusCode, response.StatusMessage))
	end

	return HttpService:JSONDecode(response.Body)
end

And the error it returns:

["Body"] = "{"object":"error","status":400,"code":"validation_error","message":"body failed validation. Fix one:\nbody.properties.status.title should be defined, instead was `undefined`.\nbody.properties.status.rich_text should be defined, instead was `undefined`.\nbody.properties.status.number should be defined, instead was `undefined`.\nbody.properties.status.url should be defined, instead was `undefined`.\nbody.properties.status.select should be defined, instead was `undefined`.\nbody.properties.status.multi_select should be defined, instead was `undefined`.\nbody.properties.status.people should be defined, instead was `undefined`.\nbody.properties.status.email should be defined, instead was `undefined`.\nbody.properties.status.phone_number should be defined, instead was `undefined`.\nbody.properties.status.date should be defined, instead was `undefined`.\nbody.properties.status.checkbox should be defined, instead was `undefined`.\nbody.properties.status.relation should be defined, instead was `undefined`.\nbody.properties.status.files should be defined, instead was `undefined`.\nbody.properties.status.status should be an object or `null`, instead was `[{\"text\":{\"content\":\"to review\"}}]`.\nbody.properties.username.id should be defined, instead was `undefined`.\nbody.properties.username.name should be defined, instead was `undefined`.\nbody.properties.username.start should be defined, instead was `undefined`.","request_id":"e12b5ea3-76b8-435d-94b6-268ffa0fd45d"}",
                    ["Headers"] =  ▶ {...},
                    ["StatusCode"] = 400,
                    ["StatusMessage"] = "Bad Request",
                    ["Success"] = false
                 }

Basically, it’s asking you to include the properties listed in this page, since every database object must have fields id, name and type.

That’s for GET requests.

Also found my answer here:

I swear that there weren’t examples before.

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.