How can I include headers (X-Contentful-Version) in requests using the python SDK?

How can I include the X-Contentful-Version header using the Python client?

        entry_id = id  
        entry = management_client.entries(space_id, environment_id).create(entry_id, {
            'content_type_id': experiment_content_id,
            'fields': {
                'contentMarkdown': {
                    'de': body
                }
            }
        })

Without this header, I get the error:

contentful_management.errors.VersionMismatchError: HTTP status code: 409
Message: Version mismatch error. The version you specified was incorrect. This may be due to someone else editing the content.

How can I add it?

The answer is not to create - to update. If you’re going to update, use the management API to fetch a resource and then update it. I was confused and thought that the create and update endpoints were the same.

1 Like