How to fix InvenTree API remote_image: Server responded with invalid status code: 403

Problem:

While trying to create a Company using the InvenTree API you see an error message like

requests.exceptions.HTTPError: {'detail': 'Error occurred during API request', 'url': 'https://inventree.techoverflow.net/api/company/', 'method': 'POST', 'status_code': 400, 'body': '{"remote_image":["Server responded with invalid status code: 403"]}', 'headers': {'AUTHORIZATION': 'Token 340fdf063d5433b83bc37c50a4b52ee2f246021b'}, 'params': {'format': 'json'}, 'data': {'name': 'DigiKey', 'website': 'https://www.digikey.de/', 'remote_image': 'https://www.digikey.de/-/media/Images/Header/logo_dk.png', 'description': 'Test', 'is_manufacturer': False, 'is_supplier': True, 'is_customer': False, 'currency': 'EUR'}}

Solution

The core issue here is:

{"remote_image":["Server responded with invalid status code: 403"]}

InvenTree tries to download the remote_image URL - but that URL can’t be downloaded and the upstream server (digikey.de in this case) generates a 403 response. This is often the case when an URL can only be downloaded with correct Referer headers or other headers set to a specific value.

In order to fix this issue, change the remote_image URL to an image URL which can be fetched correctly.

Sometimes this issue can also arise if the IP address of the InvenTree server is blocked by the server serving the image. This can easily found out by trying to download the given image URL from the server running inventree using wget [URL].