I am developing a product listing Public App on "Ruby on Rails" for Shopify Store, Where I have to call "SHOP" API for fetching the shop "domain". But I am getting an error while doing it.
Error is: "ShopifyAPI::ApiVersion::ApiVersionNotSetError (You must set ShopifyAPI::Base.api_version before making a request.):"
I am already using it in different Apps and working fine. But don't know what happened here.
Some code or examples would be very helpful.
Logs are:-
019-12-12T12:12:55.393042+00:00 heroku[router]: at=info method=GET path="/locations/new" host=warm-tundra-19548.herokuapp.com request_id=fc9e1d85-59e4-46a3-803c-b922d5c993bc fwd="103.74.223.20" dyno=web.1 connect=1ms service=101ms status=500 bytes=1827 protocol=http
2019-12-12T12:12:55.293823+00:00 app[web.1]: I, [2019-12-12T12:12:55.293721 #4] INFO -- : [fc9e1d85-59e4-46a3-803c-b922d5c993bc] Started GET "/locations/new" for 103.74.223.20 at 2019-12-12 12:12:55 +0000
2019-12-12T12:12:55.297242+00:00 app[web.1]: I, [2019-12-12T12:12:55.297154 #4] INFO -- : [fc9e1d85-59e4-46a3-803c-b922d5c993bc] Processing by LocationsController#new as HTML
2019-12-12T12:12:55.390066+00:00 app[web.1]: I, [2019-12-12T12:12:55.389910 #4] INFO -- : [fc9e1d85-59e4-46a3-803c-b922d5c993bc] Completed 500 Internal Server Error in 93ms (ActiveRecord: 36.4ms | Allocations: 7918)
2019-12-12T12:12:55.391312+00:00 app[web.1]: F, [2019-12-12T12:12:55.391186 #4] FATAL -- : [fc9e1d85-59e4-46a3-803c-b922d5c993bc]
2019-12-12T12:12:55.391325+00:00 app[web.1]: [fc9e1d85-59e4-46a3-803c-b922d5c993bc] ShopifyAPI::ApiVersion::ApiVersionNotSetError (You must set ShopifyAPI::Base.api_version before making a request.):
2019-12-12T12:12:55.391327+00:00 app[web.1]: [fc9e1d85-59e4-46a3-803c-b922d5c993bc]
2019-12-12T12:12:55.391329+00:00 app[web.1]: [fc9e1d85-59e4-46a3-803c-b922d5c993bc] app/controllers/locations_controller.rb:21:in `new'
2019-12-12T12:12:57.447093+00:00 heroku[router]: at=info method=GET path="/favicon.ico" host=warm-tundra-19548.herokuapp.com request_id=653526e1-5bf1-4833-8154-70cc4a94a9ff fwd="103.74.223.20" dyno=web.1 connect=1ms service=2ms status=200 bytes=143 protocol=http
2019-12-12T12:13:03.736460+00:00 app[web.1]: I, [2019-12-12T12:13:03.733487 #4] INFO -- : [598ef2e7-0bb4-41dd-998f-3d4dac478a9d] Started GET "/?hmac=1b356c85ac0394c932672bf226a3883082bf38245d96b2a33bd7ade6d7d6dd6b&locale=en&shop=geolocapp.myshopify.com×tamp=1576148018" for 103.74.223.20 at 2019-12-12 12:13:03 +0000
2019-12-12T12:13:03.736474+00:00 app[web.1]: I, [2019-12-12T12:13:03.735356 #4] INFO -- : [598ef2e7-0bb4-41dd-998f-3d4dac478a9d] Processing by LocationsController#new as HTML
2019-12-12T12:13:03.737702+00:00 app[web.1]: I, [2019-12-12T12:13:03.737642 #4] INFO -- : [598ef2e7-0bb4-41dd-998f-3d4dac478a9d] Completed 500 Internal Server Error in 2ms (ActiveRecord: 0.0ms | Allocations: 425)
2019-12-12T12:13:03.738252+00:00 app[web.1]: F, [2019-12-12T12:13:03.738193 #4] FATAL -- : [598ef2e7-0bb4-41dd-998f-3d4dac478a9d]
2019-12-12T12:13:03.738256+00:00 app[web.1]: [598ef2e7-0bb4-41dd-998f-3d4dac478a9d] ShopifyAPI::ApiVersion::ApiVersionNotSetError (You must set ShopifyAPI::Base.api_version before making a request.):
2019-12-12T12:13:03.738258+00:00 app[web.1]: [598ef2e7-0bb4-41dd-998f-3d4dac478a9d]
2019-12-12T12:13:03.738260+00:00 app[web.1]: [598ef2e7-0bb4-41dd-998f-3d4dac478a9d] app/controllers/locations_controller.rb:21:in `new'
2019-12-12T12:13:03.739811+00:00 heroku[router]: at=info method=GET path="/?hmac=1b356c85ac0394c932672bf226a3883082bf38245d96b2a33bd7ade6d7d6dd6b&locale=en&shop=geolocapp.myshopify.com×tamp=1576148018" host=warm-tundra-19548.herokuapp.com request_id=598ef2e7-0bb4-41dd-998f-3d4dac478a9d fwd="103.74.223.20" dyno=web.1 connect=0ms service=8ms status=500 bytes=1827 protocol=https
Hey @gaurav69,
Which version of the gem are you using?
Sounds like you need to set the version:
ShopifyAPI::Session.new(domain: domain, token: token, api_version: api_version, extras: extras)
Hello @SBD_
Thanks for the reply.
I am using gem version "3.0.3", ruby version "2.6.3" ,rails version "6.0.2" ,shopify_app version "11.4.0", shopify_api version "8.0.0".
I tried using your session method but still getting the same error. You can view the error here ("https://prnt.sc/qbuhfw").
To set the base API version (see getting started):
ShopifyAPI::Base.api_version = '<version_name>' # find the latest stable api_version [here](https://help.shopify.com/api/versioning)
If you're still stuck please share your code.
Hello @SBD_ ,
Hope you are doing well.
I am also facing same issue.
I am working on a Public app Where i have to call Shop API to fetch the current store's URL.
In the method you have provided:
shop_url = "https://#{API_KEY}:#{PASSWORD}@#{SHOP_NAME}.myshopify.com"
We don't have only one shop name so we have to fetch it through the API dynamically which BTW is not working.
For the temporary try I assigned the shop_name static but called the respective versioning method but still got the errors like:
"Both URI are relatives".
If we remove the shop_url variable then it comes back to it's original error:
"Assign ShopifyAPI::Base.api_version before making the request".
Here is my code:-
shop_url = "https://dynamictask.myshopify.com" ShopifyAPI::Base.site = shop_url ShopifyAPI::Base.api_version = '2019-10' shop = ShopifyAPI::Shop.current shop_domain = shop.domain
FYI:- I am not sharing my Api_key and password for the "shop_url" variable here.
Thank you
def connect shop_url = URI("https://#{ENV['SHOPIFY_API_KEY']}:#{ENV['SHOPIFY_API_PASSWORD']}@#{ENV['SHOPIFY_DOMAIN']}") ShopifyAPI::Base.site = shop_url ShopifyAPI::Base.api_version = "2019-10" puts ShopifyAPI::Base.api_version # 2019-10 endI am using GraphQL Admin API.
gem 'shopify_graphql_client', github: 'mikeyhew/shopify_graphql_client', branch: 'master'
connect query = ShopifyGraphQLClient.parse <<~GRAPHQL { orders(first: 5) { pageInfo { hasNextPage } edges { cursor node { id shippingLine { taxLines { rate ratePercentage } } } } } }
GRAPHQL ...
I know taxLines field was added in shippingLine in 2019-10 API version.
But when I run above query, I get this error - Field 'taxLines' doesn't exist on type 'ShippingLine'
Could you please have a look and tell me why I am getting this issue?
Thank you.
Hey @Shikha_Gupta,
For public apps, you will need to supply two parameters to the Session class before you instantiate it:
ShopifyAPI::Session.setup(api_key: API_KEY, secret: SHARED_SECRET)
Please review step 2 of getting started for private vs public configuration.
Hey @Yu727,
I don't think the version is sticking. I get the same error up until 2019-10.
Is this a rails app? Can you move the config into config/initializers/shopify_app.rb?
Hello @SBD_
Sorry for the late reply. I missed your message so far.
Yes, it is a rails Shopify app.
I know 2020-01 API version has been released so I am going to use this version.
config/initializers/shopify_app.rb
ShopifyApp.configure do |config| ... config.api_version = "2020-01" end
But I am running GraphQL queries on Sidekiq workers, the outside of the app.
So I think this doesn't affect to set API version so I am using this code.
def connect ShopifyAPI::Base.clear_session session = ShopifyAPI::Session.new(domain: shopify_domain, token: shopify_token, api_version: "2020-01") ShopifyAPI::Base.activate_session(session) end
But when I run fulfillmentCreateV2 mutation, I am getting the error.
FulfillmentV2Input isn't a defined input type (on $fulfillment)
I believe this is the issue of setting API version.
Can you please help me to fix?
User | Count |
---|---|
13 | |
12 | |
7 | |
4 | |
4 |