Including an Image with Your Event Listing
You can include a main image with your Event listing, for example to provide branding or further information on the Event, by uploading the image.
Including an image using the Eventbrite API involves the following steps:
1. Retrieve the upload instructions and an upload token from the API.
2. Upload the image file to the URL specified in the upload instructions.
3. When the upload has finished, notify the API by sending the upload token.
Authenticating Your Access to the Eventbrite API
Before including an image with your Event listing, you need to authenticate your access to the Eventbrite API. To learn how, refer to Authenticating Your Access.
Retrieving the Upload Token
To retrieve image upload token, go to the following URL:
https://www.eventbriteapi.com/v3/media/upload/?type=image-event-logo&token=PERSONAL_OAUTH_TOKEN
Example Response;
{
"upload_method": "POST",
"upload_token": "WA1HZ2ZTZULGNXBBTQ9BN3LR...",
"upload_url": "https://s3.amazonaws.com/eventbrite-uploader-incoming-prod/",
"upload_data": {
"AWSAccessKeyId": "AKIWAII7XBQ45Z756AUX",
"bucket": "eventbrite-uploader-incoming-prod",
"acl": "private",
"key": "3a0d45ffcfcf4d1bc0df0ee05ba34948",
"signature": "Bpogk9jowmy/h2E9/Hkdzxz4Wok=",
"policy": "BYEJJ25XRAKPB25IJWIRIDOXRBIZDLJPXZJBWMVVN..."
},
"file_parameter_name": "file"
}
The returned attributes have the following meaning
Attribute | Description |
---|---|
upload_data | POST data that should be included in the POST that uploads the image file. |
upload_url | URL to which the image file should be upload. |
upload_method | Method (always POST) that should be used to upload the image file. |
file_parameter_name | POST field that the image file should be included in (handled using HTTP multipart upload). |
upload_token | Token that is used in step 3 of the process of including an image file. Make note of the returned token. |
Uploading the Image File to the Specified URL
To upload the image, you can use the following request
Example request:
import requests, urllib
OAUTH_TOKEN = 'your-token-here'
MEDIA_UPLOAD_URL = 'https://www.eventbriteapi.com/v3/media/upload/'
def upload_file(filename):
instructions_url = MEDIA_UPLOAD_URL + '?' + urllib.urlencode({
'type': 'image-event-logo',
'token': OAUTH_TOKEN
})
data = requests.get(instructions_url).json()
post_args = data['upload_data']
response = requests.post(data['upload_url'],
data = post_args,
files = {
data['file_parameter_name']: open(filename)
}
)
return response, data['upload_token']
response, upload_token = upload_file('~/Pictures/test-image.jpg')
Notifying the API by Sending the Upload Token
Now that your image file has been successfully uploaded, you need to notify the
API of the upload. To do so, specify the upload token you got in step 1 (i.e.
the value of the upload_token
attribute), and include it as the
post-media-upload
endpoint. You will also need to include a crop_mask to avoid
defaulting to the old Eventbrite listing page layout. The crop mask needs to be
set to a ratio of 2:1.
Example request:
notify_url = MEDIA_UPLOAD_URL + '?' + urllib.urlencode({
'token': OAUTH_TOKEN
})
image_data = {'upload_token': upload_token, 'crop_mask': {'top_left': {'y':1, 'x':1}, 'width':1280, 'height':640}}
response = requests.post(notify_url, json=image_data)
An image
representing the image you have uploaded is returned.