How to Retrieve Data in Multiple Locales from a Single API Endpoint?

Hello everyone,

I’m working with an API where I need to fetch home data in both Spanish and English using a single endpoint. Currently, I have the following code:

async getHome(){
try{
const config = {
method: ‘GET’,
params: {
‘populate[0]’: ‘header.logo’,
‘populate[1]’: ‘header.menuLinks.headerLinks’,
‘populate[2]’: ‘header.icons’,
‘populate[3]’: ‘banner.button’,
‘populate[4]’: ‘grid.button’,
‘populate[5]’: ‘testimonials’,
‘populate[6]’: ‘footer.footerLinks’,
‘locale’: ‘es’, // This line fetches data in Spanish
‘locale’: ‘en’, // This line fetches data in English
},
headers: {
‘Content-Type’: ‘application/json’
}
};
const response = await api(‘/api/home’, config);
const homeData = response.data;

    this.headerIcons = homeData.data.header.icons;
    this.headerLogo = homeData.data.header.logo;
    this.headerMenu = homeData.data.header.menuLinks; 

    console.log('home data:', homeData);
    return homeData;
    
} catch(error){
    console.log('Error fetching home data:', error);
    throw error;
}   

}

This topic has been created from a Discord post (1295334410572533770) to give it more visibility.
It will be on Read-Only mode here.
Join the conversation on Discord