Uploading a listing image to the Etsy API in Python

It took a bit of messing around, but I was able to upload product listing images via the Etsy API in Python 3 with requests_oauthlib like this (reduced to the essentials):


from requests_oauthlib import OAuth1Session

session = OAuth1Session(
    "{etsy client key}",
    client_secret="{etsy client secret}",
    resource_owner_key="{etsy resource owner key}",
    resource_owner_secret="{etsy resource owner secret}",
)

response = session.post(
    "/listings/123456789/images",
    params={
        "listing_id": 123456789,
        "rank": 1,
        "overwrite": True,
        "is_watermarked": False,
    },
    files={
        "image": (
            "image123.jpg",
            open("image123.jpg", "rb"),
            "image/jpeg"
        )
    },
)

print(response.text)

I’ve been using this to automate management of the art decor images for our wall art prints shop.


Tech mentioned