Event Images

Let's learn to fetch and render images for events using the Discovery API.

The following are two approaches we can use to get images for an event:

  • Use the information stored in the images property of the response object.
  • Use the event images endpoint.

For now, let's try the first approach—getting the images through the images property of the event details object:

Press + to interact
import json
import requests
api_key = '{{API_KEY}}'
response = requests.get('https://app.ticketmaster.com/discovery/v2/events/{{EVENT_ID}}',
params = {
'apikey' : api_key,
}).json()
# getting the images array from the response
images_array = response['images']
# getting the url of the first image from the array
image_url = images_array[0]['url']
# rendering the image using html
print(f'<img src={image_url} width=500px>')

This call also fetches the entire event details object, not just the images. Additionally, the event details object can be quite large due to the embedded venue and attraction objects.

Let's take a look at the second approach that provides a more optimized solution to this problem—the Discovery API's event images endpoint.

The event images endpoint

The Discovery API provides an event images endpoint through which we can retrieve a list of images for any specified event. An overview of the endpoint is as follows:

The URL for this endpoint is as follows:

https://app.ticketmaster.com/discovery/v2/events/{id}/images

This endpoint takes the ID of an event as a required URL parameter, along with a couple of optional query parameters. An overview of all these parameters is as follows:

Parameter

Type

Category

Description

id

string

required

The ID of the event we want images for.

locale

string

optional

This is the locale in ISO code format. Multiple comma-separated values can be provided. When omitting the country part of the code (only en or fr) the first matching locale is used. When using *, it matches all locales. The default value is en.

domain

array[string]

optional

If provided, the results are filtered based on the domain they are available on.

As always, the response is in the form of a JSON object. Here is an overview of the keys of this object:

Property

Type

Description

_links

object

This contains a link to the current dataset.

type

string

The type of the entity. Since we're fetching images for events, the value, in this case is event.

id

string

The ID of the event.

images

array[object]

An array of objects, with each object containing the information for one event.

As you may have guessed, our main focus here is the images array. Within this array, an image is represented as an object. Let's look at the keys of this image object in detail:

Property

Type

Description

url

string

The public URL of the image.

ratio

enum['16_9', '3_2', '4_3']

The ratio of the image. There are only three allowable values: 16:9, 3:2, and 4:3.

width

integer

The width of the image.

height

integer

The height of the image.

fallback

boolean

Whether the image is a fallback image or not. It is true if it is not the event's image but instead a fallback image.

attribution

string

The attribution for the image.

Fetch and render images

Let's make a call to this endpoint using the event ID we've used in the previous examples:

Press + to interact
import json
import requests
api_key = '{{API_KEY}}'
response = requests.get('https://app.ticketmaster.com/discovery/v2/events/{{EVENT_ID}}/images',
params = {
'apikey' : api_key,
}).json()
print(json.dumps(response, indent=4))

Since we're interested in seeing the images for the event, the JSON output in the last example isn't ideal. Let's try rendering the images to the console using the url property in the image object.

You can also try changing the index on line 11 to print other images for the same event:

Note: The length of the images array varies across different responses, so you might get an IndexError for index values that are too large.

Press + to interact
import json
import requests
api_key = '{{API_KEY}}'
response = requests.get('https://app.ticketmaster.com/discovery/v2/events/{{EVENT_ID}}/images',
params = {
'apikey' : api_key,
}).json()
image_url = response['images'][0]['url']
print(f'<img src={image_url} width=500px>')

We've successfully fetched and rendered images for an event to the console.