base on ShopifyAPI is a lightweight gem for accessing the Shopify admin REST and GraphQL web services. # Shopify API Library for Ruby <!-- ![Build Status]() --> [![License: MIT](https://img.shields.io/badge/License-MIT-green.svg)](LICENSE) ![Build Status](https://github.com/Shopify/shopify-api-ruby/workflows/CI/badge.svg?branch=main) This library provides support for Ruby [Shopify apps](https://apps.shopify.com/) to access the [Shopify Admin API](https://shopify.dev/docs/api/admin), by making it easier to perform the following actions: - Creating [online](https://shopify.dev/docs/apps/auth/oauth/access-modes#online-access) or [offline](https://shopify.dev/docs/apps/auth/oauth/access-modes#offline-access) access tokens for the Admin API via OAuth - Making requests to the [REST API](https://shopify.dev/docs/api/admin-rest) - Making requests to the [GraphQL API](https://shopify.dev/docs/api/admin-graphql) - Registering/processing webhooks In addition to the Admin API, this library also allows querying the [Storefront API](https://shopify.dev/docs/api/storefront). You can use this library in any application that has a Ruby backend, since it doesn't rely on any specific framework — you can include it alongside your preferred stack and use the features that you need to build your app. **Note**: These instructions apply to v10 or later of this package. If you're running v9 in your app, you can find the documentation [in this branch](https://github.com/Shopify/shopify-api-ruby/tree/v9). ## Use with Rails If using in the Rails framework, we highly recommend you use the [shopify_app](https://github.com/Shopify/shopify_app) gem to interact with this gem. Authentication, session storage, webhook registration, and other frequently implemented paths are managed in that gem with easy to use configurations. ## Requirements To follow these usage guides, you will need to: - have a working knowledge of ruby and a web framework such as Rails or Sinatra - have a Shopify Partner account and development store - have an app already set up in your test store or partner account - add the URL and the appropriate redirect for your OAuth callback route to your app settings ## Installation Add the following to your Gemfile: ```sh gem "shopify_api" ``` or use [bundler](https://bundler.io): ```sh bundle add shopify_api ``` ## Steps to use the Gem ### Setup Shopify Context Start by initializing the `ShopifyAPI::Context` with the parameters of your app by calling `ShopifyAPI::Context.setup` (example below) when your app starts (e.g `application.rb` in a Rails app). ```ruby ShopifyAPI::Context.setup( api_key: "<api-key>", api_secret_key: "<api-secret-key>", host: "<https://application-host-name.com>", scope: "read_orders,read_products,etc", is_embedded: true, # Set to true if you are building an embedded app api_version: "2022-01", # The version of the API you would like to use is_private: false, # Set to true if you have an existing private app ) ``` ### Performing OAuth You need to go through OAuth as described [here](https://shopify.dev/docs/apps/auth/oauth) to create sessions for shops using your app. The Shopify API gem tries to make this easy by providing functions to begin and complete the OAuth process. See the [Oauth doc](docs/usage/oauth.md) for instructions on how to use these. ### Register Webhooks and a Webhook Handler If you intend to use webhooks in your application follow the steps in the [Webhooks doc](docs/usage/webhooks.md) for instructions on registering and handling webhooks. ### Start Making Authenticated Shopify API Requests Once your app can perform OAuth, it can now make authenticated Shopify API calls, see docs for: * Making [Admin REST API](docs/usage/rest.md) requests * Making [Admin GraphQL API](docs/usage/graphql.md) requests * Making [Storefront GraphQL API](docs/usage/graphql_storefront.md) requests ## Breaking Change Notices ### Breaking change notice for version 15.0.0 See [BREAKING_CHANGES_FOR_V15](BREAKING_CHANGES_FOR_V15.md) ### Breaking change notice for version 10.0.0 See [BREAKING_CHANGES_FOR_V10](BREAKING_CHANGES_FOR_V10.md) ### Breaking changes for older versions See [BREAKING_CHANGES_FOR_OLDER_VERSIONS](BREAKING_CHANGES_FOR_OLDER_VERSIONS.md) ## Developing this gem After cloning the repository, you can install the dependencies with bundler: ```bash bundle install ``` To run the automated tests: ```bash bundle exec rake test ``` We use [rubocop](https://rubocop.org) to lint/format the code. You can run it with the following command: ```bash bundle exec rubocop ``` ", Assign "at most 3 tags" to the expected json: {"id":"1406","tags":[]} "only from the tags list I provide: [{"id":77,"name":"3d"},{"id":89,"name":"agent"},{"id":17,"name":"ai"},{"id":54,"name":"algorithm"},{"id":24,"name":"api"},{"id":44,"name":"authentication"},{"id":3,"name":"aws"},{"id":27,"name":"backend"},{"id":60,"name":"benchmark"},{"id":72,"name":"best-practices"},{"id":39,"name":"bitcoin"},{"id":37,"name":"blockchain"},{"id":1,"name":"blog"},{"id":45,"name":"bundler"},{"id":58,"name":"cache"},{"id":21,"name":"chat"},{"id":49,"name":"cicd"},{"id":4,"name":"cli"},{"id":64,"name":"cloud-native"},{"id":48,"name":"cms"},{"id":61,"name":"compiler"},{"id":68,"name":"containerization"},{"id":92,"name":"crm"},{"id":34,"name":"data"},{"id":47,"name":"database"},{"id":8,"name":"declarative-gui "},{"id":9,"name":"deploy-tool"},{"id":53,"name":"desktop-app"},{"id":6,"name":"dev-exp-lib"},{"id":59,"name":"dev-tool"},{"id":13,"name":"ecommerce"},{"id":26,"name":"editor"},{"id":66,"name":"emulator"},{"id":62,"name":"filesystem"},{"id":80,"name":"finance"},{"id":15,"name":"firmware"},{"id":73,"name":"for-fun"},{"id":2,"name":"framework"},{"id":11,"name":"frontend"},{"id":22,"name":"game"},{"id":81,"name":"game-engine "},{"id":23,"name":"graphql"},{"id":84,"name":"gui"},{"id":91,"name":"http"},{"id":5,"name":"http-client"},{"id":51,"name":"iac"},{"id":30,"name":"ide"},{"id":78,"name":"iot"},{"id":40,"name":"json"},{"id":83,"name":"julian"},{"id":38,"name":"k8s"},{"id":31,"name":"language"},{"id":10,"name":"learning-resource"},{"id":33,"name":"lib"},{"id":41,"name":"linter"},{"id":28,"name":"lms"},{"id":16,"name":"logging"},{"id":76,"name":"low-code"},{"id":90,"name":"message-queue"},{"id":42,"name":"mobile-app"},{"id":18,"name":"monitoring"},{"id":36,"name":"networking"},{"id":7,"name":"node-version"},{"id":55,"name":"nosql"},{"id":57,"name":"observability"},{"id":46,"name":"orm"},{"id":52,"name":"os"},{"id":14,"name":"parser"},{"id":74,"name":"react"},{"id":82,"name":"real-time"},{"id":56,"name":"robot"},{"id":65,"name":"runtime"},{"id":32,"name":"sdk"},{"id":71,"name":"search"},{"id":63,"name":"secrets"},{"id":25,"name":"security"},{"id":85,"name":"server"},{"id":86,"name":"serverless"},{"id":70,"name":"storage"},{"id":75,"name":"system-design"},{"id":79,"name":"terminal"},{"id":29,"name":"testing"},{"id":12,"name":"ui"},{"id":50,"name":"ux"},{"id":88,"name":"video"},{"id":20,"name":"web-app"},{"id":35,"name":"web-server"},{"id":43,"name":"webassembly"},{"id":69,"name":"workflow"},{"id":87,"name":"yaml"}]" returns me the "expected json"