So here's my situation:
I upload a file and send it to an API then i get back a response with an object with some data in it. This is how i send it to the API:
apiRoute.post(async (req, res) => {
try {
const media_url = `${req.webhookBaseUrl}/media/${req.file.filename}`;
const webhook_url = `${req.webhookBaseUrl}/api/job`;
const job = await req.asyncClient.submitJobUrl(media_url, {
callback_url: webhook_url,
});
res.json(job);
} catch (error) {
console.dir(`Error: ${error}`);
res.status(500).json({ error });
}
});
Then i get the response here on my Nextjs api route like this:
/api/job.js
export default async function handler(req, res) {
try {
const result = await req.body;
res.status(200).json({ result });
console.log("webhook received:", result);
} catch (err) {
res.status(500).send({ error: "failed to TRANSCRIBE data" });
}
}
so i get the object just fine in the terminal:
...now in the front end i use SWR to get this data but it always returns and empty string:
const jobFetcher = async (...args) => {
const response = await fetch(...args);
const jobData = await response.json();
console.log("JOB PREJ TE FETCHER", jobData);
return jobData;
};
const { data: job, error: jobError } = useSWR(`/api/job`, jobFetcher);
console.log("JOBBB", job);
What am i doing wrong here? Maybe i have to save the response to a storage or a state before i fetch it with SWR? If so, how to do it? Any clues? Thanks!