Topics covering webhook creation & management, event handling, Pub/Sub, and Eventbridge, in Shopify apps.
I have a custom app with only one shop.
My call backs and even in the console when I try to authenticate then call the API I get a 401.
ActiveResource::UnauthorizedAccess: Failed. Response code = 401. Response message = Unauthorized ([API] Invalid API key or access token (unrecognized login or wrong password))
Failing code is below
# Controller
class OrdersController < ApplicationController
before_action :set_shopify_tenancy_and_api!
include ShopifyApp::WebhookVerification
def create
order = ShopifyAPI::Order.find(params[:id])
ShopifyOrderProcessor.new(order).process!
render json: {}
end
private
def set_shopify_tenancy_and_api!
Shop.first.login_with_session!
end
end
# shop.rb
class Shop < ActiveRecord::Base
include ShopifyApp::ShopSessionStorage
def login_with_session!
session = ShopifyAPI::Session.new(domain: shopify_domain, token: shopify_token)
ShopifyAPI::Base.activate_session(session)
end
end
I would check couple things here:
ShopifyAPI::Session.new(domain: shopify_domain, token: shopify_token, api_version: api_version)
Hope one of the above will help. Good luck!