Defining custom hero via the API

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 =,

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.