README.rdoc 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. = Shopify API
  2. The Shopify API gem allows Ruby developers to programmatically access the admin section of Shopify stores.
  3. The API is implemented as XML over HTTP using all four verbs (GET/POST/PUT/DELETE). Each resource, like Order, Product, or Collection, has its own URL and is manipulated in isolation. In other words, we’ve tried to make the API follow the REST principles as much as possible.
  4. == Usage
  5. === Requirements
  6. All API usage happens through Shopify applications, created by either shop owners for their own shops, or by Shopify Partners for use by other shop owners:
  7. * Shop owners can create applications for themselves through their own admin (under the Preferences > Applications tab).
  8. * Shopify Partners create applications through their admin: http://app.shopify.com/services/partners
  9. For more information and detailed documentation about the API visit http://api.shopify.com
  10. === Getting Started
  11. ShopifyAPI uses ActiveResource to communicate with the REST web service. ActiveResource has to be configured with a fully authorized URL of a particular store first. To obtain that URL you can follow these steps:
  12. 1. First create a new application in either the partners admin or your store admin and write down your API_KEY and SHARED_SECRET.
  13. 2. You will need to supply two parameters to the Session class before you instantiate it:
  14. ShopifyAPI::Session.setup({:api_key => API_KEY, :secret => SHARED_SECRET})
  15. 3. To access a shop's data apps need an access token from that specific shop. This is a two-stage process. Before interacting with a shop for the first time an app should redirect the user to the following URL:
  16. GET https://SHOP_NAME.myshopify.com/admin/oauth/authorize
  17. with the following parameters:
  18. * client_id – Required – The API key for your app
  19. * scope – Required – The list of required scopes (explained below)
  20. * redirect_uri – Optional – The URL that the merchant will be sent to once authentication is complete. Must be the same host as the Return URL specified in the application settings
  21. 4. Once authorized, the shop redirects the owner to the return URL of your application with a parameter named 'code'. This is a temporary token the the app can exchange for a permanent access token. Make the following call:
  22. POST https://SHOP_NAME.myshopify.com/admin/oauth/access_token
  23. with the following parameters:
  24. * client_id – Required – The API key for your app
  25. * client_secret – Required – The shared secret for your app
  26. * code – Required – The token you received in step 3
  27. and you'll get your permanent access token back in the response.
  28. 5. Use that token to instantiate a session that is ready to make calls to the given shop.
  29. token = params[:access_token]
  30. session = ShopifyAPI::Session.new("yourshopname.myshopify.com", token)
  31. session.valid? # returns true
  32. 5. Now you can activate the session and you're set:
  33. ShopifyAPI::Base.activate_session(session)
  34. 6. Get data from that shop (returns ActiveResource instances):
  35. shop = ShopifyAPI::Shop.current
  36. latest_orders = ShopifyAPI::Order.find(:all)
  37. Alternatively, you can use #temp to initialize a Session and execute a command which also handles temporarily setting ActiveResource::Base.site:
  38. latest_orders = ShopifyAPI::Session.temp("yourshopname.myshopify.com", token) { ShopifyAPI::Order.find(:all) }
  39. 7. Finally, you can also clear the session (for example if you want to work with another shop):
  40. ShopifyAPI::Base.clear_session
  41. == Questions or Problems?
  42. http://api.shopify.com <= Read the tech docs!
  43. http://wiki.shopify.com/Developer_Home <= Read the wiki!
  44. http://ecommerce.shopify.com/c/shopify-apis-and-technology <= Ask questions on the forums!
  45. == Copyright
  46. Copyright (c) 2012 "Shopify inc.". See LICENSE for details.