Shopify Python API - Article

New Member
2 0 0

Evening. 

 

I am having an issue with the Shopify python API, when trying to create an Article with tags. 

 

I have the following script:

 

for post in blog:
    new_article = shopify.Article()
    new_article.title = post[0].decode('windows-1252')
    new_article.author = post[2].decode('windows-1252')
    new_article.blog_id = post[3].decode('windows-1252')
    new_article.body_html = post[4].decode('windows-1252')
    new_article.created_at = post[5].decode('windows-1252')
    new_article.handle = post[6].decode('windows-1252')
    new_article.image = post[7].decode('windows-1252')
    new_article.published = 'TRUE'
    new_article.save()
    new_article_tags = post[11]

    new_article.tags = new_article_tags
    new_article.published_at = post[9].decode('windows-1252')
   
    new_article.save()
    print new_article.errors.full_messages()

post[11] prints like this: 'Tag1, Tag2, Tag3'

 

I can run the script and get no errors, however when I check the articles that have been created, there are no tags on the products. 

 

Banging my head against the wall with this one and hoping that someone may be able to point me in the right direction. 

0 Likes
Excursionist
26 1 4

From the code in https://github.com/Shopify/shopify_python_api/blob/master/shopify/resources/article.py it looks like "tags" is not a field that you can set on Article instance. It's a classmethod, probably retrieves the tags of the article.

 

Looks like someone has had a similar issue with another resource in the past and the solution appears to be to pass a dictionary of all the fields to the initialiser: https://github.com/Shopify/shopify_python_api/issues/90

 

In your case that would be:

 

new_article = shopify.Article({...., "tags": post[11]})

 

 

0 Likes