score:0

const fetchAllProducts = async () => {
        const  { data } = await axios.get('https://inventory.dearsystems.com/ExternalApi/v2/Product',{
            headers: {
                "api-auth-accountid": process.env.REACT_APP_API_ID,
                "api-auth-applicationkey": process.env.REACT_APP_API_KEY
              } 
        });

        const productsWithImage = data.Products
          .map(async product => {
            const imageUrl = await axios.get("https://inventory.dearsystems.com/ExternalApi/v2/product/attachments?ProductID=" + product.id)
            return {...product, imageUrl }
          })
        
        setContent(productsWithImage)
    }
    
// Then you can use product.imageUrl when you map your products

score:0

export const AllHandle = () => {

    const [content, setContent] = useState([]);

    const fetchAllProducts = async () => {
        
        const { data }  = await axios.get("https://inventory.dearsystems.com/ExternalApi/v2/Product?limit=10",{
            headers: {
                "api-auth-accountid": process.env.REACT_APP_API_ID,
                "api-auth-applicationkey": process.env.REACT_APP_API_KEY
              } 
        });
        let result = [];
        const totaProducts = await data.Products;

        for (let product of totaProducts) {
           
            const imageUrl = await axios.get(`https://inventory.dearsystems.com/ExternalApi/v2/product/attachments?ProductID=${product.ID}`, {
                headers: {
                    "api-auth-accountid": process.env.REACT_APP_API_ID,
                    "api-auth-applicationkey": process.env.REACT_APP_API_KEY
                  } 
              });
              
              const imgUrl = imageUrl.data
             
              result = [{ ...product, imgUrl}]
            }
           
            setContent(result)        
 }

 useEffect(() =>{
    fetchAllProducts();
}, [])   

 return (
    <div>
        <h1 className="pageTitle">All Products</h1>
        <div className="all">
            {content && content.map((c) => 
              
                <SingleContent 
                    key={c.ID} 
                    id={c.ID} 
                    name={c.Name} 
                    sku={c.SKU} 
                    category={c.Category}
                    attachment= { c.imgUrl[0].DownloadUrl}
                    />

                    )}
      
        </div>
    </div>
)

   
}

Related Query

More Query from same tag