skip to Main Content

shopify_app-13.4.0
local env works fine
when deploying to heroku and my rescue worker is trying to register webhooks I get this error:
ShopifyAPI::ApiVersion::ApiVersionNotSetError (You must set ShopifyAPI::Base.api_version before making a request.):

Are workers aware of the Shopify configuration at all? If not, what do I need to add in order for them to be aware of the Shopify configuration?

2

Answers


  1. Make sure the code you are running in your worker opens up a session before you try and access the API. If you open a session that message will disappear. Once I experienced that message doing GraphQL calls in a worker, and I inserted a command to initialize the client. That also worked, but probably is not needed.

    ShopifyAPI::GraphQL.initialize_clients

    Login or Signup to reply.
  2. Note the webhook cannot work in the local environment, because Shopify can’t send the request to local env.

    Once you have deployed the app, you will need to init the Shopify session before performing an API call from the worker. This is an example code to init the session:

    ShopifyAPI::Base.clear_session
    shop = Shop.find_by(shopify_domain: shopify_domain)
    unless shop.nil?
      shopify_token = shop.shopify_token
      session = ShopifyAPI::Session.new(
        domain: shopify_domain, 
        token: shopify_token, 
        api_version: ShopifyApp.configuration.api_version,
      )
      ShopifyAPI::Base.activate_session(session)
    end
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search