Shopify_API errors

Highlighted
New Member
3 0 0

Hello,

I am having an issue with the Shopif_API for ruby. When I run it eith a version up to and including 2019-07, it runs fine just really slow.

Now when I try to usw 2020-01 I get the errors on the bottom. I have invluded code and errors. Any helpwould be appreciated.

Thanks,
John


<----- Code ----->

require 'shopify_api'
require 'mysql2'
require 'dotenv'
require 'httparty'

Dotenv.overload

class ExtractMetaFromOrder
def initialize
# @shop_url = "https://#{ENV["API_KEY"]}:#{ENV["PASSWORD"]}@#{ENV["API_SHOP"]}.myshopify.com/admin"
# ShopifyAPI::Base.site = @shop_url

shop_url = "https://#{ENV["API_KEY"]}:#{ENV["PASSWORD"]}@#{ENV["API_SHOP"]}.myshopify.com"
ShopifyAPI::Base.site = shop_url
ShopifyAPI::Base.api_version = '2019-10' # find the latest stable api_version [here](https://help.shopify.com/api/versioning)

end

# Tests the Shopify connection with a simple GET request
def test_connection
shop = ShopifyAPI::Shop.current
puts shop.name
end
end

puts "What Order: "
ordernum = gets.chomp

myShop = ExtractMetaFromOrder.new

begin
page = 1
forders = []

count = ShopifyAPI::Order.count()
order_transactions = []

if count > 0
page += count.divmod(250).first
while page > 0
gorders = []
puts "Processing page #{page}"
x = page
gorders = ShopifyAPI::Order.find(:all, :params => {page: x, limit: 250})
forders += gorders
page -= 1
gorders.each do |order|
if (order.name.to_s == ordernum.to_s)
order_transactions = order.transactions
page = -1
count = -1
if page == -1
puts order.to_xml
puts ""
puts order.transactions.to_xml
end
break
end
end
end
end
rescue StandardError => e
puts e.inspect
puts e.backtrace
end

<----- Errors ----->

Processing page 38
#<ActiveResource::BadRequest: Failed. Response code = 400. Response message = Bad Request (page; page cannot be passed. See https://help.shopify.com/api/guides/paginated-rest-results for more information.).>
C:/Ruby25-x64/lib/ruby/gems/2.5.0/gems/activeresource-5.1.0/lib/active_resource/connection.rb:141:in `handle_response'
C:/Ruby25-x64/lib/ruby/gems/2.5.0/gems/shopify_api-9.0.2/lib/shopify_api/connection.rb:7:in `handle_response'
C:/Ruby25-x64/lib/ruby/gems/2.5.0/gems/activeresource-5.1.0/lib/active_resource/connection.rb:126:in `request'
C:/Ruby25-x64/lib/ruby/gems/2.5.0/gems/shopify_api-9.0.2/lib/shopify_api/connection.rb:15:in `request'
C:/Ruby25-x64/lib/ruby/gems/2.5.0/gems/activeresource-5.1.0/lib/active_resource/connection.rb:85:in `block in get'
C:/Ruby25-x64/lib/ruby/gems/2.5.0/gems/activeresource-5.1.0/lib/active_resource/connection.rb:220:in `with_auth'
C:/Ruby25-x64/lib/ruby/gems/2.5.0/gems/activeresource-5.1.0/lib/active_resource/connection.rb:85:in `get'
C:/Ruby25-x64/lib/ruby/gems/2.5.0/gems/activeresource-5.1.0/lib/active_resource/base.rb:1073:in `find_every'
C:/Ruby25-x64/lib/ruby/gems/2.5.0/gems/activeresource-5.1.0/lib/active_resource/base.rb:974:in `find'
ExtractMetaFromOrder.rb:44:in `<main>'

0 Likes
Highlighted
Shopify Staff
Shopify Staff
1041 140 167

Hey @JFraedrich,

 

Page-based pagination was deprecated as of 2019-10, the Shopify_api gem has been updated to support the new cursor-based pagination, here's how to use it: https://github.com/Shopify/shopify_api#pagination

Notice; Out of office, replies will be delayed until my return. Thanks!
0 Likes