Can't get my NODE backend response to come through on my react frontend

I’m having trouble getting my get project tasks API response into my react frontend even though it comes through in my node backend.

localhost:5000/get-tasks gets the tasks in the json response as well as my credentials.

I’m using this method for my backend

app.get("/get-tasks", (req, res) => {
  const client = getClient();
  const token = req.cookies.token;
  if (token) {
    client.useOauth({ credentials: token });

  
    client.workspaces.findAll().then((workspaces) => {
      if (!workspaces.data.length) {
        return res.end("No workspaces found");
      }

      
      client.tasks
        .getTasksForProject(projectGid, {
          param: "value",
          param: "value",
          opt_pretty: true,
        })
        .then((result) => {
          res.status(201).json((result));
                console.log(result);
            });
    });
  } else {
    res.redirect(client.app.asanaAuthorizeUrl());
  }
});

For my react frontend I’m using a useEffect and dataObject

 useEffect(() => {
  axios.get('http://localhost:5000/get-tasks').then(response => {
    const dataObject = response.data.data;
    

    console.log(dataObject);
    
  });
}, []);

when I do

useEffect(() => {
  axios.get('http://localhost:5000/get-tasks').then(response => {
    const dataObject = response.data;

In the console(log) I get a weird html response that doesn’t contain the tasks. Just a bunch of html and some french (which I don’t think is super relevant since google/chrome tends to switch languages on me)

I was wondering if anyone could help me solve why the response isn’t coming through.

Hi @marc.slc.bernard

Did you try accessing the Node API endpoint via Postman and see if the error still persists?

If not, there might be something on your React’s end (maybe CORS?) which is preventing you from accessing the endpoint?

Hope this points you in the right direction!

1 Like