i got this error TypeError
Cannot read property ‘id’ of undefined DETAILS
at Object.run (file:///tmp/__pdg__/dist/code/f4737dc552eaf5f0776659068a5808363db39e58cd4667c80cd22115d0345994/component.mjs:29:52)
at process.processTicksAndRejections (internal/process/task_queues.js:95:5)
at global.executeComponent (/var/task/launch_worker.js:225:22)
at MessagePort.messageHandler (/var/task/launch_worker.js:722:28)
I apologize for the error you encountered. It seems that the searchResponse.tracks.items[0] object is undefined, which means the search results might be empty or the response structure is different than expected. To handle this case, let’s add a check for the existence of the object before accessing its id property: import { axios } from "@pipedream/platform"; export default defineComponent({ async run({ steps }) { const trackName = steps.trigger.event.newRow[1]; const artistName = steps.trigger.event.newRow[4]; const accessToken = this.spotify.$auth.oauth_access_token; const searchResponse = await axios(this, { method: "GET", url: "https://api.spotify.com/v1/search", headers: { "Authorization": `Bearer ${accessToken}`, }, params: { q: `track:${trackName} artist:${artistName}`, type: "track", }, }); if (searchResponse.tracks.items.length > 0) { const trackId = searchResponse.tracks.items[0].id; return { trackId }; } else { console.log("No track found for the given search query."); return { message: "No track found for the given search query." }; } }, }); This code checks if there are any items in the search results before accessing the id property. If no items are found, it logs a message and returns a message indicating that no track was found.
I got this error when apply your code TypeError
Cannot read property ‘$auth’ of undefined DETAILS
at Object.run (file:///tmp/__pdg__/dist/code/b5f308ca849bb8f5278f83b9666296f0ff6ac7b06e35c67fed2e93a3df1c5e33/component.mjs:8:38)
at global.executeComponent (/var/task/launch_worker.js:225:53)
at MessagePort.messageHandler (/var/task/launch_worker.js:722:28)
I apologize for the oversight in my previous response. It seems I missed adding the props section to the component code, which includes the spotify app prop. Here’s the corrected code: import { axios } from "@pipedream/platform"; export default defineComponent({ props: { spotify: { type: "app", app: "spotify", }, }, async run({ steps }) { const trackName = steps.trigger.event.newRow[1]; const artistName = steps.trigger.event.newRow[4]; const accessToken = this.spotify.$auth.oauth_access_token; const searchResponse = await axios(this, { method: "GET", url: "https://api.spotify.com/v1/search", headers: { "Authorization": `Bearer ${accessToken}`, }, params: { q: `track:${trackName} artist:${artistName}`, type: "track", }, }); if (searchResponse.tracks.items.length > 0) { const trackId = searchResponse.tracks.items[0].id; return { trackId }; } else { console.log("No track found for the given search query."); return { message: "No track found for the given search query." }; } }, }); This code now includes the props section with the spotify app prop, which should resolve the error you encountered.