Rails & Shopify: DelayedJob (non WebHook) - Authenticate and create session

Hey guys,

I have a job which runs every day at midnight and retrieves information from etsy.

I need to update my products in shopify but I dont know how to create a valid shopsession.

I could do it with

shop = Shop.find_by(shopify_domain: shop_domain)

and then shop.with_shopify_session but i still need the shop_domain for this.

Do you have any tips?

Cheers!

Hello,

To create a valid Shopify session, you’ll indeed need the shop_domain. The shop_domain is a unique identifier for each shop and is necessary to establish a session.

If you’re running a job needs to update products on Shopify, you would likely have this information stored somewhere in your database. When a store installs your app, should be storing the shop_domain in your database.

Here’s a general way you could use the shop_domain to establish a Shopify session in a job:

Shop.find_each do |shop|
  shop.with_shopify_session do
    # Your code to update products on Shopify goes here
  end
end

In this example, Shop.find_each is iterating over each Shop record in your database, and for each shop, it establishes a Shopify session and runs the code within the block. If for some reason you don’t have the shop_domain stored, you would need to adjust your app installation process to save this information.

Hope this helps!

Thank you das helps me a lot :slightly_smiling_face: