laconic.com/src/pages/api/inquiry.ts
Fede Álvarez 08c938de76
Work on forms (#76)
* Work on connecting forms
2022-06-15 19:03:44 +02:00

56 lines
1.4 KiB
TypeScript

import { NextApiRequest, NextApiResponse } from 'next'
import { internalServerError, success } from '../../lib/api-responses'
import { notionAlt } from '../../lib/notion'
export default async (req: NextApiRequest, res: NextApiResponse) => {
try {
const { name, email, message, inquiry, role, company, jurisdiction } =
JSON.parse(req.body)
await notionAlt.pages.create({
parent: {
database_id: '90a7d71e342f4b91b7ca263a14d839ea' as string
},
properties: {
Name: {
title: [
{
text: {
content: name
}
}
]
},
Email: {
email,
type: 'email'
},
Message: {
type: 'rich_text',
rich_text: [{ text: { content: message }, type: 'text' }]
},
Role: {
type: 'rich_text',
rich_text: [{ text: { content: role }, type: 'text' }]
},
Company: {
type: 'rich_text',
rich_text: [{ text: { content: company }, type: 'text' }]
},
'Legal jurisdiction': {
type: 'rich_text',
rich_text: [{ text: { content: jurisdiction }, type: 'text' }]
},
Inquiry: {
type: 'select',
select: { name: inquiry }
}
}
})
success(res)
} catch (error) {
internalServerError(res, error)
}
}