shopify_api 13.1.0 → 13.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/BREAKING_CHANGES_FOR_V10.md +231 -0
- data/CHANGELOG.md +8 -1
- data/Gemfile.lock +5 -5
- data/README.md +10 -34
- data/docs/README.md +0 -1
- data/docs/getting_started.md +20 -3
- data/docs/usage/custom_apps.md +75 -0
- data/docs/usage/graphql.md +63 -18
- data/docs/usage/oauth.md +160 -27
- data/docs/usage/rest.md +204 -62
- data/docs/usage/webhooks.md +22 -4
- data/lib/shopify_api/admin_versions.rb +2 -1
- data/lib/shopify_api/context.rb +5 -3
- data/lib/shopify_api/rest/base.rb +22 -14
- data/lib/shopify_api/rest/resources/2022_10/assigned_fulfillment_order.rb +5 -3
- data/lib/shopify_api/rest/resources/2022_10/customer_address.rb +10 -0
- data/lib/shopify_api/rest/resources/2022_10/fulfillment_request.rb +10 -0
- data/lib/shopify_api/rest/resources/2022_10/order_risk.rb +5 -3
- data/lib/shopify_api/rest/resources/2023_01/assigned_fulfillment_order.rb +5 -3
- data/lib/shopify_api/rest/resources/2023_01/balance.rb +4 -0
- data/lib/shopify_api/rest/resources/2023_01/customer_address.rb +10 -0
- data/lib/shopify_api/rest/resources/2023_01/fulfillment_request.rb +10 -0
- data/lib/shopify_api/rest/resources/2023_01/order.rb +3 -0
- data/lib/shopify_api/rest/resources/2023_01/order_risk.rb +5 -3
- data/lib/shopify_api/rest/resources/2023_01/shop.rb +0 -3
- data/lib/shopify_api/rest/resources/2023_01/variant.rb +1 -5
- data/lib/shopify_api/rest/resources/2023_04/assigned_fulfillment_order.rb +5 -3
- data/lib/shopify_api/rest/resources/2023_04/balance.rb +4 -0
- data/lib/shopify_api/rest/resources/2023_04/customer_address.rb +10 -0
- data/lib/shopify_api/rest/resources/2023_04/fulfillment_request.rb +10 -0
- data/lib/shopify_api/rest/resources/2023_04/order.rb +3 -0
- data/lib/shopify_api/rest/resources/2023_04/order_risk.rb +5 -3
- data/lib/shopify_api/rest/resources/2023_04/shop.rb +0 -3
- data/lib/shopify_api/rest/resources/2023_04/variant.rb +1 -5
- data/lib/shopify_api/rest/resources/2023_07/assigned_fulfillment_order.rb +5 -3
- data/lib/shopify_api/rest/resources/2023_07/balance.rb +4 -0
- data/lib/shopify_api/rest/resources/2023_07/customer_address.rb +10 -0
- data/lib/shopify_api/rest/resources/2023_07/fulfillment_request.rb +10 -0
- data/lib/shopify_api/rest/resources/2023_07/order.rb +3 -0
- data/lib/shopify_api/rest/resources/2023_07/order_risk.rb +5 -3
- data/lib/shopify_api/rest/resources/2023_07/report.rb +121 -0
- data/lib/shopify_api/rest/resources/2023_07/shop.rb +0 -3
- data/lib/shopify_api/rest/resources/2023_07/variant.rb +1 -5
- data/lib/shopify_api/rest/resources/2023_10/abandoned_checkout.rb +190 -0
- data/lib/shopify_api/rest/resources/2023_10/access_scope.rb +58 -0
- data/lib/shopify_api/rest/resources/2023_10/apple_pay_certificate.rb +105 -0
- data/lib/shopify_api/rest/resources/2023_10/application_charge.rb +109 -0
- data/lib/shopify_api/rest/resources/2023_10/application_credit.rb +91 -0
- data/lib/shopify_api/rest/resources/2023_10/article.rb +265 -0
- data/lib/shopify_api/rest/resources/2023_10/asset.rb +118 -0
- data/lib/shopify_api/rest/resources/2023_10/assigned_fulfillment_order.rb +88 -0
- data/lib/shopify_api/rest/resources/2023_10/balance.rb +54 -0
- data/lib/shopify_api/rest/resources/2023_10/blog.rb +162 -0
- data/lib/shopify_api/rest/resources/2023_10/cancellation_request.rb +83 -0
- data/lib/shopify_api/rest/resources/2023_10/carrier_service.rb +116 -0
- data/lib/shopify_api/rest/resources/2023_10/checkout.rb +209 -0
- data/lib/shopify_api/rest/resources/2023_10/collect.rb +142 -0
- data/lib/shopify_api/rest/resources/2023_10/collection.rb +110 -0
- data/lib/shopify_api/rest/resources/2023_10/collection_listing.rb +155 -0
- data/lib/shopify_api/rest/resources/2023_10/comment.rb +283 -0
- data/lib/shopify_api/rest/resources/2023_10/country.rb +137 -0
- data/lib/shopify_api/rest/resources/2023_10/currency.rb +57 -0
- data/lib/shopify_api/rest/resources/2023_10/custom_collection.rb +187 -0
- data/lib/shopify_api/rest/resources/2023_10/customer.rb +329 -0
- data/lib/shopify_api/rest/resources/2023_10/customer_address.rb +211 -0
- data/lib/shopify_api/rest/resources/2023_10/deprecated_api_call.rb +57 -0
- data/lib/shopify_api/rest/resources/2023_10/discount_code.rb +222 -0
- data/lib/shopify_api/rest/resources/2023_10/dispute.rb +111 -0
- data/lib/shopify_api/rest/resources/2023_10/dispute_evidence.rb +117 -0
- data/lib/shopify_api/rest/resources/2023_10/dispute_file_upload.rb +81 -0
- data/lib/shopify_api/rest/resources/2023_10/draft_order.rb +275 -0
- data/lib/shopify_api/rest/resources/2023_10/event.rb +148 -0
- data/lib/shopify_api/rest/resources/2023_10/fulfillment.rb +231 -0
- data/lib/shopify_api/rest/resources/2023_10/fulfillment_event.rb +166 -0
- data/lib/shopify_api/rest/resources/2023_10/fulfillment_order.rb +312 -0
- data/lib/shopify_api/rest/resources/2023_10/fulfillment_request.rb +97 -0
- data/lib/shopify_api/rest/resources/2023_10/fulfillment_service.rb +130 -0
- data/lib/shopify_api/rest/resources/2023_10/gift_card.rb +218 -0
- data/lib/shopify_api/rest/resources/2023_10/gift_card_adjustment.rb +118 -0
- data/lib/shopify_api/rest/resources/2023_10/image.rb +157 -0
- data/lib/shopify_api/rest/resources/2023_10/inventory_item.rb +108 -0
- data/lib/shopify_api/rest/resources/2023_10/inventory_level.rb +179 -0
- data/lib/shopify_api/rest/resources/2023_10/location.rb +167 -0
- data/lib/shopify_api/rest/resources/2023_10/locations_for_move.rb +56 -0
- data/lib/shopify_api/rest/resources/2023_10/marketing_event.rb +209 -0
- data/lib/shopify_api/rest/resources/2023_10/metafield.rb +344 -0
- data/lib/shopify_api/rest/resources/2023_10/mobile_platform_application.rb +110 -0
- data/lib/shopify_api/rest/resources/2023_10/order.rb +491 -0
- data/lib/shopify_api/rest/resources/2023_10/order_risk.rb +144 -0
- data/lib/shopify_api/rest/resources/2023_10/page.rb +194 -0
- data/lib/shopify_api/rest/resources/2023_10/payment.rb +140 -0
- data/lib/shopify_api/rest/resources/2023_10/payment_gateway.rb +143 -0
- data/lib/shopify_api/rest/resources/2023_10/payment_transaction.rb +107 -0
- data/lib/shopify_api/rest/resources/2023_10/payout.rb +97 -0
- data/lib/shopify_api/rest/resources/2023_10/policy.rb +69 -0
- data/lib/shopify_api/rest/resources/2023_10/price_rule.rb +223 -0
- data/lib/shopify_api/rest/resources/2023_10/product.rb +223 -0
- data/lib/shopify_api/rest/resources/2023_10/product_listing.rb +196 -0
- data/lib/shopify_api/rest/resources/2023_10/product_resource_feedback.rb +88 -0
- data/lib/shopify_api/rest/resources/2023_10/province.rb +132 -0
- data/lib/shopify_api/rest/resources/2023_10/recurring_application_charge.rb +172 -0
- data/lib/shopify_api/rest/resources/2023_10/redirect.rb +139 -0
- data/lib/shopify_api/rest/resources/2023_10/refund.rb +151 -0
- data/lib/shopify_api/rest/resources/2023_10/report.rb +121 -0
- data/lib/shopify_api/rest/resources/2023_10/resource_feedback.rb +73 -0
- data/lib/shopify_api/rest/resources/2023_10/script_tag.rb +155 -0
- data/lib/shopify_api/rest/resources/2023_10/shipping_zone.rb +83 -0
- data/lib/shopify_api/rest/resources/2023_10/shop.rb +218 -0
- data/lib/shopify_api/rest/resources/2023_10/smart_collection.rb +216 -0
- data/lib/shopify_api/rest/resources/2023_10/storefront_access_token.rb +87 -0
- data/lib/shopify_api/rest/resources/2023_10/tender_transaction.rb +93 -0
- data/lib/shopify_api/rest/resources/2023_10/theme.rb +123 -0
- data/lib/shopify_api/rest/resources/2023_10/transaction.rb +184 -0
- data/lib/shopify_api/rest/resources/2023_10/usage_charge.rb +102 -0
- data/lib/shopify_api/rest/resources/2023_10/user.rb +138 -0
- data/lib/shopify_api/rest/resources/2023_10/variant.rb +208 -0
- data/lib/shopify_api/rest/resources/2023_10/webhook.rb +168 -0
- data/lib/shopify_api/version.rb +1 -1
- data/lib/shopify_api/webhooks/registration.rb +19 -4
- data/lib/shopify_api/webhooks/registrations/event_bridge.rb +1 -1
- data/lib/shopify_api/webhooks/registrations/http.rb +1 -1
- data/lib/shopify_api/webhooks/registrations/pub_sub.rb +2 -1
- data/lib/shopify_api/webhooks/registry.rb +9 -5
- metadata +80 -6
- data/.github/workflows/stale.yml +0 -43
- data/docs/issues.md +0 -39
- data/docs/usage/session_storage.md +0 -46
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: b83eabed3d0c78f619d6061eb4bb92c389e1d15afca55225c243c0200a73f1f9
|
4
|
+
data.tar.gz: 2d6858dda679bb4a65f2eddbbc3d746f6177eda1808109a1ebcce943ae5cb9b9
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: fb175ef43080cec7459eff1a7a40c3d0c48aabc8b69bd8fe10fba1bdcfb3c3ca9a9d4e5e5bd6184421a0639f06b18097efa151c912439198f28838a6f60b5b67
|
7
|
+
data.tar.gz: 121a72ef9cc5b608b96d5be67a9404f739598708e9649fd720b21fa7614f2d53f162d2e12872441bf4419318d5cb7f13721606239ce21f9bbfa3868e1c4153f8
|
@@ -0,0 +1,231 @@
|
|
1
|
+
# Breaking change notice for version 10.0.0
|
2
|
+
|
3
|
+
We've rewritten this library for v10, so that it provides all essential features for a Shopify app without depending on the [Active Resource](https://github.com/rails/activeresource) or [graphql-client](https://github.com/github/graphql-client) libraries.
|
4
|
+
|
5
|
+
#### Table of Contents
|
6
|
+
- [New Features](#new-features)
|
7
|
+
- [Upgrade Guide](#upgrade-guide)
|
8
|
+
- [1. Configuration Changes](#1-configuration-changes)
|
9
|
+
- [2. Session Changes](#2-session-changes)
|
10
|
+
- [ShopifyAPI::Auth::Session](#shopifyapiauthsession)
|
11
|
+
- [3. API Client Changes](#3-api-client-changes)
|
12
|
+
- [GraphQL](#graphql)
|
13
|
+
- [Rest](#rest)
|
14
|
+
- [Using Rest Resources](#using-rest-resources)
|
15
|
+
- [Using Rest Admin Client](#using-rest-admin-client)
|
16
|
+
- [Generic HTTP Client](#generic-http-client)
|
17
|
+
- [Useful References](#useful-references)
|
18
|
+
|
19
|
+
## New Features
|
20
|
+
Here are the main features version 10 provides:
|
21
|
+
|
22
|
+
- OAuth support, both with online and offline tokens.
|
23
|
+
- Full, transparent support for JWT sessions for embedded apps and cookies for non-embedded ones.
|
24
|
+
- Removal of support for 3rd party cookies which are increasingly more difficult to use with modern browsers.
|
25
|
+
- Admin API support
|
26
|
+
- Auto-generated, version-specific REST resources which are similar to `ActiveResource` (though not identical), that provide methods for all endpoints defined in our [REST API reference](https://shopify.dev/docs/api/admin-rest), as well as direct definition of known attributes.
|
27
|
+
- A GraphQL client that doesn't rely on the ActiveResource implementation for REST.
|
28
|
+
- Webhook management, with features for adding handlers and registering them with Shopify.
|
29
|
+
- Storefront GraphQL API support
|
30
|
+
|
31
|
+
Please refer to the [Getting Started](docs/getting_started.md) guide in this repository for instructions on how to use each of these components.
|
32
|
+
|
33
|
+
### Reasoning
|
34
|
+
- Browsers stopped allowing 3rd party cookies, even after jumping through several [ITP](https://webkit.org/tracking-prevention-policy/) hoops, which made the code
|
35
|
+
even more more complex and error prone.
|
36
|
+
- Session tokens and `authenticatedFetch` were introduced to make it possible for apps to authenticate requests without depending on cookies.
|
37
|
+
- The gem was too closely tied to rails on how it sets up sessions (which worked for cookies), so we had to detach the library from rails
|
38
|
+
in order to be able to work with both cookies and session tokens.
|
39
|
+
- We previously relied on an `omniauth-oauth2` strategy that worked fine when cookies were the only option. But it became increasingly
|
40
|
+
awkward when we moved towards session tokens, which meant re-writing the OAuth process in the gem as a whole.
|
41
|
+
- Introducing a DB stored session persistence rather than cookie stored.
|
42
|
+
- Most feedback we got previously was due to the `ActiveResource` classes failing out of sync with the API because:
|
43
|
+
1. We have some endpoints that didn't 100% follow REST convention;
|
44
|
+
2. We had a single class for each resource and manually maintained custom methods that didn't work across API versions.
|
45
|
+
|
46
|
+
- To solve the REST problems:
|
47
|
+
- We were adding support for auto-generated, version-specific resources for other languages, we decided to add them for Ruby too.
|
48
|
+
But those same instances where the API doesn't follow convention would become problematic. Thus we opted for the most explicit option where **every** method was "custom" rather than just some, so that the resources were always consistent.
|
49
|
+
|
50
|
+
## Upgrade Guide
|
51
|
+
With this, a lot changed in how apps access the library. Here are the updates you should make when migrating to v10:
|
52
|
+
|
53
|
+
### 1. Configuration Changes
|
54
|
+
#### Removed ShopifyAPI::Base
|
55
|
+
`ShopifyAPI::Base` class has been removed. Previous versions of this gem used this class to configure API request setting like:
|
56
|
+
- **API request version**
|
57
|
+
- **Previously**: Set by `ShopifyAPI::Base.api_version = "xxxx"`
|
58
|
+
- **Change**: Configured `api_version` in [ShopifyAPI::Context.setup](#shopifyapicontextsetup)
|
59
|
+
- **Set `User-Agent` on API request header**
|
60
|
+
- **Previously**: Set by `ShopifyAPI::Base.header["User-Agent"] = "xxxxx"`
|
61
|
+
- **Change**: Configured `user_agent_prefix` in [ShopifyAPI::Context.setup](#shopifyapicontextsetup)
|
62
|
+
- **Set custom headers on API requests**
|
63
|
+
- **Previously**: Set by `ShopifyAPI::Base.header["User-Agent"] = "xxxxx"`
|
64
|
+
- **Change**: Custom headers can be added to requests when you use [`ShopifyAPI::Clients::HttpRequest`](https://github.com/Shopify/shopify-api-ruby/blob/main/lib/shopify_api/clients/http_request.rb#L14)
|
65
|
+
|
66
|
+
#### ShopifyAPI::Context.setup
|
67
|
+
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).
|
68
|
+
This class holds global configurations for your app and defines how the library behaves.
|
69
|
+
|
70
|
+
```ruby
|
71
|
+
ShopifyAPI::Context.setup(
|
72
|
+
api_key: "<api-key>",
|
73
|
+
api_secret_key: "<api-secret-key>",
|
74
|
+
host_name: "<application-host-name>",
|
75
|
+
scope: "read_orders,read_products,etc",
|
76
|
+
is_embedded: true, # Set to true if you are building an embedded app
|
77
|
+
is_private: false, # Set to true if you are building a private app
|
78
|
+
api_version: "2021-01" # The version of the API you would like to use
|
79
|
+
user_agent_prefix: "<user_agent_prefix>" # Set a custom prefix for "User-Agent" header when making API requests
|
80
|
+
###
|
81
|
+
)
|
82
|
+
```
|
83
|
+
|
84
|
+
See other fields accepted during `ShopifyAPI::Context` setup in [context.rb](https://github.com/Shopify/shopify-api-ruby/blob/main/lib/shopify_api/context.rb).
|
85
|
+
|
86
|
+
### 2. Session Changes
|
87
|
+
`ShopifyAPI::Base` class has been removed, you can no longer activate session using `ShopifyAPI::Base.activate_session`. Instead, you can use
|
88
|
+
`ShopifyAPI::Context.activate_session` to set the active session ([`ShopifyAPI::Auth::Session`](#shopifyapiauthsesion)).
|
89
|
+
If you're using the [ShopifyApp](https://github.com/Shopify/shopify_app) gem in a Rails app, you don't have to manually set the active session if you use the included `ActiveSupport` concerns. See [Session Docs](https://github.com/Shopify/shopify_app/blob/main/docs/shopify_app/sessions.md) from ShopifyApp gem.
|
90
|
+
|
91
|
+
You can also manually specify the session to use without setting the active session by passing in the session object ([`ShopifyAPI::Auth::Session`](#shopifyapiauthsesion)) when instantiating new `ShopifyAPI::Clients` objects.
|
92
|
+
If session is `nil`, it'll default to use active session from `ShopifyAPI::Context.active_session`.
|
93
|
+
|
94
|
+
```ruby
|
95
|
+
# Manually specifying a session (ShopifyAPI::Auth::Session) in API clients.
|
96
|
+
|
97
|
+
# GraphQL Client
|
98
|
+
graphql_client = ShopifyAPI::Clients::Graphql::Admin.new(session: session)
|
99
|
+
|
100
|
+
# REST Client
|
101
|
+
rest_client = ShopifyAPI::Clients::Rest::Admin.new(session: session)
|
102
|
+
|
103
|
+
# Using REST Resources
|
104
|
+
rest_resource = ShopifyAPI::Shop.new(session: session)
|
105
|
+
```
|
106
|
+
|
107
|
+
##### ShopifyAPI::Auth::Session
|
108
|
+
If you're building a Rails app, it is highly recommended for you to use the [`ShopifyApp` gem to perform OAuth and session storage](https://github.com/Shopify/shopify_app/blob/main/docs/shopify_app/sessions.md).
|
109
|
+
|
110
|
+
If you're not using Rails, please see the [Performing OAuth](./docs/usage/oauth.md) guide on how to perform OAuth to retrieve and store sessions.
|
111
|
+
|
112
|
+
### 3. API Client Changes
|
113
|
+
|
114
|
+
#### GraphQL
|
115
|
+
- We deprecated the dependency of [graphql-client](https://rubygems.org/gems/graphql-client) gem. You must refactor your existing query and response parsing to use our new GraphQL HTTP Client classes.
|
116
|
+
- [Admin API Client](https://github.com/Shopify/shopify-api-ruby/blob/main/lib/shopify_api/clients/graphql/admin.rb)
|
117
|
+
- [Storefront API Client](https://github.com/Shopify/shopify-api-ruby/blob/main/lib/shopify_api/clients/graphql/storefront.rb)
|
118
|
+
- There is no need to dump the schema to a local JSON file before using it anymore.
|
119
|
+
- The api version used to be set on `ShopifyAPI::Base.api_version`, however that's now deprecated.
|
120
|
+
You may specify a specific version when initializing your client, or it'll infer to `ShopifyAPI::Context.api_version` as default.
|
121
|
+
|
122
|
+
⚠️ See other Admin API usage in ["Make a GraphQL API call" documentation](https://github.com/Shopify/shopify-api-ruby/blob/main/docs/usage/graphql.md).
|
123
|
+
|
124
|
+
⚠️ See Storefront API client usage in ["Make a Storefront API call" documentation](https://github.com/Shopify/shopify-api-ruby/blob/main/docs/usage/graphql.md).
|
125
|
+
|
126
|
+
###### Example refactor
|
127
|
+
ShopifyAPI Client v9
|
128
|
+
```ruby
|
129
|
+
ShopifyAPI::Base.api_version = "2023-04"
|
130
|
+
client = ShopifyAPI::GraphQL.client
|
131
|
+
|
132
|
+
SHOP_NAME_QUERY = client.parse <<-'GRAPHQL'
|
133
|
+
{
|
134
|
+
shop {
|
135
|
+
name
|
136
|
+
}
|
137
|
+
}
|
138
|
+
GRAPHQL
|
139
|
+
|
140
|
+
result = client.query(SHOP_NAME_QUERY)
|
141
|
+
shop_name = result.data.shop.name
|
142
|
+
```
|
143
|
+
|
144
|
+
ShopifyAPI Client v10+
|
145
|
+
```ruby
|
146
|
+
client = ShopifyAPI::Clients::Graphql::Admin.new(session: session, api_version: "2023-04")
|
147
|
+
# session must be an instance of ShopifyAPI::Auth::Session, see Section - [2. Session Changes]
|
148
|
+
|
149
|
+
SHOP_NAME_QUERY =<<~QUERY
|
150
|
+
{
|
151
|
+
shop {
|
152
|
+
name
|
153
|
+
}
|
154
|
+
}
|
155
|
+
QUERY
|
156
|
+
|
157
|
+
response = client.query(query: query)
|
158
|
+
shop_name = response.body["data"]["shop"]["name"]
|
159
|
+
```
|
160
|
+
|
161
|
+
#### REST
|
162
|
+
##### Using REST Resources
|
163
|
+
- The use of `ActiveResource` has been deprecated, REST API requests must now be refactored to use the new format that better represents our REST API schema.
|
164
|
+
- Previously the api_version is specified in `ShopifyAPI::Base.api_version`, that has been deprecated. It's now configured in [`ShopifyAPI::Context.setup`](#shopifyapicontextsetup).
|
165
|
+
|
166
|
+
###### Example refactor
|
167
|
+
⚠️ You can find detailed examples on how each of the resource endpoints work in our [REST reference documentation](https://shopify.dev/docs/api/admin-rest).
|
168
|
+
|
169
|
+
Please see below a (non-exhaustive) list of common replacements to guide you in your updates, using the `Order` resource as an example.
|
170
|
+
For more detail, see [`order` reference documentation's](https://shopify.dev/docs/api/admin-rest/2023-07/resources/order#top) ruby example.
|
171
|
+
|
172
|
+
|Usage | Before| After |
|
173
|
+
| -----| --- | --- |
|
174
|
+
|Find partially paid orders| `Order.find(:all, params: {financial_status: "partially_paid"})`| `Order.all(financial_status: "partially_paid")` |
|
175
|
+
|Find order by ID `<id>` | `Order.find(<id>)` | `Order.find(id: <id>)` |
|
176
|
+
|Update an order's fulfillment status|`order = Order.find<id>`<br/>`order.fulfillment_status = "fulfilled"`<br/>`order.note = "Fulfilled on September 6, 2023"`<br/>`order.save`|`order = Order.find(id: <id>)`<br/>`order.fulfillment_status = "fulfilled"`<br/>`order.note = "Fulfilled on September 6, 2023"`<br/>`order.save!`|
|
177
|
+
|Close an order| `order = Order.new(<id>)`<br/>`order.post(:close)` | `order = Order.find(id: <id>)`<br/>`order.close` |
|
178
|
+
|Delete an order| `order = Order.new(<id>)`<br/>`order.delete` | `Order.delete(id: <id>)` |
|
179
|
+
|
180
|
+
###### Note on resource connections
|
181
|
+
Previously we added helper methods to load related resource connections like [`orders.transactions`](https://github.com/Shopify/shopify-api-ruby/blob/97eec35fb76afbce1d948cee2963791457e934da/lib/shopify_api/resources/order.rb#L20).
|
182
|
+
After the upgrade, only connected properties listed in the REST API will be supported.
|
183
|
+
|
184
|
+
For example:
|
185
|
+
- `order.transactions` is not supported because `transactions` is not a property of the `Order` resource.
|
186
|
+
- `order.customer` is supported because `customer` is a property of the `Order` resource.
|
187
|
+
|
188
|
+
[See the full list of `Order` properties here.](https://shopify.dev/docs/api/admin-rest/2023-07/resources/order#resource-object)
|
189
|
+
|
190
|
+
##### Using REST Admin Client
|
191
|
+
If you do not want to use the REST resource classes, you can use our REST Admin client directly to make HTTP requests.
|
192
|
+
|
193
|
+
⚠️ See other REST client usage in ["Make a REST API call" documentation](https://github.com/Shopify/shopify-api-ruby/blob/main/docs/usage/rest.md).
|
194
|
+
|
195
|
+
Example:
|
196
|
+
```ruby
|
197
|
+
# Create a new client.
|
198
|
+
client = ShopifyAPI::Clients::Rest::Admin.new(session: session)
|
199
|
+
|
200
|
+
# Update title for product with ID <id>
|
201
|
+
body = {
|
202
|
+
product: {
|
203
|
+
title: "My cool product"
|
204
|
+
}
|
205
|
+
}
|
206
|
+
|
207
|
+
# Use `client.put` to send your request to the specified Shopify Admin REST API endpoint.
|
208
|
+
client.put(path: "products/<id>.json", body: body)
|
209
|
+
```
|
210
|
+
|
211
|
+
#### Generic HTTP Client
|
212
|
+
We added a new generic [HttpClient](https://github.com/Shopify/shopify-api-ruby/blob/main/lib/shopify_api/clients/http_client.rb) wrapper to make requests and handle Shopify specific errors. All of the REST and GraphQL Clients use this HTTP Client in its foundation.
|
213
|
+
You can use this to make direct HTTP API calls easily.
|
214
|
+
See how the GraphQL Client makes a request with this HttpClient class in its [implementation here](https://github.com/Shopify/shopify-api-ruby/blob/main/lib/shopify_api/clients/graphql/client.rb#L33-L45).
|
215
|
+
|
216
|
+
## Useful references
|
217
|
+
|
218
|
+
ShopifyAPI:
|
219
|
+
- [Performing OAuth](https://github.com/Shopify/shopify-api-ruby/blob/main/docs/usage/oauth.md)
|
220
|
+
- [Make a GraphQL API Call](https://github.com/Shopify/shopify-api-ruby/blob/main/docs/usage/graphql.md)
|
221
|
+
- [Make a Storefront API Call (GraphQL)](https://github.com/Shopify/shopify-api-ruby/blob/main/docs/usage/graphql_storefront.md)
|
222
|
+
- [Make a REST API Call](https://github.com/Shopify/shopify-api-ruby/blob/main/docs/usage/rest.md)
|
223
|
+
- [Webhooks](https://github.com/Shopify/shopify-api-ruby/blob/main/docs/usage/webhooks.md)
|
224
|
+
|
225
|
+
ShopifyApp Gem (Rails):
|
226
|
+
- [Authentication](https://github.com/Shopify/shopify_app/blob/main/docs/shopify_app/authentication.md)
|
227
|
+
- [Sessions](https://github.com/Shopify/shopify_app/blob/main/docs/shopify_app/sessions.md)
|
228
|
+
|
229
|
+
Shopify API:
|
230
|
+
- [Admin GraphQL Reference](https://shopify.dev/docs/api/admin-graphql)
|
231
|
+
- [Admin REST Reference](https://shopify.dev/docs/api/admin-rest)
|
data/CHANGELOG.md
CHANGED
@@ -4,6 +4,13 @@ Note: For changes to the API, see https://shopify.dev/changelog?filter=api
|
|
4
4
|
|
5
5
|
## Unreleased
|
6
6
|
|
7
|
+
## 13.2.0
|
8
|
+
|
9
|
+
- [#1183](https://github.com/Shopify/shopify-api-ruby/pull/1189) Added string array support for fields parameter in Webhook::Registry
|
10
|
+
- [1208](https://github.com/Shopify/shopify-api-ruby/pull/1208) Fix CustomerAddress and FulfillmentRequest methods
|
11
|
+
- [1225](https://github.com/Shopify/shopify-api-ruby/pull/1225) Support for 2023_10 API version
|
12
|
+
- [#1186](https://github.com/Shopify/shopify-api-ruby/pull/1186) Extend webhook registration to support metafield_namespaces
|
13
|
+
|
7
14
|
## 13.1.0
|
8
15
|
|
9
16
|
- [#1183](https://github.com/Shopify/shopify-api-ruby/pull/1183) Added support for API version 2023-07
|
@@ -14,7 +21,7 @@ Note: For changes to the API, see https://shopify.dev/changelog?filter=api
|
|
14
21
|
|
15
22
|
- [#1140](https://github.com/Shopify/shopify-api-ruby/pull/1140) ⚠️ [Breaking] Reformat Http error messages to be JSON parsable.
|
16
23
|
- [#1142](https://github.com/Shopify/shopify-api-ruby/issues/1142) Restore API version 2022-04, in alignment with [this](https://shopify.dev/changelog/action-required-support-for-api-version-2022-04-extended-to-june-30-2023) changelog notice.
|
17
|
-
- [#1155](https://github.com/Shopify/shopify-api-ruby/pull/1155) ⚠️ [Breaking] Remove session storage that was deprecated with [#1055](https://github.com/Shopify/shopify-api-ruby/pull/1055). ⚠️ [Breaking] GraphQL Proxy now requires `session` to be passed as an argument.
|
24
|
+
- [#1155](https://github.com/Shopify/shopify-api-ruby/pull/1155) ⚠️ [Breaking] Remove session storage that was deprecated with [#1055](https://github.com/Shopify/shopify-api-ruby/pull/1055). To upgrade, remove `session_storage` from your API context block. ⚠️ [Breaking] GraphQL Proxy now requires `session` to be passed as an argument.
|
18
25
|
- [#1150](https://github.com/Shopify/shopify-api-ruby/pull/1150) [Patch] Add support for Event topic names.
|
19
26
|
|
20
27
|
## 12.5.0
|
data/Gemfile.lock
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
shopify_api (13.
|
4
|
+
shopify_api (13.2.0)
|
5
5
|
activesupport
|
6
6
|
concurrent-ruby
|
7
7
|
hash_diff
|
@@ -16,7 +16,7 @@ PATH
|
|
16
16
|
GEM
|
17
17
|
remote: https://rubygems.org/
|
18
18
|
specs:
|
19
|
-
activesupport (7.0.
|
19
|
+
activesupport (7.0.7.2)
|
20
20
|
concurrent-ruby (~> 1.0, >= 1.0.2)
|
21
21
|
i18n (>= 1.6, < 2)
|
22
22
|
minitest (>= 5.1)
|
@@ -42,12 +42,12 @@ GEM
|
|
42
42
|
jwt (2.7.1)
|
43
43
|
language_server-protocol (3.17.0.1)
|
44
44
|
method_source (1.0.0)
|
45
|
-
mini_mime (1.1.
|
45
|
+
mini_mime (1.1.5)
|
46
46
|
minitest (5.15.0)
|
47
47
|
mocha (1.13.0)
|
48
48
|
multi_xml (0.6.0)
|
49
49
|
netrc (0.11.0)
|
50
|
-
oj (3.
|
50
|
+
oj (3.16.0)
|
51
51
|
openssl (3.1.0)
|
52
52
|
parallel (1.22.1)
|
53
53
|
parser (3.1.2.1)
|
@@ -133,7 +133,7 @@ GEM
|
|
133
133
|
yard-sorbet (0.7.0)
|
134
134
|
sorbet-runtime (>= 0.5)
|
135
135
|
yard (>= 0.9)
|
136
|
-
zeitwerk (2.6.
|
136
|
+
zeitwerk (2.6.11)
|
137
137
|
|
138
138
|
PLATFORMS
|
139
139
|
arm64-darwin-21
|
data/README.md
CHANGED
@@ -17,6 +17,9 @@ You can use this library in any application that has a Ruby backend, since it do
|
|
17
17
|
|
18
18
|
**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).
|
19
19
|
|
20
|
+
## Use with Rails
|
21
|
+
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.
|
22
|
+
|
20
23
|
## Requirements
|
21
24
|
|
22
25
|
To follow these usage guides, you will need to:
|
@@ -67,46 +70,19 @@ The Shopify API gem tries to make this easy by providing functions to begin and
|
|
67
70
|
|
68
71
|
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.
|
69
72
|
|
70
|
-
### Start Making Authenticated Shopify Requests
|
73
|
+
### Start Making Authenticated Shopify API Requests
|
71
74
|
|
72
|
-
Once your app can perform OAuth, it can now make authenticated Shopify API calls
|
75
|
+
Once your app can perform OAuth, it can now make authenticated Shopify API calls, see docs for:
|
76
|
+
* Making [Admin REST API](docs/usage/rest.md) requests
|
77
|
+
* Making [Admin GraphQL API](docs/usage/graphql.md) requests
|
78
|
+
* Making [Storefront GraphQL API](docs/usage/graphql_storefront.md) requests
|
73
79
|
|
74
80
|
## Breaking Change Notices
|
75
81
|
|
76
82
|
### Breaking change notice for version 10.0.0
|
83
|
+
See [BREAKING_CHANGES_FOR_V10](BREAKING_CHANGES_FOR_V10.md)
|
77
84
|
|
78
|
-
|
79
|
-
|
80
|
-
Here are the main features it provides:
|
81
|
-
|
82
|
-
- OAuth support, both with online and offline tokens.
|
83
|
-
- Full, transparent support for JWT sessions for embedded apps and cookies for non-embedded ones.
|
84
|
-
- Removal of support for 3rd party cookies which are increasingly more difficult to use with modern browsers.
|
85
|
-
- Admin API support
|
86
|
-
- Auto-generated, version-specific REST resources which are similar to `ActiveResource` (though not identical), that provide methods for all endpoints defined in our [REST API reference](https://shopify.dev/docs/api/admin-rest), as well as direct definition of known attributes.
|
87
|
-
- A GraphQL client that doesn't rely on the ActiveResource implementation for REST.
|
88
|
-
- Webhook management, with features for adding handlers and registering them with Shopify.
|
89
|
-
- Storefront GraphQL API support
|
90
|
-
|
91
|
-
Please refer to [the documentation](docs/getting_started.md) in this repository for instructions on how to use each of these components.
|
92
|
-
|
93
|
-
With this, a lot changed in how apps access the library. Here are the updates you should make when migrating to v10:
|
94
|
-
|
95
|
-
- Call `ShopifyAPI::Context.setup` when setting up your app. This class holds global configurations for your app and defines how the library behaves.
|
96
|
-
- If not using the `shopify_app` gem, your app needs to provide an implementation of `ShopifyAPI::Auth::SessionStorage` for production. Read more about this [in our documentation](docs/usage/session_storage.md).
|
97
|
-
- To change the `User-Agent` header, use `user_agent_prefix` in `ShopifyAPI::Context.setup`.
|
98
|
-
- Usages of the `ActiveResource` classes for REST API requests need to be refactored into the new format. You can find detailed examples on how each of the endpoints work in our [reference documentation](https://shopify.dev/docs/api/admin-rest).
|
99
|
-
|
100
|
-
Please see below a (non-exhaustive) list of common replacements to guide you in your updates, using the `Order` resource as an example.
|
101
|
-
|
102
|
-
| Before | After |
|
103
|
-
| --- | --- |
|
104
|
-
| `Order.find(:all, params: {param1: value1})` | `Order.all(param1: value1)` |
|
105
|
-
| `Order.find(<id>)` | `Order.find(id: <id>)` |
|
106
|
-
| `order = Order.new(<id>)`<br/>`order.post(:close)` | `order = Order.new`<br/>`order.close` |
|
107
|
-
| `order = Order.new(<id>)`<br/>`order.delete` | `Order.delete(id: <id>)` |
|
108
|
-
|
109
|
-
## Breaking changes for older versions
|
85
|
+
### Breaking changes for older versions
|
110
86
|
|
111
87
|
See [BREAKING_CHANGES_FOR_OLDER_VERSIONS](BREAKING_CHANGES_FOR_OLDER_VERSIONS.md)
|
112
88
|
|
data/docs/README.md
CHANGED
data/docs/getting_started.md
CHANGED
@@ -37,10 +37,27 @@ ShopifyAPI::Context.setup(
|
|
37
37
|
Next, unless you are making a private app, you need to go through OAuth as described [here](https://shopify.dev/docs/apps/auth/oauth) to create sessions for shops using your app.
|
38
38
|
The Shopify API gem tries to make this easy by providing functions to begin and complete the OAuth process. See the [Oauth doc](usage/oauth.md) for instructions on how to use these.
|
39
39
|
|
40
|
-
###
|
40
|
+
### Sessions
|
41
41
|
|
42
|
-
|
42
|
+
Sessions are required to make requests with the REST or GraphQL clients. This Library provides helpers for creating sessions via OAuth. Helpers are provided to retrieve session ID from a HTTP request from an embedded Shopify app or cookies from non-embedded apps.
|
43
|
+
|
44
|
+
Session persistence is handled by the [ShopifyApp](https://github.com/Shopify/shopify_app) gem and is recommended for use in the Rails context. See that gem for documentation on how to use it.
|
45
|
+
|
46
|
+
#### Cookie
|
47
|
+
Cookie based authentication is not supported for embedded apps due to browsers dropping support for third party cookies due to security concerns. Non-embedded apps are able to use cookies for session storage/retrieval.
|
48
|
+
|
49
|
+
For *non-embedded* apps, you can pass the cookies into `ShopifyAPI::Utils::SessionUtils.current_session_id(nil, cookies, true)` for online (user) sessions or `ShopifyAPI::Utils::SessionUtils.current_session_id(nil, cookies, false)` for offline (store) sessions.
|
50
|
+
|
51
|
+
#### Getting Session ID From Embedded Requests
|
52
|
+
For *embedded* apps, you can pass the auth header into `ShopifyAPI::Utils::SessionUtils.current_session_id(auth_header, nil, true)` for online (user) sessions or `ShopifyAPI::Utils::SessionUtils.current_session_id(auth_header, nil, false)` for offline (store) sessions. This function needs an `auth_header` which is the `HTTP_AUTHORIZATION` header.
|
43
53
|
|
44
|
-
|
54
|
+
If your app uses client side rendering instead of server side rendering, you will need to use App Bridge's [authenticatedFetch](https://shopify.dev/docs/apps/auth/oauth/session-tokens/getting-started) to make authenticated API requests from the client.
|
55
|
+
|
56
|
+
#### Start Making Authenticated Shopify Requests
|
45
57
|
|
46
58
|
You can now start making authenticated Shopify API calls using the Admin [REST](usage/rest.md) or [GraphQL](usage/graphql.md) Clients or the [Storefront GraphQL Client](usage/graphql_storefront.md).
|
59
|
+
|
60
|
+
### Register Webhooks and a Webhook Handler
|
61
|
+
|
62
|
+
If you intend to use webhooks in your application follow the steps in the [Webhooks doc](usage/webhooks.md) for instructions on registering and handling webhooks.
|
63
|
+
|
@@ -0,0 +1,75 @@
|
|
1
|
+
# Custom Apps
|
2
|
+
|
3
|
+
If you have followed instructions on creating [custom apps](https://help.shopify.com/current/manual/apps/app-types/custom-apps), you should be able to access your API token without having to go through the OAuth flow.
|
4
|
+
|
5
|
+
You can follow instructions for [initializing the session object](#initializing-the-session-object) to construct the session object to be used in authenticated API calls to your store. There are 2 methods to use the session object to make API calls:
|
6
|
+
1. [Passing `session` object into each client request](#passing-session-object-into-each-client-request)
|
7
|
+
2. [Setting `active_session` in `ShopifyAPI::Context`](#setting-active-session-in-shopifyapicontext)
|
8
|
+
|
9
|
+
## Initializing the Session object
|
10
|
+
Following is a basic example to construct a simple Session object. You can see full list of parameters for this object in the [class definition](https://github.com/Shopify/shopify-api-ruby/blob/main/lib/shopify_api/auth/session.rb)
|
11
|
+
```ruby
|
12
|
+
session = ShopifyAPI::Auth::Session.new(
|
13
|
+
shop: "#{your_shop_name}.myshopify.com"
|
14
|
+
access_token: "the_token_for_your_custom_app_found_in_admin"
|
15
|
+
)
|
16
|
+
|
17
|
+
```
|
18
|
+
## Using `Session` to make API calls
|
19
|
+
|
20
|
+
### Passing `session` object into each client request
|
21
|
+
Example:
|
22
|
+
```ruby
|
23
|
+
def make_api_request(shop)
|
24
|
+
# 1. create session object
|
25
|
+
session = ShopifyAPI::Auth::Session.new(
|
26
|
+
shop: "#{your_shop_name}.myshopify.com"
|
27
|
+
access_token: "the_token_for_your_custom_app_found_in_admin"
|
28
|
+
)
|
29
|
+
|
30
|
+
# 2a. Create API client with the session information
|
31
|
+
# session must be type `ShopifyAPI::Auth::Session`
|
32
|
+
graphql_client = ShopifyAPI::Clients::Graphql::Admin.new(session: session)
|
33
|
+
response = graphql_client.query(query: MY_API_QUERY)
|
34
|
+
|
35
|
+
# 2b. REST example
|
36
|
+
product_count = ShopifyAPI::Product.count(session: session)
|
37
|
+
|
38
|
+
...
|
39
|
+
end
|
40
|
+
```
|
41
|
+
|
42
|
+
### Setting `active_session` in `ShopifyAPI::Context`
|
43
|
+
Alternatively, if you don't want to keep having to create/retrieve a Session object for a shop, you may set [`ShopifyAPI::Context.active_session`](https://github.com/Shopify/shopify-api-ruby/blob/main/lib/shopify_api/context.rb#L144).
|
44
|
+
All of the API client classes will [use the `active_session`](https://github.com/Shopify/shopify-api-ruby/blob/c3bb9d8f8b6053756149a4cf9299e059ec337544/lib/shopify_api/clients/http_client.rb#L13) if the `session` passed in is `nil`.
|
45
|
+
|
46
|
+
Example:
|
47
|
+
```ruby
|
48
|
+
#### Configuration
|
49
|
+
def configure_app
|
50
|
+
# This method is called before making authenticated API calls
|
51
|
+
session = ShopifyAPI::Auth::Session.new(
|
52
|
+
shop: "#{your_shop_name}.myshopify.com"
|
53
|
+
access_token: "the_token_for_your_custom_app_found_in_admin"
|
54
|
+
)
|
55
|
+
|
56
|
+
# Activate session to be used in all API calls
|
57
|
+
# session must be type `ShopifyAPI::Auth::Session`
|
58
|
+
ShopifyAPI::Context.activate_session(session)
|
59
|
+
end
|
60
|
+
|
61
|
+
#### Using clients to make authenticated API calls
|
62
|
+
def make_api_request
|
63
|
+
# 1. Create API client without session information
|
64
|
+
# The graphql_client will use `ShopifyAPI::Context.active_session` when making API calls
|
65
|
+
graphql_client = ShopifyAPI::Clients::Graphql::Admin.new
|
66
|
+
|
67
|
+
# 2. Use API client to make queries
|
68
|
+
...
|
69
|
+
end
|
70
|
+
|
71
|
+
```
|
72
|
+
|
73
|
+
⚠️ See following docs on how to use the API clients:
|
74
|
+
- [Make a GraphQL API call](https://github.com/Shopify/shopify-api-ruby/blob/main/docs/usage/graphql.md)
|
75
|
+
- [Make a REST API call](https://github.com/Shopify/shopify-api-ruby/blob/main/docs/usage/rest.md)
|
data/docs/usage/graphql.md
CHANGED
@@ -1,17 +1,37 @@
|
|
1
1
|
# Make a GraphQL API call
|
2
2
|
|
3
|
-
Once
|
3
|
+
Once OAuth is complete, we can use `ShopifyAPI::Clients::Graphql::Admin` to make authenticated API calls to the Shopify Admin GraphQL API.
|
4
|
+
#### Required Session
|
5
|
+
Every API request requires a valid
|
6
|
+
[ShopifyAPI::Auth::Session](https://github.com/Shopify/shopify-api-ruby/blob/main/lib/shopify_api/auth/session.rb).
|
7
|
+
|
8
|
+
To instantiate a session, we recommend you either use the `shopify_app` if working in Rails, or refer to our OAuth docs on constructing a session:
|
9
|
+
- ["Custom Apps"](https://github.com/Shopify/shopify-api-ruby/blob/main/docs/usage/custom_apps.md) - documentation on how to create Session from a custom app API token.
|
10
|
+
- ["Performing OAuth"](https://github.com/Shopify/shopify-api-ruby/blob/main/docs/usage/oauth.md) - documentation on how to create new sessions
|
11
|
+
- [[ShopifyApp] - "Session"](https://github.com/Shopify/shopify_app/blob/main/docs/shopify_app/sessions.md) - documentation on session handling if you're using the [`ShopifyApp`](https://github.com/Shopify/shopify_app) gem.
|
12
|
+
|
13
|
+
### Instantiation
|
14
|
+
Create an instance of [`ShopifyAPI::Clients::Graphql::Admin`](https://github.com/Shopify/shopify-api-ruby/blob/main/lib/shopify_api/clients/graphql/admin.rb) using the current session to make requests to the Admin API.
|
15
|
+
|
16
|
+
#### Constructor parameters
|
17
|
+
| Parameter | Type | Notes |
|
18
|
+
| ----------|------|-------|
|
19
|
+
| `session` | `ShopifyAPI::Auth::Session` | Default value is `nil`. <br><br>When `nil` is passed in, active session information is inferred from `ShopifyAPI::Context.active_session`. <br>To set active session, use `ShopifyAPI::Context.activate_session`. <br><br>This is handled automatically behind the scenes if you use ShopifyApp's [session controllers](https://github.com/Shopify/shopify_app/blob/main/docs/shopify_app/sessions.md). |
|
20
|
+
| `api_version` | `String` | Default value is `nil`. When `nil` is passed in, api version is inferred from [`ShopifyAPI::Context.setup`](https://github.com/Shopify/shopify-api-ruby/blob/main/README.md#setup-shopify-context).|
|
21
|
+
|
22
|
+
Usage:
|
23
|
+
```ruby
|
24
|
+
client = ShopifyAPI::Clients::Graphql::Admin.new(session: session, api_version: "unstable")
|
25
|
+
```
|
4
26
|
|
5
|
-
|
27
|
+
### Making Authenticated API calls
|
28
|
+
#### Basic example
|
6
29
|
|
7
30
|
```ruby
|
8
|
-
#
|
9
|
-
session = ShopifyAPI::Utils::SessionUtils.load_current_session(auth_header: <auth-header>, cookies: <cookies>, is_online: <true|false>)
|
10
|
-
|
11
|
-
# initalize the client
|
31
|
+
# Initialize the client
|
12
32
|
client = ShopifyAPI::Clients::Graphql::Admin.new(session: session)
|
13
33
|
|
14
|
-
#
|
34
|
+
# Make the GraphQL query string
|
15
35
|
query =<<~QUERY
|
16
36
|
{
|
17
37
|
products(first: 10) {
|
@@ -28,10 +48,13 @@ query =<<~QUERY
|
|
28
48
|
QUERY
|
29
49
|
|
30
50
|
response = client.query(query: query)
|
51
|
+
|
31
52
|
# do something with the response data
|
53
|
+
product = response.body["data"]["products"]["edges"][0]
|
54
|
+
my_function(product)
|
32
55
|
```
|
33
56
|
|
34
|
-
|
57
|
+
#### Example GraphQL query with variables
|
35
58
|
|
36
59
|
```ruby
|
37
60
|
client = ShopifyAPI::Clients::Graphql::Admin.new(session: session)
|
@@ -50,18 +73,19 @@ query = <<~QUERY
|
|
50
73
|
}
|
51
74
|
}
|
52
75
|
QUERY
|
76
|
+
|
53
77
|
variables = {
|
54
78
|
first: 3
|
55
79
|
}
|
56
80
|
|
57
81
|
response = client.query(query: query, variables: variables)
|
58
|
-
|
59
82
|
```
|
60
83
|
|
61
|
-
|
84
|
+
#### Example GraphQL query with fragments
|
62
85
|
|
63
86
|
```ruby
|
64
87
|
client = ShopifyAPI::Clients::Graphql::Admin.new(session: session)
|
88
|
+
|
65
89
|
# define the fragment as part of the query
|
66
90
|
query = <<~QUERY
|
67
91
|
fragment ProductStuff on Product {
|
@@ -81,29 +105,47 @@ query = <<~QUERY
|
|
81
105
|
}
|
82
106
|
}
|
83
107
|
QUERY
|
108
|
+
|
84
109
|
variables = {
|
85
110
|
first: 3
|
86
111
|
}
|
112
|
+
|
87
113
|
response = client.query(query: query, variables: variables)
|
88
|
-
# do something with the
|
114
|
+
# do something with the response
|
89
115
|
```
|
90
116
|
|
91
|
-
By default, the client uses the API version configured in `ShopifyAPI`. To use a different API version, set the optional `api_version` parameter. To experiment with prerelease API features, use `"unstable"` for the API version.
|
92
117
|
|
93
|
-
|
94
|
-
|
95
|
-
|
118
|
+
### Output
|
119
|
+
#### Success
|
120
|
+
If the request is successful these methods will all return a [`ShopifyAPI::Clients::HttpResponse`](https://github.com/Shopify/shopify-api-ruby/blob/main/lib/shopify_api/clients/http_response.rb) object, which has the following methods:
|
121
|
+
| Methods | Type | Notes |
|
122
|
+
|---------|------|-------|
|
123
|
+
| `code` |`Integer`| HTTP Response code, e.g. `200`|
|
124
|
+
| `header` |`Hash{String, [String]}` | HTTP Response headers |
|
125
|
+
| `body` | `Hash{String, Untyped}` | HTTP Response body |
|
126
|
+
| `prev_page_info` | `String` | See [Pagination](#pagination)|
|
127
|
+
| `next_page_info` | `String` | See [Pagination](#pagination)|
|
96
128
|
|
97
|
-
|
129
|
+
#### Failure
|
130
|
+
If the request has failed, an error will be raised describing what went wrong.
|
131
|
+
You can rescue [`ShopifyAPI::Errors::HttpResponseError`](https://github.com/Shopify/shopify-api-ruby/blob/main/lib/shopify_api/errors/http_response_error.rb)
|
132
|
+
and output error messages with `errors.full_messages`
|
98
133
|
|
99
|
-
|
134
|
+
## Pagination
|
100
135
|
|
101
|
-
|
136
|
+
This library also supports cursor-based pagination for GraphQL Admin API requests. [Learn more about GraphQL request pagination](https://shopify.dev/docs/api/usage/pagination-graphql).
|
137
|
+
|
138
|
+
After making a request, the `next_page_info` and `prev_page_info` can be found on the response object and be used in the query param in other requests.
|
139
|
+
|
140
|
+
## Proxy a GraphQL Query
|
141
|
+
|
142
|
+
If you would like to give your front end the ability to make authenticated graphql queries to the Shopify Admin API, the `shopify_api` gem makes proxy-ing a graphql request easy! The gem provides a utility function which will accept the raw request body (a GraphQL query), the headers, and the cookies (optional). It will add authentication to the request, proxy it to the Shopify Admin API, and return a `ShopifyAPI::Clients::HttpResponse`. An example utilization of this in Rails is shown below:
|
102
143
|
|
103
144
|
```ruby
|
104
145
|
def proxy
|
105
146
|
begin
|
106
147
|
response = ShopifyAPI::Utils::GraphqlProxy.proxy_query(
|
148
|
+
session: session,
|
107
149
|
headers: request.headers.to_h,
|
108
150
|
body: request.raw_post,
|
109
151
|
cookies: request.cookies.to_h
|
@@ -119,3 +161,6 @@ end
|
|
119
161
|
```
|
120
162
|
|
121
163
|
**Note:** GraphQL proxying is only supported for online sessions for non-private apps, the utility will raise a `ShopifyAPI::Errors::SessionNotFoundError` if there are no existing online tokens for the provided credentials, and a `ShopifyAPI::Errors::PrivateAppError` if called from a private app.
|
164
|
+
|
165
|
+
## Storefront API
|
166
|
+
⚠️ Want to make calls to the Storefront API? [Read this](graphql_storefront.md).
|