ゴール
admin apiから注文履歴を取得すること
概要
デフォルト(liquid)の注文履歴では、絞り込み機能(メタフィールドや更新日)が実装できそうになかったので、
カスタムアプリで注文履歴を取得し、絞り込みをすることにしました。
リクエストの流れとしてはテーマ→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にチェックを入れる。
query GetOrder {
orders(first: 10, query: "customer_id:'hogehoge'") {
nodes {
id
}
}
}
エラー
//error
GraphqlQueryError: Access denied for orders field.
一点気になる点としては、graphqlのリクエストにappInstallation.accessScopesを含めて(コード1)スコープを確認した際に、read_orders,write_ordersが含まれていない(コード2)ことです。ただ、管理画面で確認した際にはscopeは反映されていそうなので、原因がわからず。。手順が間違っているのでしょうか?
こちら詳しい方いましたら、ご教授いただけらと思います。
コード1
query GetOrder {
orders(first: 1) {
nodes {
id
}
}
appInstallation {
accessScopes {
handle
description
}
}
}
コード2
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 │ }