Contentful logo

Contentful Community

Python Image Asset Creation Issue

Hey, trying to push an image asset into contentful so I can use it in an entry. However, it keeps coming back to me with;
HTTP status code: 422
Message: Validation error

I’ve tried using this;
https://www.contentful.com/developers/docs/references/content-management-api/#/reference/assets/assets-collection/create-an-asset/console/python

But, then it gives me an issue and says I need a url field instead. So I replaced ‘upload’ with ‘url’. Still getting the 422 error though. Here’s my code;

        # Create an Asset:
        asset_id = None  # Use `None` if you want the API to autogenerate the ID.
        asset = client.assets(siete_space_id, environment_id).create(asset_id, {
            'fields': {
                'title': {
                    'en-US': row['Product']
                },
                'file': {
                    'en-US': { 
                        'contentType': 'image/jpeg',
                        'fileName': row['Product'] + '.jpg',
                        'url': product_info.iloc[0]['Image_Url']
                    }
                }
            }
        })

        try:
            # Update an Asset:
            asset.title = row['Product']
            asset.save()
            # Publish asset
            asset.publish()
        except Exception as e:
            print(e)