It been few days that I'm trying to make my request work but with no success. In react, I would like to do a search request with a genre filter as param, I can normally do it as mentioned in the docmentationtext
When typing the name of any band in the search field, if it is in the genre that I have pre-selected (e.g. rock) it will appear, otherwise nothing happens.
with this code, all tunes, even those of the wrong genre, appear.
Thanks in advance for your help
here is me code snippet:
const search = async (accessToken: string | null, searchValue: string, musicalGenre?: string[]) => {
const listOfMusicalGenre = musicalGenre?.join('%3A');
const queryParams = new URLSearchParams({
q: `${encodeURIComponent(searchValue)}%20genre%3A${listOfMusicalGenre}`,
type: 'track,artist',
market: 'FR'
});
try {
const response = await fetch(`https://api.spotify.com/v1/search?${queryParams}`, {
method: 'GET',
headers: {
'Authorization': `Bearer ${accessToken}`,
},
});
const data = await response.json();
return data;
} catch (error) {
console.error('Error fetching available genres:', error);
}
};