Why this matters
The upload endpoint stores the file, but SEO metadata often needs a second request.
WordPress REST / safe media upload
Use a code snapshot when the article explains a technical pattern but the body still needs copyable code.
upload-media.py
media = requests.post(
f"{BASE}/media",
auth=AUTH,
headers=headers,
data=png_bytes,
).json()
requests.post(
f"{BASE}/media/{media['id']}",
auth=AUTH,
json={
"title": title,
"alt_text": alt_text,
"caption": caption,
},
)
Why this matters
The upload endpoint stores the file, but SEO metadata often needs a second request.
Gotcha
Never build Gutenberg payloads with shell heredocs when block comments must survive intact.