'Error 401 on API Platform for some requests

I try to request some information from API Platform with React.

This is my code to get all the Technics. It works perfectly fine, I got a status code 200. But when I try to do it with the Ingredients, it dosen't work and I don't know why. It's the exact same thing, except I got a status code 401.

Thanks for your help

const { user, updateUser } = useContext(LoginContext);
  let tech = new Array();
  const getAllTechnical = async () => {
    try {
      // TODO
      let technicalData = await fetchData(user.token, "/technicals");
      technicalData.forEach(element => {
        tech.push(new Array(element.technicalName, element.technicalDescription, "https://via.placeholder.com/150", "link"));
      });
      console.log(tech);
      
      return tech;
    } catch (error) {
      throw error;
    }
  };

The fetchData method

import axios from "axios";

export default async function fetchData(token, url = "") {
    axios.defaults.baseURL = "http://localhost:8000/api";
    try {
        const config = {
            headers: {
                Accept: "application/ld+json",
                Authorization: "Bearer " + token,
            },
        };

        let response = await axios.get(url, config);

        if (response.status === 200) {
            return response.data["hydra:member"];
        }
    } catch (error) {
        throw error;
    }
}

Error on Ingredient : GET http://localhost:8000/api/ingredients [HTTP/1.1 400 Bad Request 4311ms] Ingredient API Technical API



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source