Jamming step 94: Unexpected use of 'name' no-restricted-globals

Hey there,

I was working on POST request which would create new playlist. I have a weird to me error which I tried to google and find a solution but I think I do not understand it properly. Below is the method in which when i try to use “name” like this “body: JSON.stringify({ name: name })” react fails to compile.

I don’t get what am i supposed to replace “name” with since it is appreciated by JS in general. In the video tutorial mentor uses exactly body: JSON.stringify({ name: name })".

PLease advice. I’m stuck again.

	savePlaylist(playListName, arrayOfTrackURI) {
		if (!playListName || !arrayOfTrackURI.length) {
		const accessToken = Spotify.getAccessToken();
		const headers = { Authorization: `Bearer ${accessToken}` };
		let userId;
		return fetch("https://api.spotify.com/v1/me", { headers: headers }).then(
			(resp) =>
				resp.json().then((jsonResp) => {
					userId = jsonResp.id;
					return fetch(`https://api.spotify.com/v1/users/${userId}/playlists`, {
						headers: headers,
						method: "POST",
						body: JSON.stringify({ name: name }),
						.then((resp) => resp.json())
						.then((jsonResp) => {
							const playListId = jsonResp.id;
							return fetch();

Hi there, me again…

What is name? I cannot see that you defined it anywhere. And the parameter names don’t match with what you pass as the value ‘name’ to the object assigned to the body.

@mirja_t just by asking your counter-question you made me think and find the issue :slight_smile: indeed I was supposed to define it in the method parameter. I didn’t :slight_smile:

Thank you so much @mirja_t.

1 Like