API Not working in POSTMAN but working internally.
Unanswered
Transvaal lion posted this in #help-forum
Transvaal lionOP
Can anyone offer an explanation or a solution to why this is happening?
Whenever i try to make a request to the app router's api using POSTMAN, i seem to get an error stating "Unexpected number in JSON at position 1" within the nextjs console and a 500 error.
it seems the issue lies within this section "const { shared_list_id, resource_id } = json" since when i remove it, it returns a 200 status code response.
Here is my the route method
export async function POST(req: Request) {
try {
// const currentUser = await getCurrentUserAction("db");
// if (!currentUser || !currentUser.id) {
// return new Response("Unauthorized", { status: 401 });
// }
const json = await req.json();
const { shared_list_id, resource_id } = json;
const alreadyInSharedResource = await findSharedResourceAction(
shared_list_id,
resource_id
);
if (alreadyInSharedResource) {
return new Response("Already in watchlist", { status: 409 });
}
console.log(shared_list_id, resource_id);
const createSharedResource = await createSharedResourceAction({
resource_id: resource_id,
shared_list_id: shared_list_id,
});
console.log(createSharedResource);
if (!createSharedResource) {
return new Response("Something went wrong", { status: 500 });
}
return new Response("Shared list created", { status: 200 });
} catch (error) {
console.log(error);
return new Response("Something went wrong", { status: 500 });
}
}
Whenever i try to make a request to the app router's api using POSTMAN, i seem to get an error stating "Unexpected number in JSON at position 1" within the nextjs console and a 500 error.
it seems the issue lies within this section "const { shared_list_id, resource_id } = json" since when i remove it, it returns a 200 status code response.
Here is my the route method
export async function POST(req: Request) {
try {
// const currentUser = await getCurrentUserAction("db");
// if (!currentUser || !currentUser.id) {
// return new Response("Unauthorized", { status: 401 });
// }
const json = await req.json();
const { shared_list_id, resource_id } = json;
const alreadyInSharedResource = await findSharedResourceAction(
shared_list_id,
resource_id
);
if (alreadyInSharedResource) {
return new Response("Already in watchlist", { status: 409 });
}
console.log(shared_list_id, resource_id);
const createSharedResource = await createSharedResourceAction({
resource_id: resource_id,
shared_list_id: shared_list_id,
});
console.log(createSharedResource);
if (!createSharedResource) {
return new Response("Something went wrong", { status: 500 });
}
return new Response("Shared list created", { status: 200 });
} catch (error) {
console.log(error);
return new Response("Something went wrong", { status: 500 });
}
}