Creating representations via api

When I try to create a representation to an existing version using the api it keeps returning bad request for URL.

This is the data I am sending:

files_data = [{
    'name': 'jpg',
    'versionId': version_data['id'],
    'files': [
        {
            'name': 'imageresized.jpg',
            'path': '{root[work]}/PRPT/seq_001/SEQ_001_SHOT_001/publish/render/renderCMPMain/v001/imageresized.jpg',
        }
    ],
    'status': 'Active',
}]
rep_id = ayon_api.create_representation(project_name, name='jpg', version_id=version_data['id'], files=files_data)
print(rep_id)

And this is the response I am getting:

Traceback (most recent call last):
  File "E:\ayon\.sandbox\ayon_09.py", line 161, in <module>
    rep_id = ayon_api.create_representation(project_name, name='jpg', version_id=version_data['id'], files=json_data)
  File "C:\Python39\lib\site-packages\ayon_api\_api.py", line 5506, in create_representation
    return con.create_representation(
  File "C:\Python39\lib\site-packages\ayon_api\server_api.py", line 7438, in create_representation
    response.raise_for_status()
  File "C:\Python39\lib\site-packages\ayon_api\server_api.py", line 275, in raise_for_status
    raise HTTPRequestError(message, exc.response)
ayon_api.exceptions.HTTPRequestError: 400 Client Error: Bad Request for url: http://192.168.15.50:5000/api/projects/PRPT/representations

This seems to be the same when i use the REST API also.

Can someone suggest how to go about this.

I’m not sure if you are using it correctly. you don’t have data or attrib for example.

https://docs.ayon.dev/ayon-python-api/ayon_api.html#ayon_api.create_representation

The rest API mentions that project_name, name, and versionId are required. But I’m not sure what other arguments are required when adding files in this case.

Tried giving that data too, but doesnt seem to work,

tt = {
    'status': 'Active',
    'files': [{
        'path': '{root[work]}/PRPT/seq_001/SEQ_001_SHOT_001/publish/render/renderCMPMain/v001/imageresized.jpg',
        'size': 114647,
        # 'id': 'ba502e82058f11fd0a64e047c16c50256',
        # 'hash': 'imageresized,jpg|1742477530,3845496|114647',
        'name': 'imageresized.jpg'}],
    'attrib': {
        'template': '{root[work]}/{project[name]}/{hierarchy}/{folder[name]}/publish/{product[type]}/{product[name]}/v{version:0>3}/{project[code]}_{folder[name]}_{product[name]}_v{version:0>3}<_{output}><.{frame:0>4}>.{ext}',
        'frameStart': 1001, 'handleStart': 0,
        'path': 'M:\\demo_project\\PRPT\\seq_001\\SEQ_001_SHOT_001\\publish\\render\\renderCMPMain\\v001\\imageresized.jpg',
        'handleEnd': 0, 'clipOut': 1, 'resolutionHeight': 1080, 'frameEnd': 1001, 'pixelAspect': 1.0,
        'description': None,
        'clipIn': 1, 'resolutionWidth': 1920, 'fps': 25.0, 'extension': None}, 'tags': [],
    'context': {'asset': 'SEQ_001_SHOT_001', 'ext': 'jpg', 'family': 'render',
                'folder': {'name': 'SEQ_001_SHOT_001', 'parents': ['seq_001'], 'path': '/seq_001/SEQ_001_SHOT_001',
                           'type': 'Shot'}, 'hierarchy': 'seq_001', 'output': 'baking',
                'product': {'name': 'renderCMPMain', 'type': 'render'}, 'project': {'code': 'PRPT', 'name': 'PRPT'},
                'representation': 'thumbnail', 'root': {'work': 'M:/demo_project'}, 'subset': 'renderCMPMain',
                'task': {'name': 'CMP', 'short': 'CMP', 'type': 'Comp'}, 'user': 'pavithraj', 'username': 'pavithraj',
                'version': 1},
    # 'id': 'b9f0484d058f11f08d89047c16c50256',
    'createdAt': '2025-03-20T13:32:11.341145+00:00', 'name': 'thumbnail',
    'active': True,
    'data': {
        'context': {
            'asset': 'SEQ_001_SHOT_001', 'ext': 'jpg', 'family': 'render',
            'folder': {
                'name': 'SEQ_001_SHOT_001', 'parents': ['seq_001'], 'path': '/seq_001/SEQ_001_SHOT_001',
                'type': 'Shot'
            },
            'hierarchy': 'seq_001',
            'output': 'baking',
            'product': {'name': 'renderCMPMain', 'type': 'render'},
            'project': {'code': 'PRPT', 'name': 'PRPT'},
            'representation': 'thumbnail',
            'root': {'work': 'M:/demo_project'},
            'subset': 'renderCMPMain',
            'task': {'name': 'CMP', 'short': 'CMP', 'type': 'Comp'},
            'user': 'pavithraj',
            'username': 'pavithraj', 'version': 1
        }
    },
    'traits': None,
    'versionId': 'b9ec4d24058f11f0bd8e047c16c50256'}
rep_id = ayon_api.create_representation(project_name, name='jpg', version_id=version_data['id'], files=tt)
print(rep_id)

but still getting the same error

It seems if i just do this

rep_id = ayon_api.create_representation(project_name, name='client_movB', version_id=version_data['id'])
print(rep_id)

it seems to create just the entry, how do i add files? i already have the files at the version folder,