Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Select an option

  • Save RussellBishop/4ed703591643b72014a431c7da3f69f9 to your computer and use it in GitHub Desktop.

Select an option

Save RussellBishop/4ed703591643b72014a431c7da3f69f9 to your computer and use it in GitHub Desktop.
Search Discogs via API
let inputConfig = input.config();
console.log(`The value of artistName is ${inputConfig.artistName}`);
console.log(`The value of releaseName is ${inputConfig.releaseName}`);
// Replace with your actual artist name, API token, and User-Agent
let artistName = inputConfig.artistName;
let releaseName = inputConfig.releaseName;
// let discogsToken = "YOUR_DISCOGS_TOKEN"; // Securely store and retrieve this via Airtable's secret manager if needed
let userAgent = "MyAirtableApp/1.0";
// Construct the API URL. Here we're using the search endpoint.
// Construct the Discogs API URL using consumer key and secret for authentication
let url = `https://api.discogs.com/database/search?q=${encodeURIComponent(releaseName)}&type=master&artist=${encodeURIComponent(artistName)}&key=KEY&secret=TOKEN`;
try {
// Make the HTTP request to the Discogs API
let response = await fetch(url, {
headers: {
"User-Agent": userAgent
}
});
// Check if the request was successful
if (!response.ok) {
throw new Error(`Request failed with status ${response.status}`);
}
// Parse the JSON response
let data = await response.json();
// Log or process the returned data
console.log("Discogs API response:", data);
// For example, if you wanted to update a record in your Airtable base with some of this data,
// you could add code here to use the Airtable API.
} catch (error) {
console.error("Error fetching data from Discogs:", error);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment