Giter Club home page Giter Club logo

shopify_api_console's Introduction

Shopify API Console for Ruby

Build Status

⚠️ Important:

  • As of August 2021, this gem is no longer maintained and the repository has been archived. You can still fork this repo if you want to make modifications to it.
  • This gem was renamed in June 2019. It was named shopify_cli previously.

If you're looking for Shopify CLI, refer to the official docs or contribute on GitHub.

shopify_cli 1.x will not be supported going forward. v1.0.3+ will produce a deprecation warning.

Starting with v2.0, the gem has been renamed to shopify_api_console. We recommend switching to shopify_api_console v2.0+ as soon as possible.

1.x versions will continue to exist on RubyGems and in the GitHub releases. If you must use one of these releases, make sure to specify a version:

gem install shopify_cli -v v1.0.4

Getting started

This tutorial will get you started using the Shopify API console in development.

Requirements

Before you begin using the console, you'll need a few things:

Set up your development store

To become a Shopify Partner, sign up for a free Shopify Partner account.

As a Shopify Partner, you gain access to the Partner Dashboard. From the Partner Dashboard, you can create a development store.

Open up your development store and populate it with orders, customers, products — whatever you might need to properly develop your app.

Create an API key for a private app

To access the Shopify API console, you need to create a dedicated private app in your development store with the permissions required to access resources. You'll use this private app's API credentials when setting up your Shopify API Console Ruby gem. Creating the private app generates its API key and password.

Learn more about creating API keys for private apps.

Install the required gems

After you've set up your development store, created the private app, and have your API key, install the Shopify API and Shopify API Console Ruby gems.

gem install shopify_api shopify_api_console

Using the console

Open up your terminal, and type shopify-api.

$ shopify-api
Commands:
  shopify-api add CONNECTION        # create a config file for a connection named...
  shopify-api console [CONNECTION]  # start an API console for CONNECTION
  shopify-api default [CONNECTION]  # show the default connection, or make CONNEC...
  shopify-api edit [CONNECTION]     # open the config file for CONNECTION with yo...
  shopify-api help [COMMAND]        # Describe available commands or one specific...
  shopify-api list                  # list available connections
  shopify-api remove CONNECTION     # remove the config file for CONNECTION
  shopify-api show [CONNECTION]     # output the location and contents of the CON...

You’re presented with options for setting up and managing connection configuration. Nothing is set up yet, so start by adding a connection. Name it whatever you like, but make sure that the URL matches up with that of your development store. You’ll be prompted to enter in your API key and password. Be sure to enter the API password, not secret. To learn more about Shopify API release schedule to find the API version, please read Shopify API Versioning

$ shopify-api add myshopifystore
Domain? (leave blank for myshopifystore.myshopify.com) myshopifystore.myshopify.com
open https://myshopifystore.myshopify.com/admin/apps/private in your browser to get API credentials
API key? [REDACTED]
Password? [REDACTED]
API version? Leave blank for the latest version
create  .shopify/shops/myshopifystore.yml
remove  .shopify/shops/default
Default connection is myshopifystore

Now, start the console. Type shopify-api console:

$ shopify-api console
using myshopifystore.myshopify.com

To make things easier, you can include the ShopifyAPI module provided by the Shopify API gem right away. This is optional, but if you leave it off, you’ll need to prefix API calls with ShopifyAPI::.

> include ShopifyAPI

Now you can start to query the API and look at data from your store. Check out the API docs to see what is queryable and mutable.

To get a list of products, type Product.all:

> Product.all

Try mutating some data; add a customer with the following values:

{
  first_name: 'Firstname',
  last_name: 'Lastname',
  email: '[email protected]',
  addresses: [
    {
      address1: '123 Fake St',
      city: 'Townsville',
      province: 'ON',
      phone: '555-1212',
      zip: '123ABC',
      last_name: 'Lastname',
      first_name: 'Firstname',
      country: 'CA'
    }
  ],
  send_email_invite: true
}
> i = ShopifyAPI::Customer.new({first_name: 'Firstname', last_name: 'Lastname', email: '[email protected]', addresses: [{ address1: '123 Fake St', city: 'Townsville',  province: 'ON', phone: '555-1212', zip: '123ABC', last_name: 'Lastname', first_name: 'Firstname', country: 'CA' }], send_email_invite: true })
> i.save
 => true

Don’t forget to save the entry!

You’ve now successfully added a customer to your dev store, and sent them an email invitation.

More complex calls

Get a list of resources using query parameters

Find all of a given resource type (e.g. Products, Customers, etc.), using the limit parameter to limit the results:

> Product.find(:all, :params => {:limit => 3})

Update a resource

Add a description to an existing resource:

> i = CustomCollection.find(7724148)
 => #<ShopifyAPI::CustomCollection:0x007fd47c57acf8 @attributes={"body_html"=>nil, "handle"=>"frontpage", "id"=>7724148, "published_at"=>2012-07-06 17:57:28 UTC, "sort_order"=>"alpha-asc", "template_suffix"=>nil, "title"=>"Frontpage", "updated_at"=>2013-01-31 21:55:21 UTC}, @prefix_options={}>
> i.body_html = 'Give the collection a new description'
 => "Give the collection a new description"
> i.save
 => true
> CustomCollection.find(7724148)
 => #<ShopifyAPI::CustomCollection:0x007fd47c5f1ba0 @attributes={"body_html"=>"Give the collection a new description", "handle"=>"frontpage", "id"=>7724148, "published_at"=>2012-07-06 17:57:28 UTC, "sort_order"=>"alpha-asc", "template_suffix"=>nil, "title"=>"Frontpage", "updated_at"=>2013-02-26 04:21:41 UTC}, @prefix_options={}>

Troubleshooting

By making a small change to the earlier example, you can see how to troubleshoot errors. Change the entry slightly to set a password instead of sending an email invite, and then save the entry.

{
  first_name: 'Firstname',
  last_name: 'Lastname',
  email: '[email protected]',
  addresses: [
    {
      address1: '123 Fake St',
      city: 'Townsville',
      province: 'ON',
      phone: '555-1212',
      zip: '123ABC',
      last_name: 'Lastname',
      first_name: 'Firstname',
      country: 'CA'
    }
  ],
  password: '1234',
  password_confirmation: '1234'
}

Trying to save this data fails:

> i.save
 => false

Type i.errors to find out why. You’ll get some information back on what you tried to POST, and some information on the error:

@remote_errors=#<ActiveResource::ResourceInvalid: Failed.  Response code = 422.  Response message = Unprocessable Entity.>, @validation_context=nil, @errors=#<ActiveResource::Errors:0x007fc814173b60 ...>>, @messages={:password=>["is too short (minimum is 5 characters)"], :email=>["has already been taken"]

It didn’t work because the password is too short, and the email address is already registered to the first customer you created. You’ve just quickly and easily debugged why an API call wasn’t working!

Contributing

After checking out the source, run:

$ bundle install && bundle exec rake test

shopify_api_console's People

Contributors

anduong avatar chrisbutcher avatar csaunders avatar gfscott avatar nwtn avatar shopify-rails[bot] avatar supportbeam avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

shopify_api_console's Issues

commands fail since no API Versioning is presented to the base connection

Using Ruby 2.4.2 the gem works fine.

p = ShopifyAPI::Product.count
=> 52

Using Ruby 2.6.2 the gem fails. A simple call to a product exits as follows

p = ShopifyAPI::Product.count

NoMethodError: undefined method `construct_api_path' for nil:NilClass
from /Users/dlazar/.rvm/gems/ruby-2.6.2/gems/shopify_api- 
7.0.1/lib/shopify_api/resources/base.rb:84:in `prefix'

This was fixable by adding an API Version to the base connection in the method site_from_config

ShopifyAPI::Base.api_version = '2019-04'

fails with ruby 2.3.1

Hi,

Trying to use this gem with Ruby 2.3.1 and it blows out on not finding activesupport =2.3.0 which is amusing seeing as activesupport is now at version 5.0

Rails 6: cannot install gem because thor has conflicting versions

Bundler could not find compatible versions for gem "thor":
In snapshot (Gemfile.lock):
thor (= 0.20.3)

In Gemfile:
rails (~> 6.0.0) was resolved to 6.0.0, which depends on
railties (= 6.0.0) was resolved to 6.0.0, which depends on
thor (>= 0.20.3, < 2.0)

shopify_api_console was resolved to 2.0.0, which depends on
  thor (~> 0.18.1)

Aborts trying invalid path to Rails

I ran into a problem when running shopify create project shopify-cli-demo. It wanted to run rails from an old ruby location that did not have rails. In other words, /Users/rcapozzi/.gem/ruby/2.3.7/bin exists, but /Users/rcapozzi/.gem/ruby/2.3.7/bin/rails does not exist.

I rm -fr /Users/rcapozzi/.gem/ruby/2.3.7 (mostly b/c I like removing ruby) and that resolved the problem.

$ which rails
/usr/local/lib/ruby/gems/2.6.0/bin/rails
This command ran with ID: 19937
Please include this information in any issues/report along with relevant logs
/Users/rcapozzi/.shopify-app-cli/vendor/deps/cli-kit/lib/cli/kit/system.rb:114:in `spawn': No such file or directory - /Users/rcapozzi/.gem/ruby/2.3.7/bin/rails (Errno::ENOENT)
from /Users/rcapozzi/.shopify-app-cli/vendor/deps/cli-kit/lib/cli/kit/system.rb:114:in `system'
from /Users/rcapozzi/.shopify-app-cli/lib/shopify-cli/context/system.rb:11:in `system'
from /Users/rcapozzi/.shopify-app-cli/lib/shopify-cli/app_types/rails.rb:54:in `block in build'
from /Users/rcapozzi/.shopify-app-cli/vendor/deps/cli-ui/lib/cli/ui/frame.rb:82:in `open'
from /Users/rcapozzi/.shopify-app-cli/lib/shopify-cli/app_types/rails.rb:53:in `build'
from /Users/rcapozzi/.shopify-app-cli/lib/shopify-cli/app_type_registry.rb:12:in `build'
from /Users/rcapozzi/.shopify-app-cli/lib/shopify-cli/commands/create/project.rb:19:in `call'
from /Users/rcapozzi/.shopify-app-cli/lib/shopify-cli/sub_command.rb:12:in `call'
from /Users/rcapozzi/.shopify-app-cli/lib/shopify-cli/command.rb:16:in `call'
from /Users/rcapozzi/.shopify-app-cli/vendor/deps/cli-kit/lib/cli/kit/executor.rb:17:in `block (2 levels) in call'
from /Users/rcapozzi/.shopify-app-cli/vendor/deps/cli-kit/lib/cli/kit/executor.rb:39:in `block (2 levels) in with_logging'
from /Users/rcapozzi/.shopify-app-cli/vendor/deps/cli-ui/lib/cli/ui/stdout_router.rb:164:in `with_id'
from /Users/rcapozzi/.shopify-app-cli/vendor/deps/cli-kit/lib/cli/kit/executor.rb:38:in `block in with_logging'
from /Users/rcapozzi/.shopify-app-cli/vendor/deps/cli-ui/lib/cli/ui.rb:143:in `log_output_to'
from /Users/rcapozzi/.shopify-app-cli/vendor/deps/cli-kit/lib/cli/kit/executor.rb:37:in `with_logging'
from /Users/rcapozzi/.shopify-app-cli/vendor/deps/cli-kit/lib/cli/kit/executor.rb:15:in `block in call'
from /Users/rcapozzi/.shopify-app-cli/vendor/deps/cli-kit/lib/cli/kit/executor.rb:47:in `block (2 levels) in with_traps'
from /Users/rcapozzi/.shopify-app-cli/vendor/deps/cli-kit/lib/cli/kit/executor.rb:57:in `twrap'
from /Users/rcapozzi/.shopify-app-cli/vendor/deps/cli-kit/lib/cli/kit/executor.rb:46:in `block in with_traps'
from /Users/rcapozzi/.shopify-app-cli/vendor/deps/cli-kit/lib/cli/kit/executor.rb:57:in `twrap'
from /Users/rcapozzi/.shopify-app-cli/vendor/deps/cli-kit/lib/cli/kit/executor.rb:45:in `with_traps'
from /Users/rcapozzi/.shopify-app-cli/vendor/deps/cli-kit/lib/cli/kit/executor.rb:14:in `call'
from /Users/rcapozzi/.shopify-app-cli/lib/shopify-cli/executor.rb:16:in `call'
from /Users/rcapozzi/.shopify-app-cli/lib/shopify-cli/entry_point.rb:16:in `block in call'
from /Users/rcapozzi/.shopify-app-cli/lib/shopify-cli/monorail/log.rb:44:in `event'
from /Users/rcapozzi/.shopify-app-cli/lib/shopify-cli/monorail/log.rb:28:in `invocation'
from /Users/rcapozzi/.shopify-app-cli/lib/shopify-cli/entry_point.rb:15:in `call'
from /Users/rcapozzi/.shopify-app-cli/bin/shopify:37:in `block in <main>'
from /Users/rcapozzi/.shopify-app-cli/vendor/deps/cli-kit/lib/cli/kit/error_handler.rb:75:in `handle_abort'
from /Users/rcapozzi/.shopify-app-cli/vendor/deps/cli-kit/lib/cli/kit/error_handler.rb:21:in `call'
from /Users/rcapozzi/.shopify-app-cli/bin/shopify:36:in

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.