MyBB Internal: One or more warnings occured. Please contact your administrator for assistance.
WebPagetest Forums - Defining custom hero via the API

WebPagetest Forums

Full Version: Defining custom hero via the API
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
I'm having trouble defining a custom hero via the API. I can get everything to work OK using the UI, but not the API. Here's my Python code:

# Prepare the post data
post_data = {'k': API_TOKEN,
'location': location,
'url': url,
'runs': 1,
'fvonly': 1,
#'debug': 1,
'keepua': 1,
'f': 'json',
'video': True,
'script': script,
'custom': '\n'.join(custom),
'heroElements': {"MWTEST":".product"}
}

# Make the request
response = requests.post(BASE_URL,
data=post_data,
timeout=10)

custom is a script - it runs OK and the output is in the results. heroElements works fine when I put the dict in the UI. But when I run this code, there's no custom hero at all in the results and nothing shows up in debug.

Has anyone got any advise on custom heroes via the API?
I figured out how to do this. The solution is to use json.dumps(), so the dict becomes:

'heroElements': json.dumps({"MWTEST":".product"})

I can confirm that this works - meaning you can define custom heroes through the API.
Reference URL's