0

In the Shopify API documentation, the resource "User" is offered for those who pay for the Shopify Plus account. See below: https://help.shopify.com/api/reference/user#current Speaking to Shopify's support, because Shopify Plus user's are a minority, the shopify_api gem does not support these calls, so I have to build them myself. I've tried doing this by extending the current ShopifyAPI module and classes like so:

module ShopifyAPI
  class User < Base
    def self.current(options={})
      find(:one, options.merge({from: "/admin/users/current.json"}))
    end
  end
end

Then I call the new method like the following:

@user = ShopifyAPI::User.current

I get a "Not Found" error. If I check the logs of ActiveResource to see what call it is trying, strangely I get the following, which looks right:

I, [2017-02-24T13:14:19.278087 #4890]  INFO -- : GET https://mazer-3.myshopify.com:443/admin/users/current.json
I, [2017-02-24T13:14:19.278356 #4890]  INFO -- : --> 404 Not Found 22 (279.5ms)
I, [2017-02-24T13:14:19.279605 #4890]  INFO -- : Headers: {"Accept"=>"application/json", "User-Agent"=>"ShopifyAPI/4.3.5 ActiveResource/4.1.0 Ruby/2.3.1", "X-Shopify-Access-Token"=>"SOME_CHARACTERS_HERE_I_AM_NOT_SHOWING_TO_THE_PUBLIC"}
I, [2017-02-24T13:14:19.279680 #4890]  INFO -- : Response:
{"errors":"Not Found"}

If I copy that URL it is generating on the first line, https://mazer-3.myshopify.com:443/admin/users/current.json, and paste it in my browser while logged into Shopify, strangely it does gives me the current user, and a 200 success response code.

Is there something I am missing in configuring ActiveResource?

Colin Brogan
  • 728
  • 10
  • 26

1 Answers1

0

There is no API endpoint activated for you to use, since the Shop is not a Plus shop... you cannot make your own endpoint calls and expect them to work, if Shopify has not authorized those calls. Internally, they turn on the Plus scopes... like User.

So you can consider it a good attempt, but you cannot fake out Shopify.

David Lazar
  • 10,865
  • 3
  • 25
  • 38
  • You have assumed something which is not the case. I have Shopify plus, internally the plus scopes are on. The question here is, how do you extend the shopify_api gem to use them? The standard Shopify GEM does not have any of the shopify plus calls built-in, and they don't offer a Shopify Plus API gem. – Colin Brogan Mar 10 '17 at 21:32
  • Do what programmers do then. Fork the gem. Copy and paste the suitable code for the endpoints you want, edit them as needed and use your fork in your App. That way you can maintain upstream changes easily. I do this all the time when the shopify_api gem fails to provide. – David Lazar Mar 10 '17 at 22:23
  • Not long ago, the gem had Discount endpoint code too.. I think they pulled it recently. Note that that endpoint is really underpowered no matter how special you are. You cannot even search for a code by name. Bahhhhh – David Lazar Mar 10 '17 at 22:31