featured images with python api for article objects

joshbar
Visitor
2 0 0

hey guys i'm trying to add featured image for my blog articles using python api 

something like this 

 

img = shopify.Image(dict(article_id=83503120552))
img.src='https://cdn.shopify.com/s/files/1/0590/9862/8264/t/16/assets/cafecubanocubancoffeerecipeasassyspoon4-1643921321008.jpg?v=1643921337'
img.save()

 

above code clearly doesnt work, and i cant find any relevant topic from anywhere. 

Thanks!

Replies 2 (2)

ashensha90
Visitor
3 0 0

Im waiting for the same answer. I hope somebody can help us soon. Im using the below code and the article creates but without the image.

 

  new_article = shopify.Article(
      {
         "blog_id": 84588953792, 
         "title": title, 
         "body_html": body_html, 
         "author": "hit-parader",
         "image": { 
            "src": imageSRC, 
            "Alt": "image92" 
         }, 
         "tags": tags })

   new_article.save()
yoann_gasque
Shopify Partner
2 0 0

Hello @ashensha90 and @joshbar , 

when i use Python Shopify SDK i do this:

import shopify
from dotenv import dotenv_values

config = dotenv_values("../.env.local")
PASSWORD = config.get('PASSWORD')
API_KEY = config.get('API_KEY')
API_SECRET = config.get('API_SECRET')

shop_url = config.get('shop_url')
api_version = config.get('api_version')

TARGET_BLOG = your_blog_id
new_session = shopify.Session(shop_url, api_version,PASSWORD)
shopify.ShopifyResource.activate_session(new_session)
new_article = shopify.Article()
new_article.blog_id = TARGET_BLOG
#for featured image
new_article.attributes['image'] = {'src': "your_cdn_image_url"}
new_article.save()