shopify_api 14.3.0 → 14.4.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_V15.md +42 -0
- data/CHANGELOG.md +12 -0
- data/Gemfile.lock +2 -2
- data/README.md +3 -0
- data/docs/usage/oauth.md +88 -16
- data/lib/shopify_api/admin_versions.rb +2 -1
- data/lib/shopify_api/clients/graphql/client.rb +3 -2
- data/lib/shopify_api/clients/graphql/storefront.rb +4 -2
- data/lib/shopify_api/rest/resources/2022_04/shop.rb +2 -2
- data/lib/shopify_api/rest/resources/2022_07/shop.rb +2 -2
- data/lib/shopify_api/rest/resources/2022_10/shop.rb +2 -2
- data/lib/shopify_api/rest/resources/2023_01/shop.rb +2 -2
- data/lib/shopify_api/rest/resources/2023_04/shop.rb +2 -2
- data/lib/shopify_api/rest/resources/2023_07/shop.rb +2 -2
- data/lib/shopify_api/rest/resources/2023_10/shop.rb +2 -2
- data/lib/shopify_api/rest/resources/2024_01/shop.rb +2 -2
- data/lib/shopify_api/rest/resources/2024_04/shop.rb +2 -2
- data/lib/shopify_api/rest/resources/2024_07/abandoned_checkout.rb +194 -0
- data/lib/shopify_api/rest/resources/2024_07/access_scope.rb +62 -0
- data/lib/shopify_api/rest/resources/2024_07/apple_pay_certificate.rb +109 -0
- data/lib/shopify_api/rest/resources/2024_07/application_charge.rb +113 -0
- data/lib/shopify_api/rest/resources/2024_07/application_credit.rb +95 -0
- data/lib/shopify_api/rest/resources/2024_07/article.rb +269 -0
- data/lib/shopify_api/rest/resources/2024_07/asset.rb +122 -0
- data/lib/shopify_api/rest/resources/2024_07/assigned_fulfillment_order.rb +92 -0
- data/lib/shopify_api/rest/resources/2024_07/balance.rb +58 -0
- data/lib/shopify_api/rest/resources/2024_07/blog.rb +166 -0
- data/lib/shopify_api/rest/resources/2024_07/cancellation_request.rb +87 -0
- data/lib/shopify_api/rest/resources/2024_07/carrier_service.rb +120 -0
- data/lib/shopify_api/rest/resources/2024_07/checkout.rb +213 -0
- data/lib/shopify_api/rest/resources/2024_07/collect.rb +146 -0
- data/lib/shopify_api/rest/resources/2024_07/collection.rb +114 -0
- data/lib/shopify_api/rest/resources/2024_07/collection_listing.rb +159 -0
- data/lib/shopify_api/rest/resources/2024_07/comment.rb +287 -0
- data/lib/shopify_api/rest/resources/2024_07/country.rb +141 -0
- data/lib/shopify_api/rest/resources/2024_07/currency.rb +61 -0
- data/lib/shopify_api/rest/resources/2024_07/custom_collection.rb +191 -0
- data/lib/shopify_api/rest/resources/2024_07/customer.rb +333 -0
- data/lib/shopify_api/rest/resources/2024_07/customer_address.rb +215 -0
- data/lib/shopify_api/rest/resources/2024_07/deprecated_api_call.rb +61 -0
- data/lib/shopify_api/rest/resources/2024_07/discount_code.rb +226 -0
- data/lib/shopify_api/rest/resources/2024_07/dispute.rb +115 -0
- data/lib/shopify_api/rest/resources/2024_07/dispute_evidence.rb +121 -0
- data/lib/shopify_api/rest/resources/2024_07/dispute_file_upload.rb +85 -0
- data/lib/shopify_api/rest/resources/2024_07/draft_order.rb +279 -0
- data/lib/shopify_api/rest/resources/2024_07/event.rb +152 -0
- data/lib/shopify_api/rest/resources/2024_07/fulfillment.rb +235 -0
- data/lib/shopify_api/rest/resources/2024_07/fulfillment_event.rb +167 -0
- data/lib/shopify_api/rest/resources/2024_07/fulfillment_order.rb +326 -0
- data/lib/shopify_api/rest/resources/2024_07/fulfillment_request.rb +101 -0
- data/lib/shopify_api/rest/resources/2024_07/fulfillment_service.rb +134 -0
- data/lib/shopify_api/rest/resources/2024_07/gift_card.rb +222 -0
- data/lib/shopify_api/rest/resources/2024_07/gift_card_adjustment.rb +122 -0
- data/lib/shopify_api/rest/resources/2024_07/image.rb +161 -0
- data/lib/shopify_api/rest/resources/2024_07/inventory_item.rb +112 -0
- data/lib/shopify_api/rest/resources/2024_07/inventory_level.rb +183 -0
- data/lib/shopify_api/rest/resources/2024_07/location.rb +171 -0
- data/lib/shopify_api/rest/resources/2024_07/locations_for_move.rb +60 -0
- data/lib/shopify_api/rest/resources/2024_07/marketing_event.rb +213 -0
- data/lib/shopify_api/rest/resources/2024_07/metafield.rb +348 -0
- data/lib/shopify_api/rest/resources/2024_07/mobile_platform_application.rb +114 -0
- data/lib/shopify_api/rest/resources/2024_07/order.rb +489 -0
- data/lib/shopify_api/rest/resources/2024_07/order_risk.rb +148 -0
- data/lib/shopify_api/rest/resources/2024_07/page.rb +198 -0
- data/lib/shopify_api/rest/resources/2024_07/payment.rb +144 -0
- data/lib/shopify_api/rest/resources/2024_07/payment_gateway.rb +147 -0
- data/lib/shopify_api/rest/resources/2024_07/payment_transaction.rb +114 -0
- data/lib/shopify_api/rest/resources/2024_07/payout.rb +101 -0
- data/lib/shopify_api/rest/resources/2024_07/policy.rb +73 -0
- data/lib/shopify_api/rest/resources/2024_07/price_rule.rb +227 -0
- data/lib/shopify_api/rest/resources/2024_07/product.rb +227 -0
- data/lib/shopify_api/rest/resources/2024_07/product_listing.rb +200 -0
- data/lib/shopify_api/rest/resources/2024_07/product_resource_feedback.rb +92 -0
- data/lib/shopify_api/rest/resources/2024_07/province.rb +136 -0
- data/lib/shopify_api/rest/resources/2024_07/recurring_application_charge.rb +176 -0
- data/lib/shopify_api/rest/resources/2024_07/redirect.rb +143 -0
- data/lib/shopify_api/rest/resources/2024_07/refund.rb +155 -0
- data/lib/shopify_api/rest/resources/2024_07/resource_feedback.rb +77 -0
- data/lib/shopify_api/rest/resources/2024_07/script_tag.rb +159 -0
- data/lib/shopify_api/rest/resources/2024_07/shipping_zone.rb +87 -0
- data/lib/shopify_api/rest/resources/2024_07/shop.rb +222 -0
- data/lib/shopify_api/rest/resources/2024_07/smart_collection.rb +220 -0
- data/lib/shopify_api/rest/resources/2024_07/storefront_access_token.rb +91 -0
- data/lib/shopify_api/rest/resources/2024_07/tender_transaction.rb +97 -0
- data/lib/shopify_api/rest/resources/2024_07/theme.rb +127 -0
- data/lib/shopify_api/rest/resources/2024_07/transaction.rb +188 -0
- data/lib/shopify_api/rest/resources/2024_07/usage_charge.rb +106 -0
- data/lib/shopify_api/rest/resources/2024_07/user.rb +142 -0
- data/lib/shopify_api/rest/resources/2024_07/variant.rb +212 -0
- data/lib/shopify_api/rest/resources/2024_07/webhook.rb +172 -0
- data/lib/shopify_api/version.rb +1 -1
- data/lib/shopify_api/webhooks/registry.rb +5 -4
- metadata +80 -6
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: cc6cb9b900f3eba7d192c4d5091308edeaff8245517254af586192f72f57417c
|
4
|
+
data.tar.gz: bb86d0654b8aa58ce70c017707ac700cb51094467608119d75d2235942483d85
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d7a256c3ce166b787b5a21d228fe25d73fc2ea1f0bbe2fca6896c3c07bae3300336c1c2efc7943d7a0096cdfd99bd0938d81fe1c097a39b2ef2f9ee931edbea2
|
7
|
+
data.tar.gz: 42c03e72834f764f6435c7f81286ef45502a36819ce4647eb6a346eb48e349d6f6f59dd5913bef591d4a45ae95e339d6bea9c016109d9d6bec0c077fc86bf29c
|
@@ -0,0 +1,42 @@
|
|
1
|
+
# Breaking change notice for version 15.0.0
|
2
|
+
|
3
|
+
## Removal of `ShopifyAPI::Webhooks::Handler`
|
4
|
+
|
5
|
+
The `ShopifyAPI::Webhooks::Handler` class has been removed in favor of `ShopifyAPI::Webhooks::WebhookHandler`. The `ShopifyAPI::Webhooks::WebhookHandler` class is now the recommended way to handle webhooks.
|
6
|
+
|
7
|
+
Make a module or class that includes or extends `ShopifyAPI::Webhooks::WebhookHandler` and implement the `handle` method which accepts the following named parameters: data: `WebhookMetadata`.
|
8
|
+
|
9
|
+
In v14, adding new fields to the callback would become a breaking change. To make this code more flexible, handlers will now receive an object that can be typed and extended.
|
10
|
+
|
11
|
+
`data` will have the following keys
|
12
|
+
- `topic`, `String` - The topic of the webhook
|
13
|
+
- `shop`, `String` - The shop domain of the webhook
|
14
|
+
- `body`, `T::Hash[String, T.untyped]`- The body of the webhook
|
15
|
+
- `webhook_id`, `String` - The id of the webhook event to [avoid duplicates](https://shopify.dev/docs/apps/webhooks/best-practices#ignore-duplicates)
|
16
|
+
- `api_version`, `String` - The api version of the webhook
|
17
|
+
|
18
|
+
### New implementation
|
19
|
+
```ruby
|
20
|
+
module WebhookHandler
|
21
|
+
extend ShopifyAPI::Webhooks::WebhookHandler
|
22
|
+
|
23
|
+
class << self
|
24
|
+
def handle_webhook(data:)
|
25
|
+
puts "Received webhook! topic: #{data.topic} shop: #{data.shop} body: #{data.body} webhook_id: #{data.webhook_id} api_version: #{data.api_version"
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
29
|
+
```
|
30
|
+
|
31
|
+
### Previous implementation
|
32
|
+
```ruby
|
33
|
+
module WebhookHandler
|
34
|
+
include ShopifyAPI::Webhooks::Handler
|
35
|
+
|
36
|
+
class << self
|
37
|
+
def handle(topic:, shop:, body:)
|
38
|
+
puts "Received webhook! topic: #{topic} shop: #{shop} body: #{body}"
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
42
|
+
```
|
data/CHANGELOG.md
CHANGED
@@ -4,8 +4,15 @@ Note: For changes to the API, see https://shopify.dev/changelog?filter=api
|
|
4
4
|
|
5
5
|
## Unreleased
|
6
6
|
|
7
|
+
## 14.4.0
|
8
|
+
|
9
|
+
- [#1325](https://github.com/Shopify/shopify-api-ruby/pull/1325) Add support for 2024-07 API version
|
10
|
+
- [#1320](https://github.com/Shopify/shopify-api-ruby/pull/1320) Fix sorbet type on Shop.tax_shipping field
|
11
|
+
|
7
12
|
## 14.3.0
|
13
|
+
|
8
14
|
- [#1312](https://github.com/Shopify/shopify-api-ruby/pull/1312) Use same leeway for `exp` and `nbf` when parsing JWT
|
15
|
+
- [#1313](https://github.com/Shopify/shopify-api-ruby/pull/1313) Fix: Webhook Registry now working with response_as_struct enabled
|
9
16
|
- [#1314](https://github.com/Shopify/shopify-api-ruby/pull/1314)
|
10
17
|
- Add new session util method `SessionUtils::session_id_from_shopify_id_token`
|
11
18
|
- `SessionUtils::current_session_id` now accepts shopify Id token in the format of `Bearer this_token` or just `this_token`
|
@@ -15,9 +22,11 @@ Note: For changes to the API, see https://shopify.dev/changelog?filter=api
|
|
15
22
|
- `expires_at` alias for `exp` - returns the expiration time
|
16
23
|
|
17
24
|
## 14.2.0
|
25
|
+
|
18
26
|
- [#1309](https://github.com/Shopify/shopify-api-ruby/pull/1309) Add `Session#copy_attributes_from` method
|
19
27
|
|
20
28
|
## 14.1.0
|
29
|
+
|
21
30
|
- [#1071](https://github.com/Shopify/shopify-api-ruby/issues/1071) Fix FulfillmentEvent class types
|
22
31
|
- Fix: InventoryItem class `harmonized_system_code` attribute type which can be either integer, string or nil
|
23
32
|
- Fix: Variant class `inventory_quantity` attribute type which can be either integer, string or nil
|
@@ -26,10 +35,12 @@ Note: For changes to the API, see https://shopify.dev/changelog?filter=api
|
|
26
35
|
- [1305](https://github.com/Shopify/shopify-api-ruby/pull/1305/) Adds support for the `2024-04` API version.
|
27
36
|
|
28
37
|
## 14.0.1
|
38
|
+
|
29
39
|
- [#1288](https://github.com/Shopify/shopify-api-ruby/pull/1288) Fix FeatureDeprecatedError being raised without a message.
|
30
40
|
- [1290](https://github.com/Shopify/shopify-api-ruby/pull/1290) Move deprecation of `ShopifyAPI::Webhooks::Handler#handle` to version 15.0.0
|
31
41
|
|
32
42
|
## 14.0.0
|
43
|
+
|
33
44
|
- [#1274](https://github.com/Shopify/shopify-api-ruby/pull/1274) ⚠️ [Breaking] Update sorbet and rbi dependencies. Remove support for ruby 2.7. Minimum required Ruby version is 3.0
|
34
45
|
- [#1282](https://github.com/Shopify/shopify-api-ruby/pull/1282) Fixes a bug where diffing attributes to update not take into account of Array changes and required ids.
|
35
46
|
- [#1254](https://github.com/Shopify/shopify-api-ruby/pull/1254) Introduce token exchange API for fetching access tokens. This feature is currently unstable and cannot be used yet.
|
@@ -37,6 +48,7 @@ Note: For changes to the API, see https://shopify.dev/changelog?filter=api
|
|
37
48
|
- [#1275](https://github.com/Shopify/shopify-api-ruby/pull/1275) Allow adding custom headers in REST Resource HTTP calls.
|
38
49
|
|
39
50
|
## 13.4.0
|
51
|
+
|
40
52
|
- [#1210](https://github.com/Shopify/shopify-api-ruby/pull/1246) Add context option `response_as_struct` to allow GraphQL API responses to be accessed via dot notation.
|
41
53
|
- [#1257](https://github.com/Shopify/shopify-api-ruby/pull/1257) Add `api_call_limit` and `retry_request_after` to REST resources to expose rate limit information.
|
42
54
|
- [#1257](https://github.com/Shopify/shopify-api-ruby/pull/1257) Added support for the 2024-01 API version. This also includes a fix for the `for_hash` option when creating resources.
|
data/Gemfile.lock
CHANGED
data/README.md
CHANGED
@@ -79,6 +79,9 @@ Once your app can perform OAuth, it can now make authenticated Shopify API calls
|
|
79
79
|
|
80
80
|
## Breaking Change Notices
|
81
81
|
|
82
|
+
### Breaking change notice for version 15.0.0
|
83
|
+
See [BREAKING_CHANGES_FOR_V15](BREAKING_CHANGES_FOR_V15.md)
|
84
|
+
|
82
85
|
### Breaking change notice for version 10.0.0
|
83
86
|
See [BREAKING_CHANGES_FOR_V10](BREAKING_CHANGES_FOR_V10.md)
|
84
87
|
|
data/docs/usage/oauth.md
CHANGED
@@ -5,31 +5,103 @@ Once the library is set up for your project, you'll be able to use it to start a
|
|
5
5
|
To do this, you can follow the steps below.
|
6
6
|
For more information on authenticating a Shopify app please see the [Types of Authentication](https://shopify.dev/docs/apps/auth#types-of-authentication) page.
|
7
7
|
|
8
|
+
#### Table of contents
|
9
|
+
- [Session Persistence](#session-persistence)
|
10
|
+
- [Supported types of OAuth Flow](#supported-types-of-oauth)
|
11
|
+
- [Note about Rails](#note-about-rails)
|
12
|
+
- [Performing OAuth](#performing-oauth-1)
|
13
|
+
- [Token Exchange](#token-exchange)
|
14
|
+
- [Authorization Code Grant Flow](#authorization-code-grant-flow)
|
15
|
+
- [Using OAuth Session to make authenticated API calls](#using-oauth-session-to-make-authenticated-api-calls)
|
16
|
+
|
8
17
|
## Session Persistence
|
9
18
|
Session persistence is deprecated from the `ShopifyAPI` library gem since [version 12.3.0](https://github.com/Shopify/shopify-api-ruby/blob/main/CHANGELOG.md#version-1230). The responsibility of session storage typically is fulfilled by the web framework middleware.
|
10
19
|
This API library's focus is on making requests and facilitate session creation.
|
11
20
|
|
12
21
|
⚠️ If you're not using the [ShopifyApp](https://github.com/Shopify/shopify_app) gem, you may use ShopifyAPI to perform OAuth to create sessions, but you must implement your own session storage method to persist the session information to be used in authenticated API calls.
|
13
22
|
|
23
|
+
## Supported Types of OAuth
|
24
|
+
> [!TIP]
|
25
|
+
> If you are building an embedded app, we **strongly** recommend using [Shopify managed installation](https://shopify.dev/docs/apps/auth/installation#shopify-managed-installation)
|
26
|
+
with [token exchange](#token-exchange) instead of the authorization code grant flow.
|
27
|
+
|
28
|
+
1. [Token Exchange](#token-exchange)
|
29
|
+
- OAuth flow by exchanging the current user's [session token (shopify id token)](https://shopify.dev/docs/apps/auth/session-tokens) for an
|
30
|
+
[access token](https://shopify.dev/docs/apps/auth/access-token-types/online.md).
|
31
|
+
- Recommended and is only available for embedded apps
|
32
|
+
- Doesn't require redirects, which makes authorization faster and prevents flickering when loading the app
|
33
|
+
- Access scope changes are handled by [Shopify managed installation](https://shopify.dev/docs/apps/auth/installation#shopify-managed-installation)
|
34
|
+
2. [Authorization Code Grant Flow](#authorization-code-grant-flow)
|
35
|
+
- OAuth flow that requires the app to redirect the user to Shopify for installation/authorization of the app to access the shop's data.
|
36
|
+
- Suitable for non-embedded apps
|
37
|
+
- Installations, and access scope changes are managed by the app
|
38
|
+
|
14
39
|
## Note about Rails
|
15
40
|
If using in the Rails framework, we highly recommend you use the [shopify_app](https://github.com/Shopify/shopify_app) gem to perform OAuth, you won't have to follow the instructions below to start your own OAuth flow.
|
16
41
|
- See `ShopifyApp`'s [documentation on session storage](https://github.com/Shopify/shopify_app/blob/main/docs/shopify_app/sessions.md#sessions)
|
17
42
|
|
18
43
|
If you aren't using Rails, you can look at how the `ShopifyApp` gem handles OAuth flow for further examples:
|
19
|
-
-
|
20
|
-
-
|
21
|
-
-
|
22
|
-
|
44
|
+
- Token Exchange Flow
|
45
|
+
- [Token Exchange](https://github.com/Shopify/shopify_app/blob/main/lib/shopify_app/auth/token_exchange.rb)
|
46
|
+
- Completes token exchange flow to get online and offline access tokens
|
47
|
+
- Authorization Code Grant Flow
|
48
|
+
- [Session Controller](https://github.com/Shopify/shopify_app/blob/main/app/controllers/shopify_app/sessions_controller.rb)
|
49
|
+
- Triggering and redirecting user to **begin** OAuth flow
|
50
|
+
- [Callback Controller](https://github.com/Shopify/shopify_app/blob/main/app/controllers/shopify_app/callback_controller.rb)
|
51
|
+
- Creating / storing sessions to **complete** the OAuth flow
|
23
52
|
|
24
53
|
## Performing OAuth
|
54
|
+
### Token Exchange
|
25
55
|
#### Steps
|
56
|
+
1. Enable [Shopify managed installation](https://shopify.dev/docs/apps/auth/installation#shopify-managed-installation)
|
57
|
+
by configuring your scopes [through the Shopify CLI](https://shopify.dev/docs/apps/tools/cli/configuration).
|
58
|
+
2. [Perform token exchange](#perform-token-exchange) to get an access token.
|
59
|
+
|
60
|
+
#### Perform Token Exchange
|
61
|
+
Use [`ShopifyAPI::Auth::TokenExchange`](https://github.com/Shopify/shopify-api-ruby/blob/main/lib/shopify_api/auth/token_exchange.rb) to
|
62
|
+
exchange a [session token](https://shopify.dev/docs/apps/auth/session-tokens) (Shopify Id Token) for an [access token](https://shopify.dev/docs/apps/auth/access-token-types/online.md).
|
63
|
+
|
64
|
+
#### Input
|
65
|
+
| Parameter | Type | Required? | Default Value | Notes |
|
66
|
+
| -------------- | ---------------------- | :-------: | :-----------: | ----------------------------------------------------------------------------------------------------------- |
|
67
|
+
| `shop` | `String` | Yes | - | A Shopify domain name in the form `{exampleshop}.myshopify.com`. |
|
68
|
+
| `session_token` | `String` | Yes| - | The session token (Shopify Id Token) provided by App Bridge in either the request 'Authorization' header or URL param when the app is loaded in Admin. |
|
69
|
+
| `requested_token_type` | `TokenExchange::RequestedTokenType` | Yes | - | The type of token requested. Online: `TokenExchange::RequestedTokenType::ONLINE_ACCESS_TOKEN` or offline: `TokenExchange::RequestedTokenType::OFFLINE_ACCESS_TOKEN`. |
|
70
|
+
|
71
|
+
#### Output
|
72
|
+
This method returns the new `ShopifyAPI::Auth::Session` object from the token exchange,
|
73
|
+
your app should store this `Session` object to be used later [when making authenticated API calls](#using-oauth-session-to-make-authenticated-api-calls).
|
74
|
+
|
75
|
+
#### Example
|
76
|
+
```ruby
|
77
|
+
|
78
|
+
# `shop` is the shop domain name - "this-is-my-example-shop.myshopify.com"
|
79
|
+
# `session_token` is the session token provided by App Bridge either in:
|
80
|
+
# - the request 'Authorization' header as `Bearer this-is-the-session_token`
|
81
|
+
# - or as a URL param `id_token=this-is-the-session_token`
|
82
|
+
|
83
|
+
def authenticate(shop, session_token)
|
84
|
+
session = ShopifyAPI::Auth::TokenExchange.exchange_token(
|
85
|
+
shop: shop,
|
86
|
+
session_token: session_token,
|
87
|
+
requested_token_type: ShopifyAPI::Auth::TokenExchange::RequestedTokenType::OFFLINE_ACCESS_TOKEN,
|
88
|
+
# or if you're requesting an online access token:
|
89
|
+
# requested_token_type: ShopifyAPI::Auth::TokenExchange::RequestedTokenType::ONLINE_ACCESS_TOKEN,
|
90
|
+
)
|
91
|
+
|
92
|
+
SessionRepository.store_session(session)
|
93
|
+
end
|
94
|
+
|
95
|
+
```
|
96
|
+
|
97
|
+
### Authorization Code Grant Flow
|
98
|
+
##### Steps
|
26
99
|
1. [Add a route to start OAuth](#1-add-a-route-to-start-oauth)
|
27
100
|
2. [Add an Oauth callback route](#2-add-an-oauth-callback-route)
|
28
101
|
3. [Begin OAuth](#3-begin-oauth)
|
29
102
|
4. [Handle OAuth Callback](#4-handle-oauth-callback)
|
30
|
-
5. [Using OAuth Session to make authenticated API calls](#5-using-oauth-session-to-make-authenticated-api-calls)
|
31
103
|
|
32
|
-
|
104
|
+
#### 1. Add a route to start OAuth
|
33
105
|
Add a route to your app to start the OAuth process.
|
34
106
|
|
35
107
|
```ruby
|
@@ -40,7 +112,7 @@ class ShopifyAuthController < ApplicationController
|
|
40
112
|
end
|
41
113
|
```
|
42
114
|
|
43
|
-
|
115
|
+
#### 2. Add an OAuth callback route
|
44
116
|
After the app is authenticated with Shopify, the Shopify platform will send a request back to your app using this route
|
45
117
|
(which you will provide as the `redirect_path` parameter to `begin_auth` method, in [step 3 - Begin OAuth](#3-begin-oauth)).
|
46
118
|
```ruby
|
@@ -50,7 +122,7 @@ class ShopifyCallbackController < ApplicationController
|
|
50
122
|
end
|
51
123
|
```
|
52
124
|
|
53
|
-
|
125
|
+
#### 3. Begin OAuth
|
54
126
|
Use [`ShopifyAPI::Auth::Oauth.begin_auth`](https://github.com/Shopify/shopify-api-ruby/blob/main/lib/shopify_api/auth/oauth.rb#L22) method to start OAuth process for your app.
|
55
127
|
|
56
128
|
#### Input
|
@@ -74,7 +146,7 @@ Use [`ShopifyAPI::Auth::Oauth.begin_auth`](https://github.com/Shopify/shopify-ap
|
|
74
146
|
|`auth_route`|`String`|URI that will be used for redirecting the user to the Shopify Authentication screen|
|
75
147
|
|`cookie`|`ShopifyAPI::Auth::Oauth::SessionCookie`|A session cookie to store on the user's browser. |
|
76
148
|
|
77
|
-
|
149
|
+
##### Example
|
78
150
|
Your app should take the returned values from the `begin_auth` method and:
|
79
151
|
|
80
152
|
1. Set the cookie in the user's browser. We strongly recommend that you use secure, httpOnly cookies for this to help prevent session hijacking.
|
@@ -109,19 +181,19 @@ end
|
|
109
181
|
|
110
182
|
⚠️ You can see a concrete example in the `ShopifyApp` gem's [SessionController](https://github.com/Shopify/shopify_app/blob/main/app/controllers/shopify_app/sessions_controller.rb).
|
111
183
|
|
112
|
-
|
184
|
+
#### 4. Handle OAuth Callback
|
113
185
|
When the user grants permission to the app in Shopify admin, they'll be redirected back to the app's callback route
|
114
186
|
(configured in [Step 2 - Add an OAuth callback route](#2-add-an-oauth-callback-route)).
|
115
187
|
|
116
188
|
Use [`ShopifyAPI::AuthL::Oauth.validate_auth_callback`](https://github.com/Shopify/shopify-api-ruby/blob/main/lib/shopify_api/auth/oauth.rb#L60) method to finalize the OAuth process.
|
117
189
|
|
118
|
-
|
190
|
+
##### Input
|
119
191
|
| Parameter | Type | Notes |
|
120
192
|
| ------------ | --------| ----------------------------------------------------------------------------------------------------------- |
|
121
193
|
| `cookies` | `Hash` | All browser cookies in a hash format with key and value as `String` |
|
122
194
|
| `auth_query` | `ShopifyAPI::Auth::Oauth::AuthQuery`| An `AuthQuery` containing the authorization request information used to validate the request.|
|
123
195
|
|
124
|
-
|
196
|
+
##### Output
|
125
197
|
This method returns a hash containing the new session and a cookie to be set in the browser in form of:
|
126
198
|
```ruby
|
127
199
|
{
|
@@ -134,12 +206,12 @@ This method returns a hash containing the new session and a cookie to be set in
|
|
134
206
|
|`session`|`ShopifyAPI::Auth::Session`|A session object that contains necessary information to identify the session like `shop`, `access_token`, `scope`, etc.|
|
135
207
|
|`cookie` |`ShopifyAPI::Auth::Oauth::SessionCookie`|A session cookie to store on the user's browser. |
|
136
208
|
|
137
|
-
|
209
|
+
##### Example
|
138
210
|
Your app should call `validate_auth_callback` to construct the `Session` object and cookie that will be used later for authenticated API requests.
|
139
211
|
|
140
212
|
1. Call `validate_auth_callback` to construct `Session` and `SessionCookie`.
|
141
213
|
2. Update browser cookies with the new value for the session.
|
142
|
-
3. Store the `Session` object to be used later when making authenticated API calls.
|
214
|
+
3. Store the `Session` object to be used later when [making authenticated API calls](#using-oauth-session-to-make-authenticated-api-calls).
|
143
215
|
- See [Make a GraphQL API call](https://github.com/Shopify/shopify-api-ruby/blob/main/docs/usage/graphql.md), or
|
144
216
|
[Make a REST API call](https://github.com/Shopify/shopify-api-ruby/blob/main/docs/usage/rest.md) for examples on how to use the result `Session` object.
|
145
217
|
|
@@ -182,8 +254,8 @@ end
|
|
182
254
|
|
183
255
|
⚠️ You can see a concrete example in the `ShopifyApp` gem's [CallbackController](https://github.com/Shopify/shopify_app/blob/main/app/controllers/shopify_app/callback_controller.rb).
|
184
256
|
|
185
|
-
|
186
|
-
Once your OAuth flow is complete, and you have
|
257
|
+
## Using OAuth Session to make authenticated API calls
|
258
|
+
Once your OAuth flow is complete, and you have persisted your `Session` object, you may use that `Session` object to make authenticated API calls.
|
187
259
|
|
188
260
|
Example:
|
189
261
|
```ruby
|
@@ -5,6 +5,7 @@ module ShopifyAPI
|
|
5
5
|
module AdminVersions
|
6
6
|
SUPPORTED_ADMIN_VERSIONS = T.let([
|
7
7
|
"unstable",
|
8
|
+
"2024-07",
|
8
9
|
"2024-04",
|
9
10
|
"2024-01",
|
10
11
|
"2023-10",
|
@@ -17,7 +18,7 @@ module ShopifyAPI
|
|
17
18
|
"2022-01",
|
18
19
|
], T::Array[String])
|
19
20
|
|
20
|
-
LATEST_SUPPORTED_ADMIN_VERSION = T.let("2024-
|
21
|
+
LATEST_SUPPORTED_ADMIN_VERSION = T.let("2024-07", String)
|
21
22
|
end
|
22
23
|
|
23
24
|
SUPPORTED_ADMIN_VERSIONS = ShopifyAPI::AdminVersions::SUPPORTED_ADMIN_VERSIONS
|
@@ -28,9 +28,10 @@ module ShopifyAPI
|
|
28
28
|
variables: T.nilable(T::Hash[T.any(Symbol, String), T.untyped]),
|
29
29
|
headers: T.nilable(T::Hash[T.any(Symbol, String), T.untyped]),
|
30
30
|
tries: Integer,
|
31
|
+
response_as_struct: T.nilable(T::Boolean),
|
31
32
|
).returns(HttpResponse)
|
32
33
|
end
|
33
|
-
def query(query:, variables: nil, headers: nil, tries: 1)
|
34
|
+
def query(query:, variables: nil, headers: nil, tries: 1, response_as_struct: Context.response_as_struct)
|
34
35
|
body = { query: query, variables: variables }
|
35
36
|
@http_client.request(
|
36
37
|
HttpRequest.new(
|
@@ -42,7 +43,7 @@ module ShopifyAPI
|
|
42
43
|
body_type: "application/json",
|
43
44
|
tries: tries,
|
44
45
|
),
|
45
|
-
response_as_struct:
|
46
|
+
response_as_struct: response_as_struct || false,
|
46
47
|
)
|
47
48
|
end
|
48
49
|
end
|
@@ -45,11 +45,13 @@ module ShopifyAPI
|
|
45
45
|
variables: T.nilable(T::Hash[T.any(Symbol, String), T.untyped]),
|
46
46
|
headers: T.nilable(T::Hash[T.any(Symbol, String), T.untyped]),
|
47
47
|
tries: Integer,
|
48
|
+
response_as_struct: T.nilable(T::Boolean),
|
48
49
|
).returns(HttpResponse)
|
49
50
|
end
|
50
|
-
def query(query:, variables: nil, headers: {}, tries: 1)
|
51
|
+
def query(query:, variables: nil, headers: {}, tries: 1, response_as_struct: Context.response_as_struct)
|
51
52
|
T.must(headers).merge!({ @storefront_auth_header => @storefront_access_token })
|
52
|
-
super(query: query, variables: variables, headers: headers, tries: tries
|
53
|
+
super(query: query, variables: variables, headers: headers, tries: tries,
|
54
|
+
response_as_struct: response_as_struct)
|
53
55
|
end
|
54
56
|
end
|
55
57
|
end
|
@@ -66,7 +66,7 @@ module ShopifyAPI
|
|
66
66
|
@setup_required = T.let(nil, T.nilable(T::Boolean))
|
67
67
|
@shop_owner = T.let(nil, T.nilable(String))
|
68
68
|
@source = T.let(nil, T.nilable(String))
|
69
|
-
@tax_shipping = T.let(nil, T.nilable(
|
69
|
+
@tax_shipping = T.let(nil, T.nilable(T::Boolean))
|
70
70
|
@taxes_included = T.let(nil, T.nilable(T::Boolean))
|
71
71
|
@timezone = T.let(nil, T.nilable(String))
|
72
72
|
@transactional_sms_disabled = T.let(nil, T.nilable(T::Boolean))
|
@@ -179,7 +179,7 @@ module ShopifyAPI
|
|
179
179
|
attr_reader :shop_owner
|
180
180
|
sig { returns(T.nilable(String)) }
|
181
181
|
attr_reader :source
|
182
|
-
sig { returns(T.nilable(
|
182
|
+
sig { returns(T.nilable(T::Boolean)) }
|
183
183
|
attr_reader :tax_shipping
|
184
184
|
sig { returns(T.nilable(T::Boolean)) }
|
185
185
|
attr_reader :taxes_included
|
@@ -66,7 +66,7 @@ module ShopifyAPI
|
|
66
66
|
@setup_required = T.let(nil, T.nilable(T::Boolean))
|
67
67
|
@shop_owner = T.let(nil, T.nilable(String))
|
68
68
|
@source = T.let(nil, T.nilable(String))
|
69
|
-
@tax_shipping = T.let(nil, T.nilable(
|
69
|
+
@tax_shipping = T.let(nil, T.nilable(T::Boolean))
|
70
70
|
@taxes_included = T.let(nil, T.nilable(T::Boolean))
|
71
71
|
@timezone = T.let(nil, T.nilable(String))
|
72
72
|
@transactional_sms_disabled = T.let(nil, T.nilable(T::Boolean))
|
@@ -179,7 +179,7 @@ module ShopifyAPI
|
|
179
179
|
attr_reader :shop_owner
|
180
180
|
sig { returns(T.nilable(String)) }
|
181
181
|
attr_reader :source
|
182
|
-
sig { returns(T.nilable(
|
182
|
+
sig { returns(T.nilable(T::Boolean)) }
|
183
183
|
attr_reader :tax_shipping
|
184
184
|
sig { returns(T.nilable(T::Boolean)) }
|
185
185
|
attr_reader :taxes_included
|
@@ -66,7 +66,7 @@ module ShopifyAPI
|
|
66
66
|
@setup_required = T.let(nil, T.nilable(T::Boolean))
|
67
67
|
@shop_owner = T.let(nil, T.nilable(String))
|
68
68
|
@source = T.let(nil, T.nilable(String))
|
69
|
-
@tax_shipping = T.let(nil, T.nilable(
|
69
|
+
@tax_shipping = T.let(nil, T.nilable(T::Boolean))
|
70
70
|
@taxes_included = T.let(nil, T.nilable(T::Boolean))
|
71
71
|
@timezone = T.let(nil, T.nilable(String))
|
72
72
|
@transactional_sms_disabled = T.let(nil, T.nilable(T::Boolean))
|
@@ -179,7 +179,7 @@ module ShopifyAPI
|
|
179
179
|
attr_reader :shop_owner
|
180
180
|
sig { returns(T.nilable(String)) }
|
181
181
|
attr_reader :source
|
182
|
-
sig { returns(T.nilable(
|
182
|
+
sig { returns(T.nilable(T::Boolean)) }
|
183
183
|
attr_reader :tax_shipping
|
184
184
|
sig { returns(T.nilable(T::Boolean)) }
|
185
185
|
attr_reader :taxes_included
|
@@ -66,7 +66,7 @@ module ShopifyAPI
|
|
66
66
|
@setup_required = T.let(nil, T.nilable(T::Boolean))
|
67
67
|
@shop_owner = T.let(nil, T.nilable(String))
|
68
68
|
@source = T.let(nil, T.nilable(String))
|
69
|
-
@tax_shipping = T.let(nil, T.nilable(
|
69
|
+
@tax_shipping = T.let(nil, T.nilable(T::Boolean))
|
70
70
|
@taxes_included = T.let(nil, T.nilable(T::Boolean))
|
71
71
|
@timezone = T.let(nil, T.nilable(String))
|
72
72
|
@transactional_sms_disabled = T.let(nil, T.nilable(T::Boolean))
|
@@ -179,7 +179,7 @@ module ShopifyAPI
|
|
179
179
|
attr_reader :shop_owner
|
180
180
|
sig { returns(T.nilable(String)) }
|
181
181
|
attr_reader :source
|
182
|
-
sig { returns(T.nilable(
|
182
|
+
sig { returns(T.nilable(T::Boolean)) }
|
183
183
|
attr_reader :tax_shipping
|
184
184
|
sig { returns(T.nilable(T::Boolean)) }
|
185
185
|
attr_reader :taxes_included
|
@@ -66,7 +66,7 @@ module ShopifyAPI
|
|
66
66
|
@setup_required = T.let(nil, T.nilable(T::Boolean))
|
67
67
|
@shop_owner = T.let(nil, T.nilable(String))
|
68
68
|
@source = T.let(nil, T.nilable(String))
|
69
|
-
@tax_shipping = T.let(nil, T.nilable(
|
69
|
+
@tax_shipping = T.let(nil, T.nilable(T::Boolean))
|
70
70
|
@taxes_included = T.let(nil, T.nilable(T::Boolean))
|
71
71
|
@timezone = T.let(nil, T.nilable(String))
|
72
72
|
@transactional_sms_disabled = T.let(nil, T.nilable(T::Boolean))
|
@@ -179,7 +179,7 @@ module ShopifyAPI
|
|
179
179
|
attr_reader :shop_owner
|
180
180
|
sig { returns(T.nilable(String)) }
|
181
181
|
attr_reader :source
|
182
|
-
sig { returns(T.nilable(
|
182
|
+
sig { returns(T.nilable(T::Boolean)) }
|
183
183
|
attr_reader :tax_shipping
|
184
184
|
sig { returns(T.nilable(T::Boolean)) }
|
185
185
|
attr_reader :taxes_included
|
@@ -66,7 +66,7 @@ module ShopifyAPI
|
|
66
66
|
@setup_required = T.let(nil, T.nilable(T::Boolean))
|
67
67
|
@shop_owner = T.let(nil, T.nilable(String))
|
68
68
|
@source = T.let(nil, T.nilable(String))
|
69
|
-
@tax_shipping = T.let(nil, T.nilable(
|
69
|
+
@tax_shipping = T.let(nil, T.nilable(T::Boolean))
|
70
70
|
@taxes_included = T.let(nil, T.nilable(T::Boolean))
|
71
71
|
@timezone = T.let(nil, T.nilable(String))
|
72
72
|
@transactional_sms_disabled = T.let(nil, T.nilable(T::Boolean))
|
@@ -179,7 +179,7 @@ module ShopifyAPI
|
|
179
179
|
attr_reader :shop_owner
|
180
180
|
sig { returns(T.nilable(String)) }
|
181
181
|
attr_reader :source
|
182
|
-
sig { returns(T.nilable(
|
182
|
+
sig { returns(T.nilable(T::Boolean)) }
|
183
183
|
attr_reader :tax_shipping
|
184
184
|
sig { returns(T.nilable(T::Boolean)) }
|
185
185
|
attr_reader :taxes_included
|
@@ -66,7 +66,7 @@ module ShopifyAPI
|
|
66
66
|
@setup_required = T.let(nil, T.nilable(T::Boolean))
|
67
67
|
@shop_owner = T.let(nil, T.nilable(String))
|
68
68
|
@source = T.let(nil, T.nilable(String))
|
69
|
-
@tax_shipping = T.let(nil, T.nilable(
|
69
|
+
@tax_shipping = T.let(nil, T.nilable(T::Boolean))
|
70
70
|
@taxes_included = T.let(nil, T.nilable(T::Boolean))
|
71
71
|
@timezone = T.let(nil, T.nilable(String))
|
72
72
|
@transactional_sms_disabled = T.let(nil, T.nilable(T::Boolean))
|
@@ -179,7 +179,7 @@ module ShopifyAPI
|
|
179
179
|
attr_reader :shop_owner
|
180
180
|
sig { returns(T.nilable(String)) }
|
181
181
|
attr_reader :source
|
182
|
-
sig { returns(T.nilable(
|
182
|
+
sig { returns(T.nilable(T::Boolean)) }
|
183
183
|
attr_reader :tax_shipping
|
184
184
|
sig { returns(T.nilable(T::Boolean)) }
|
185
185
|
attr_reader :taxes_included
|
@@ -66,7 +66,7 @@ module ShopifyAPI
|
|
66
66
|
@setup_required = T.let(nil, T.nilable(T::Boolean))
|
67
67
|
@shop_owner = T.let(nil, T.nilable(String))
|
68
68
|
@source = T.let(nil, T.nilable(String))
|
69
|
-
@tax_shipping = T.let(nil, T.nilable(
|
69
|
+
@tax_shipping = T.let(nil, T.nilable(T::Boolean))
|
70
70
|
@taxes_included = T.let(nil, T.nilable(T::Boolean))
|
71
71
|
@timezone = T.let(nil, T.nilable(String))
|
72
72
|
@transactional_sms_disabled = T.let(nil, T.nilable(T::Boolean))
|
@@ -179,7 +179,7 @@ module ShopifyAPI
|
|
179
179
|
attr_reader :shop_owner
|
180
180
|
sig { returns(T.nilable(String)) }
|
181
181
|
attr_reader :source
|
182
|
-
sig { returns(T.nilable(
|
182
|
+
sig { returns(T.nilable(T::Boolean)) }
|
183
183
|
attr_reader :tax_shipping
|
184
184
|
sig { returns(T.nilable(T::Boolean)) }
|
185
185
|
attr_reader :taxes_included
|
@@ -66,7 +66,7 @@ module ShopifyAPI
|
|
66
66
|
@setup_required = T.let(nil, T.nilable(T::Boolean))
|
67
67
|
@shop_owner = T.let(nil, T.nilable(String))
|
68
68
|
@source = T.let(nil, T.nilable(String))
|
69
|
-
@tax_shipping = T.let(nil, T.nilable(
|
69
|
+
@tax_shipping = T.let(nil, T.nilable(T::Boolean))
|
70
70
|
@taxes_included = T.let(nil, T.nilable(T::Boolean))
|
71
71
|
@timezone = T.let(nil, T.nilable(String))
|
72
72
|
@transactional_sms_disabled = T.let(nil, T.nilable(T::Boolean))
|
@@ -179,7 +179,7 @@ module ShopifyAPI
|
|
179
179
|
attr_reader :shop_owner
|
180
180
|
sig { returns(T.nilable(String)) }
|
181
181
|
attr_reader :source
|
182
|
-
sig { returns(T.nilable(
|
182
|
+
sig { returns(T.nilable(T::Boolean)) }
|
183
183
|
attr_reader :tax_shipping
|
184
184
|
sig { returns(T.nilable(T::Boolean)) }
|
185
185
|
attr_reader :taxes_included
|