Hello,
I am just trying to post an image, and following the documentation available for the admin api:
When I see the curl:
curl -X POST -F 'file=@/path/to/images/my-image.jpg' -F 'ref=path/to/images/my-image.jpg' -H "Authorization: 'Ghost $token'" -H "Accept-Version: $version" https://{admin_domain}/ghost/api/admin/images/upload/
It translates to:
import os
import requests
token' = os.getenv('token'')
version = os.getenv('version')
headers = {
'Authorization': f"'Ghost {token'}",
'Accept-Version': f"{version}",
}
files = {
'file': open('/path/to/images/my-image.jpg', 'rb'),
'ref': (None, 'path/to/images/my-image.jpg'),
}
response = requests.post('https://{admin_domain}/ghost/api/admin/images/upload/', headers=headers, files=files)
In python,
There is already a difference between the ref in the curl and the one in the documentation.
Whatever I try, my best result is a 415 error code:
'{"errors":[{"message":"Please select a valid image.","context":null,"type":"UnsupportedMediaTypeError","details":null,"property":null,"help":null,"code":null,"id":"46fff9b0-ecb1-11ec-9c4b-e5f617404273"}]}'
I tried both jpg and png. I saw different things online, but I guess they were linked to other version of the api.
EDIT1:
I forgot indeed the content-type header.
If i go with
headers = {'Authorization': 'Ghost {}'.format(token),
'Accept-Version': "v1",
'Content-Type': 'multipart/form-data;'}
I now get a Error code 422:
{"message":"Please select an image.","context":null,"type":"ValidationError"
Thanks in advance!