API route: 400
Unanswered
Alligator mississippiensis posted this in #help-forum
Alligator mississippiensisOP
Version: next 12
Folder structure: pages/api/cancel-subscription/index.js
(also tried to have [userId].js instead of index.js)
Axios code:
The axios has a base url of: "http://localhost:3000/api/"
Handler:
(cancelSubscriptionRecord is a function that has DB code)
Info:
When I tried to simple down this syntax, without adding a praram, it worked:
Folder structure: pages/api/cancel-subscription/index.js
(also tried to have [userId].js instead of index.js)
Axios code:
await axios.delete('cancel-subscription', {
params: {
userId,
},
});The axios has a base url of: "http://localhost:3000/api/"
Handler:
export default async function handler(req, res) {
const { userId } = req.query;
const response = await cancelSubscriptionRecord(userId);
res.status(200).json(response);
}(cancelSubscriptionRecord is a function that has DB code)
Info:
When I tried to simple down this syntax, without adding a praram, it worked:
export async function cancelSubscription(userId) {
try {
const response = await axios.delete('cancel-subscription');
return response;
} catch (error) {
console.error(error);
}
}
export default async function handler(req, res) {
res.status(200).json('hey');
}