Skip to content

Commit

Permalink
Add REST resource rate limit docs
Browse files Browse the repository at this point in the history
  • Loading branch information
lizkenyon committed Dec 19, 2023
1 parent 5c112aa commit 4929a91
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 3 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ Note: For changes to the API, see https://shopify.dev/changelog?filter=api

## Unreleased
[#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.
[#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.

## 13.3.1

Expand Down
21 changes: 18 additions & 3 deletions docs/usage/rest.md
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ Create an instance of [`ShopifyAPI::Clients::Rest::Admin`](https://github.com/Sh

Examples:
```ruby
# Create a default client with `ShopifyAPI::Context.api_version`
# Create a default client with `ShopifyAPI::Context.api_version`
# and the active session from `ShopifyAPI::Context.active_session`
client = ShopifyAPI::Clients::Rest::Admin.new

Expand All @@ -147,7 +147,7 @@ The `ShopifyAPI::Clients::Rest::Admin` client offers the 4 core request methods:

#### Input Parameters

Each method can take the parameters outlined in the table below.
Each method can take the parameters outlined in the table below.

| Parameter | Type | Required in Methods | Default Value | Notes |
| -------------- | -------------------------------------------------------- | :-----------------: | :-----------: | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
Expand All @@ -161,7 +161,7 @@ Each method can take the parameters outlined in the table below.

#### Output
##### Success
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:
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:
| Methods | Type | Notes |
|---------|------|-------|
| `code` |`Integer`| HTTP Response code, e.g. `200`|
Expand Down Expand Up @@ -247,6 +247,21 @@ _For more information on the `products` endpoint, [check out our API reference g

_For more information on the `products` endpoint, [check out our API reference guide](https://shopify.dev/docs/api/admin-rest/latest/resources/product)._

#### Accessing Rate Limit information

The REST resources have `api_call_limit` and `retry_after` can be found on the Resource class. These values correspond to the `X-Shopify-Shop-Api-Call-Limit` and `Retry-After` [headers](https://shopify.dev/docs/api/usage/rate-limits#rest-admin-api-rate-limits) respectively.

```ruby
product = ShopifyAPI::Product.find(session: session, id: 12345)

# X-Shopify-Shop-Api-Call-Limit: 32/40
request_count = ShopifyAPI::Product.api_call_limit[:request_count] # 32
bucket_size = ShopifyAPI::Product.api_call_limit[:bucket_size] # 40

retry_after = ShopifyAPI::Product.retry_request_after

```

### Pagination

This library also supports cursor-based pagination for REST Admin API requests. [Learn more about REST request pagination](https://shopify.dev/docs/api/usage/pagination-rest).
Expand Down

0 comments on commit 4929a91

Please sign in to comment.