# Graphql でadmin apiにリクエスト(注文履歴を取得)したら、scopeを設定しているのにアクセスが拒否される

**URL:** <https://community.shopify.com/t/graphql-admin-api-scope/245588>\
**Category:** 技術的なQ＆A\
**Tags:** javascript\
**Created:** [August 30, 2023, 7:30am UTC](https://community.shopify.com/t/graphql-admin-api-scope/245588 "2023-08-30T07:30:13Z")\
**Posts on this page:** 1\
**Page:** 1

## AI-generated summary

目的: Admin API から注文履歴を取得し、メタフィールドや更新日で絞り込み可能な独自の注文履歴機能を実装したい。

実装概要: テーマ → プロキシ → カスタムアプリの経路で GraphQL を実行。

問題: GraphQL で orders を取得するクエリが「Access denied for orders field.」で失敗。一方、Shopify GraphQL App（ブラウザ）では同クエリは成功しており、クエリ自体は正しい可能性が高い。

想定原因: スコープ不足（read_orders / write_orders）。
- 対応済み手順: toml に read_orders, write_orders を追加し yarn deploy 実行。Partner ダッシュボードと管理画面の Admin API スコープでも両権限を確認。
- 追加検証: appInstallation.accessScopes を GraphQL で取得すると、products/customers 関連のみが返り、read_orders / write_orders が含まれない。

現状: 管理画面表示と実際のアクセッスコープが不整合で、orders へのアクセスが拒否される状態。正しいスコープ適用（反映/再認可など）の手順に不明点があり、解決策は未確定。利用者が助言を求めている。

<div class="post-metadata">

**Author:** ![nomin](https://avatars.discourse-cdn.com/v4/letter/n/58f4c7/32.png) [@nomin](https://community.shopify.com/u/nomin)\
**Post date:** [August 30, 2023, 7:30am UTC](https://community.shopify.com/t/graphql-admin-api-scope/245588/1 "2023-08-30T07:30:13Z")

</div>

ゴール  
admin apiから注文履歴を取得すること

概要  
[デフォルト(liquid)の注文履歴](https://shopify.dev/docs/themes/architecture/templates/customers-account)では、絞り込み機能(メタフィールドや更新日)が実装できそうになかったので、  
カスタムアプリで注文履歴を取得し、絞り込みをすることにしました。  
リクエストの流れとしてはテーマ→proxy→カスタムアプリになります。

問題点  
今回の質問の本題ですが、下記のクエリでadmin apiにリクエストしたのですが、下記のエラーが返ってきてしまいます。ちなみにshopify graphql appでブラウザからリクエストした際には取得できていますので、graphqlのコードは間違っていないと思います。  
アクセス拒否されていますのでscopeが問題だと思っています。  
私が試したscopeの設定の手順は下記です。  
1.tomlファイルにread\_orders,write\_ordersを追記してyarn deployで設定を反映

2.shopify partner\>APIアクセス\>スコープを確認し、read\_orders,write\_ordersは追加されているのを確認  
3.オンラインストアの管理画面の「設定\>アプリと販売チャンネル\>アプリ開発\>該当のアプリを選択\>設定\>admin api」のスコープもread\_orders,write\_ordersにチェックを入れる。

```javascript
query GetOrder {
  orders(first: 10, query: "customer_id:'hogehoge'") {
    nodes {
      id
  }
}
}

```

エラー

```javascript
//error
GraphqlQueryError: Access denied for orders field.

```

一点気になる点としては、graphqlのリクエストにappInstallation.accessScopesを含めて(コード１)スコープを確認した際に、read\_orders,write\_ordersが含まれていない(コード２)ことです。ただ、管理画面で確認した際にはscopeは反映されていそうなので、原因がわからず。。手順が間違っているのでしょうか？

こちら詳しい方いましたら、ご教授いただけらと思います。

コード１

```javascript
query GetOrder {
        orders(first: 1) {
          nodes {
            id
          }
        }
        appInstallation {
          accessScopes {
            handle
            description
          }
        }
      }

```

コード２

```css
15:22:21 │ remix │ res [
15:22:21 │ remix │ {
15:22:21 │ remix │ handle: 'write_products',
15:22:21 │ remix │ description: 'Modify products, variants, and collections'
15:22:21 │ remix │ },
15:22:21 │ remix │ {
15:22:21 │ remix │ handle: 'read_customers',
15:22:21 │ remix │ description: 'Read customer details and customer groups'
15:22:21 │ remix │ },
15:22:21 │ remix │ {
15:22:21 │ remix │ handle: 'write_customers',
15:22:21 │ remix │ description: 'Modify customer details and customer groups'
15:22:21 │ remix │ },
15:22:21 │ remix │ {
15:22:21 │ remix │ handle: 'read_products',
15:22:21 │ remix │ description: 'Read products, variants, and collections'
15:22:21 │ remix │ }

```
