Access shop through cron job

346 views
Skip to first unread message

Sumit Garg

unread,
May 25, 2012, 4:40:41 AM5/25/12
to shopify-api
Hi All,
For one of my app, I am trying to access the authenticated shop
through cron jobs using gem shopify_api 3.0.0..

while getting the shop details, i am getting the following response
ActiveResource::Redirection: Failed. Response code = 302. Response
message = Found. => https://my-shop.myshopify.com/admin/shop.json

I am doing the steps

while login, i am storing the
token("xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx") received
(request.env['omniauth.auth']['credentials']['token']) and the domian
of the shop ("www.my-shop.com")

now in the cron job, i am using the shop domain and the token as
follows
* shopify_session = ShopifyAPI::Session.new(shop.domain, shop.token)
returns: #<ShopifyAPI::Session:0x000000036a7450 @url="www.my-
shop.com", @token="xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx">

* ShopifyAPI::Base.activate_session(shopify_session)
returns: {"User-Agent"=>"ShopifyAPI/3.0.0 ActiveResource/3.2.1 Ruby/
1.9.2", "X-Shopify-Access-Token"=>"xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"}

* shopify_shop = ShopifyAPI::Shop.current
returns: ActiveResource::Redirection: Failed. Response code = 302.
Response message = Found. => https://my-shop.myshopify.com/admin/shop.json


It should give me the shop details rather than redirecting me to a
json url.
Please let me know if i am missing something or doing something
wrong..

Thanks
Sumit Garg

David Underwood

unread,
May 25, 2012, 9:02:02 AM5/25/12
to shopi...@googlegroups.com
Hi Summit,

I believe this is happening because you're using a custom domain to create the session rather than the myshopify.com one. We're returning a redirect to the actual resource under the myshopify domain and ActiveResource is flaming out. I'll flag this for the API team but in the meantime try creating the session with the myshopify domain up front and it should work.

-David Underwood
 Developer Advocate, Shopify

Sumit Garg

unread,
May 25, 2012, 9:17:42 AM5/25/12
to shopi...@googlegroups.com
True David,
When i used the myshop.myshopify.com, it worked. Actually the shop for which this problem arises has authenticated with the custom domain.

Does that mean that I need to restrict the store owners to input shop names with myshopify.com domain and they can not use the custom domains?

For app created from scratch, I can think (once) doing this (although I am sure, the store owners would not like it), but what about the apps which are already live and store owners have authenticated using the custom domain. The cron job is working perfectly fine with legacy authentication on those apps.

Thanks
Sumit Garg

David Underwood

unread,
May 25, 2012, 9:30:05 AM5/25/12
to shopi...@googlegroups.com
Hi Sumit,

I'll pass this onto the API team, sounds like a bug that needs fixing. :)

-David Underwood
 Developer Advocate, Shopify

David Underwood

unread,
May 25, 2012, 10:21:34 AM5/25/12
to shopi...@googlegroups.com
Ok, we did some digging and this is what we came up with:

You should always be making API calls to the myshopify domain, or else you'll get the redirect that you're seeing. ActiveResource doesn't like redirects so it errors out.

To fix this, Make sure you grab the myshopify domain from the initial auth confirmation redirect that you're sent when a merchant installs your app. It should be in a query param alongside your access token.

-David Underwood
 Developer Advocate, Shopify

Sumit Garg

unread,
May 25, 2012, 10:28:55 AM5/25/12
to shopi...@googlegroups.com
Thanks David, for looking into this..
Will check and update the findings.. Hope this fixes the problem..

Thanks
Sumit Garg
Thanks and Regards
Sumit Garg

From: David Underwood <david.u...@jadedpixel.com>
Date: Fri, 25 May 2012 07:21:34 -0700 (PDT)
Subject: Re: Access shop through cron job
Reply all
Reply to author
Forward
0 new messages