voskart
voskart

Reputation: 777

How to get the responses of an API call (shopify)?

I've been using rails for about a week and have found numerous good tutorials but haven't found any info for my current problem. I have a webshop running and can access it via the shopify console:

      ShopifyAPI::Customer.find(674469828)
      -> will return the customer with the id 674469828

If I use the same code in my rails app nothing happens. I would like to get the error message of this API call and have no idea how to do this. I mean I'm sending a POST request to the service and am getting a response (HTTP/1.1 200 OK for example).
How can I "catch" the http response in my code? How can I display the response header? I could use simple http requests and get the responses easily but if there's an API, why not use it.
I'd be thankful for any help.

Upvotes: 0

Views: 778

Answers (1)

sixty4bit
sixty4bit

Reputation: 7956

Assuming you have set up your app with API credentials etc, you can "catch" the response by assigning it to a variable, like so:

customer = ShopifyAPI::Customer.find(674469828)
# now we can play around with the customer object

customer.name # => "Jimmy" 

If this doesn't help / is missing the point, please post a specific error message or server output that you are getting along with the specific request you made.

Upvotes: 1

Related Questions