with_shopify_session - undefined local variable or method `session' for an instane - RecurringJob

ToPre
Shopify Partner
5 1 0

Hello again,

 

I created a recurring job, without using the webhooks. It should update quantities regulary.

 

 

shop_domain = "myshopdomain"
    shop = Shop.where(shopify_domain: shop_domain).first

    if shop.nil?
      logger.error("#{self.class} failed: cannot find shop with domain '#{shop_domain}'")
      
      raise ActiveRecord::RecordNotFound, "Shop Not Found"
    end

    shop.with_shopify_session do

      product_data = ProductData.where(sku: "test-sku" )

      mutation = <<~QUERY
        mutation inventoryAdjustQuantities($input: InventoryAdjustQuantitiesInput!) {
          inventoryAdjustQuantities(input: $input) {
            userErrors {
              field
              message
            }
            inventoryAdjustmentGroup {
              createdAt
              reason
              referenceDocumentUri
              changes {
                name
                delta
              }
            }
          }
        }
        QUERY
      client = ShopifyAPI::Clients::Graphql::Admin.new(
        session: session
      )

      variables = {
        "input": {
          "reason": "other",
          "name": "available",
          "changes": [{"delta"=>-1, "inventoryItemId"=>"#{product_data.shopify_inventory_item_id}", "locationId"=>"#{product_data.shopify_product_location_id}"}]
        }
      }

      response = client.query(query: mutation, variables: variables)
end

 

 

 

Somehow I dont know why it says 

 

 

undefined local variable or method `session' for an instance

 

 

in the with_shopify_session block. Anybody has an idea to fix it?

 

Kind Regards

Torsten

Replies 0 (0)