diff options
Diffstat (limited to 'docs/pages/api/user')
| -rw-r--r-- | docs/pages/api/user/[id].tsx | 36 |
1 files changed, 36 insertions, 0 deletions
diff --git a/docs/pages/api/user/[id].tsx b/docs/pages/api/user/[id].tsx new file mode 100644 index 0000000..091d716 --- /dev/null +++ b/docs/pages/api/user/[id].tsx @@ -0,0 +1,36 @@ +import { NextApiRequest, NextApiResponse } from "next"; +import { withSentry } from "@sentry/nextjs"; +import { + getSubscriber, + Subscriber, + updateSubscriber, +} from "../../../lib/ConvertKitApi"; + +async function handler(req: NextApiRequest, res: NextApiResponse) { + try { + if (req.method === "PUT") { + const subscriber = await updateSubscriber( + req.query.id as string, + { + first_name: req.body.first_name, + email_address: req.body.email_address, + fields: req.body.fields, + } as Subscriber + ); + res.setHeader("Content-Type", "application/json"); + res.statusCode = 204; + res.json(subscriber); + } else { + const subscriber = await getSubscriber(req.query.id as string); + res.setHeader("Content-Type", "application/json"); + res.statusCode = 200; + res.json(subscriber); + } + } catch (error) { + console.log(error); + res.statusCode = 500; + res.json({ okay: false }); + } +} + +export default withSentry(handler); |
