Event Images
Let's learn to fetch and render images for events using the Discovery API.
We'll cover the following
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:
import jsonimport requestsapi_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 responseimages_array = response['images']# getting the url of the first image from the arrayimage_url = images_array[0]['url']# rendering the image using htmlprint(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 |
| string | required | The ID of the event we want images for. |
| 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 |
| 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 |
| object | This contains a link to the current dataset. |
| string | The type of the entity. Since we're fetching images for events, the value, in this case is |
| string | The ID of the event. |
| 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 |
| string | The public URL of the image. |
| 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. |
| integer | The width of the image. |
| integer | The height of the image. |
| boolean | Whether the image is a fallback image or not. It is |
| 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:
import jsonimport requestsapi_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 anIndexError
for index values that are too large.
import jsonimport requestsapi_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.