Skip to content

Instantly share code, notes, and snippets.

@fbegue
Last active July 11, 2024 22:25
Show Gist options
  • Save fbegue/8ad6afb9a72dfced22b06f1bc7c29622 to your computer and use it in GitHub Desktop.
Save fbegue/8ad6afb9a72dfced22b06f1bc7c29622 to your computer and use it in GitHub Desktop.
spotify_api_concerts_opester_fork
{
"data": {
"artistUnion": {
"goods": {
"events": {
"concerts": {
"items": [
{
"artistsV2": {
"items": [
{
"data": {
"profile": {
"name": "Charley Crockett"
}
}
},
{
"data": {
"profile": {
"name": "Lee Fields"
}
}
}
]
},
"date": {
"isoString": "2024-06-27T19:00-07:00"
},
"nearUser": false,
"title": "Charley Crockett: $10 Cowboy Tour",
"uri": "spotify:concert:0yG7gMZz6oq5onHJ3tA48E",
"venue": {
"location": {
"name": "Woodinville"
},
"name": "Chateau Ste Michelle Winery"
}
},
"and so on ..."
]
},
"userLocation": {
"name": "Cleveland"
}
}
},
"profile": {
"name": "Charley Crockett"
},
"uri": "spotify:artist:3BJX1nYizKvWpZTY5HOAr4",
"visuals": {
"headerImage": {
"extractedColors": {
"colorDark": {
"hex": "#0082A0"
}
},
"sources": [
{
"height": 1140,
"url": "https://i.scdn.co/image/ab67618600001016899bda1fd6bbd4cb2bfbfb6d",
"width": 2660
}
]
}
}
}
},
"extensions": {}
}
//spotify_songkick_api_opester_fork.js
import fs from 'fs'
import fetch from 'node-fetch';
let fetch_response_output_filename = "direct-events-charley-crockett.json"
//TODO: add artistId extraction to sha extraction below
// adjust song artist to get concerts for different artists
let artistId = "3BJX1nYizKvWpZTY5HOAr4"
let variables = encodeURIComponent(JSON.stringify({
"artistId": `spotify:artist:${artistId}`
}))
// you dont really need to adjust this. that still works even with the same sha key and different artists
// to get your sha256Hash value, copy in fetch query URL and extract code from there
//let fetch_str = "https://api-partner.spotify.com/pathfinder/v1/query?operationName=artistConcerts&variables=%7B%22artistId%22%3A%22spotify%3Aartist%3A3BJX1nYizKvWpZTY5HOAr4%22%7D&extensions=%7B%22persistedQuery%22%3A%7B%22version%22%3A1%2C%22sha256Hash%22%3A%22ce78fdb28c5036de6d81bbc45571b62e2201a0c08eb068ab17dd3428396026f5%22%7D%7D";
let fetch_str = "Your_Request_URL_Value"
// Remove all text before "sha"
let sha256Hash = fetch_str.substring(fetch_str.indexOf("sha"));
// Remove specific substrings
sha256Hash = sha256Hash.replace("%22%3A%22", "").replace("%22%7D%7D", "").replace("sha256Hash", "");
let extension = encodeURIComponent(JSON.stringify({ "persistedQuery": { "version": 1, "sha256Hash": `${sha256Hash}`}}))
let operation = "artistConcerts"
let authorization = "<Your_Authorization_Value>"
let client_token = "<Your_Client-Token_Value>"
fetch(`https://api-partner.spotify.com/pathfinder/v1/query?operationName=${operation}&variables=${variables}&extensions=${extension}`, {
"headers": {
"accept": "application/json",
"accept-language": "en",
"app-platform": "WebPlayer",
"cache-control": "no-cache",
"authorization": `${authorization}`,
"client-token": `${client_token}`,
"content-type": "application/json;charset=UTF-8",
"pragma": "no-cache",
"priority": "u=1, i",
"sec-ch-ua": "\"Not/A)Brand\";v=\"8\", \"Chromium\";v=\"126\", \"Google Chrome\";v=\"126\"",
"sec-ch-ua-mobile": "?0",
"sec-ch-ua-platform": "\"Windows\"",
"sec-fetch-dest": "empty",
"sec-fetch-mode": "cors",
"sec-fetch-site": "same-site",
"spotify-app-version": "1.2.41.282.g67f2a22e",
"Referer": "https://open.spotify.com/",
"Referrer-Policy": "strict-origin-when-cross-origin"
},
"body": null,
"method": "GET"
})
.then(response => response.json())
.then(data => {
console.log(data)
fs.writeFileSync(`${fetch_response_output_filename}`, JSON.stringify(
data
, null, 2))
})

spotify_songkick_api_opester_fork.md

You need to use spotify.com in the browser to fetch security bits, therefore the script is "unstable" and will fail if Spotify decides to change the way their requests work

directions

  • Open Spotify in browser
  • Login
  • open developer console network tab
  • on page, click on artist - example URL: https://open.spotify.com/artist/3BJX1nYizKvWpZTY5HOAr4
  • on page, click on "View all upcoming concerts"
  • in network tab, search for "artistConcerts"
  • fetch_str: from Headers tab, copy Request URL value
  • authorization and client_token: from Headers tab, copy Authorization and Client-Token values

credit

opester https://www.reddit.com/r/webdev/comments/wtahj0/comment/la18boo/?context=3 https://gitlab.com/-/snippets/3721862

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment