Trouble updating assets using python ShopifyAPI

158 views
Skip to first unread message

Richard Antecki

unread,
Dec 9, 2011, 1:36:52 AM12/9/11
to shopi...@googlegroups.com
Hi guys,

I'm having trouble updating the value of an asset using the python version of ShopifyAPI.  I'm not sure if I'm doing something wrong, but I couldn't find many examples of updating objects via the API.

Here's what I'm doing:

        asset = shopify.Asset.find(remote_path, theme_id=theme_id)
        asset.value = "new contents"
        asset.save()

Asset.find() pulls the file contents correctly, but updating the value attribute doesn't seem to be updating the file on the server.

After the asset.save() call an 'attachment' attribute appears to be added to the asset object containing the base64 encoded value of the new file contents, and the 'value' attribute is also still there with the original value.

Also, the theme ID doesn't seem to be being passed in the XML request to the server during the save() call.  I found another similar topic regarding this (https://groups.google.com/forum/#!searchin/shopify-api/ShopifyAPI$20asset/shopify-api/Kvxt1nL6nls/P1mlENlIY_QJ) which gives me the impression that it's meant to be there.  I can't work out how to replicate the authors workaround in the python version of activeresource though.

Would appreciate any help.

Thanks!

Richard

Dylan Smith

unread,
Dec 9, 2011, 12:54:37 PM12/9/11
to shopi...@googlegroups.com
This was a bug in the attribute setting for Asset objects. Thanks for letting me know about it.

I have fixed the bug and made a new release.  You should be able to `easy_install -U ShopifyAPI` the new version if you are using easy_install, and your problem should be fixed.

Richard Antecki

unread,
Dec 9, 2011, 5:02:50 PM12/9/11
to shopi...@googlegroups.com
Hi Dylan,

Thanks for the quick response, it now works for assets in the currently published theme.

However, it still doesn't seem to be working for assets in unpublished themes.  When an unpublished theme asset is updated, it just overwrites the asset in the published theme.  No theme ID is being passed with the request.

The XML request currently looks like this:

<?xml version="1.0" encoding="UTF-8"?>
<asset>
<value>NEW VALUE</value>
<created-at>2011-12-02 16:25:23+11:00</created-at>
<public-url nil="true" />
<updated-at>2011-12-02 16:25:23+11:00</updated-at>
<key>templates/index.liquid</key>
</asset>

Thanks,

Richard

Dylan Smith

unread,
Dec 9, 2011, 6:07:55 PM12/9/11
to shopi...@googlegroups.com
You're right, it seems that the prefix option doesn't get stored after the call to find.  It looks like this is also a bug with the ruby shopify_api gem.

I have filed a bug report for both projects:

I'll let you know when I have fixed shopify_python_api, after which I will make another bug fix release.

Richard Antecki

unread,
Dec 9, 2011, 8:22:02 PM12/9/11
to shopi...@googlegroups.com
Awesome, thanks!

Dylan Smith

unread,
Dec 9, 2011, 8:50:55 PM12/9/11
to shopi...@googlegroups.com
Fixed and released.

Let me know if you experience any other problems after upgrading.

Thanks for reporting the issues.

Richard Antecki

unread,
Dec 10, 2011, 3:07:00 AM12/10/11
to shopi...@googlegroups.com
All seems to be working fine now Dylan.  Thanks again for the fast turnaround.

Richard Antecki

unread,
Dec 12, 2011, 7:03:33 PM12/12/11
to shopify-api
One more thing...

When creating a new Asset, there needs to be some way of specifying
the theme_id. At the moment I'm doing this:

asset = shopify.Asset()
asset.key = path
asset.attach(read_file(path))
asset._prefix_options["theme_id"] = theme_id
asset.save()

Is there a more elegant / recommended way of doing this?

Cheers

Dylan Smith

unread,
Dec 13, 2011, 7:49:40 AM12/13/11
to shopi...@googlegroups.com
  asset = Asset(dict(key=path, theme_id=theme_id))
  asset.attach(read_file(path))
  asset.save()

The resource constructor can take a single dictionary argument with attributes and prefix_options, and will split them according to the known prefix options.
Reply all
Reply to author
Forward
0 new messages