Making the API Call: Code Examples

Now, let’s use this URL to fetch the data. Choose the language or tool you’re most comfortable with.

Remember to replace YOUR_API_KEY_HERE with your actual API key.

cURL (Command Line)

This is the quickest way to test an API endpoint directly from your terminal.

Bash

curl "https://api.showgiant.com/events?artistName=The+National&geoPostalCode=60601&geoRadiusAmount=50&apikey=YOUR_API_KEY_HERE"

Python (with requests library)

A popular choice for backend services. If you don’t have the requests library, install it with pip install requests.

Python

import requests

# Define the API endpoint and parameters
api_url = "https://api.showgiant.com/events"
api_key = "YOUR_API_KEY_HERE"

params = {
    'artistName': 'The National',
    'geoPostalCode': '60601',
    'geoRadiusAmount': '50',
    'apikey': api_key
}

# Make the API request
response = requests.get(api_url, params=params)

# Check if the request was successful
if response.status_code == 200:
    data = response.json()
    # Print the name of the first event found
    if data['events']:
        print(f"First event found: {data['events'][0]['eventName']}")
    else:
        print("No events found for this search.")
else:
    print(f"Error: {response.status_code}")
    print(response.text)

 

JavaScript (Node.js with fetch)

Perfect for building a backend service with Node.js.

JavaScript

async function getEvents() {
  const apiKey = 'YOUR_API_KEY_HERE';
  const artist = encodeURIComponent('The National');
  const postalCode = '60601';
  const radius = '50';

  const apiUrl = `https://api.showgiant.com/events?artistName=${artist}&geoPostalCode=${postalCode}&geoRadiusAmount=${radius}&apikey=${apiKey}`;

  try {
    const response = await fetch(apiUrl);
    if (!response.ok) {
      throw new Error(`HTTP error! status: ${response.status}`);
    }
    const data = await response.json();
    
    if (data.events && data.events.length > 0) {
      console.log(`First event found: ${data.events[0].eventName}`);
    } else {
      console.log('No events found for this search.');
    }
  } catch (error) {
    console.error('Error fetching data:', error);
  }
}

getEvents();

Security Warning: The following browser-based JavaScript example is for testing purposes only. Never expose your API key in client-side code in a public application. All production API calls should be made from a secure backend server.

JavaScript (Browser with fetch)

JavaScript

// FOR TESTING PURPOSES ONLY -- DO NOT USE IN PRODUCTION
const apiKey = 'YOUR_API_KEY_HERE'; 
const apiUrl = `https://api.showgiant.com/events?artistName=The+National&geoPostalCode=60601&geoRadiusAmount=50&apikey=${apiKey}`;

fetch(apiUrl)
  .then(response => response.json())
  .then(data => {
    console.log(data);
    // You can now use the 'data' object to display events on your page
  })
  .catch(error => console.error('Error:', error));