FROM CACHE - jp_header
このコミュニティはピアツーピアサポートに移行しました。Shopify サポートは今後、このコミュニティへのサービスを提供いたしません。これからもぜひ、他のマーチャントやパートナーとつながり、サポートし合い、経験を共有してください。 当社の行動規範に違反する行動や削除を希望するコンテンツがありましたら、引き続きご報告ください

キャンペーンのレポートの昨日分をGASで書き出したい

キャンペーンのレポートの昨日分をGASで書き出したい

fu10ta
Shopify Partner
2 0 0

お世話になります。

当方、非エンジニア、業務自動化挑戦中の者です。

みなさまのお力添えをいただきたく投稿させていただきました。

 

このページの情報を書き出したいというテーマになります。

report.jpg 

 

Retrieves a list of reportsRetrieves a list of all marketing eventsが参考になるのではと思い、こちらを試しましたが期待通りの取得ができませんでした。

確認のためRetrieve a list of ordersを試しましたが、こちらは期待通りの値が取得できました。

gas.jpg

 

var myAPI = myAPI_();
var API_KEY = myAPI.apiKey;
var API_PASSWORD = myAPI.apiPass;
var SHOP_ID = myAPI.shopID;
var API_VERSION = myAPI.apiVer;

var encoded = Utilities.base64Encode(API_KEY + ':' + API_PASSWORD);
var headers = {
  "Content-Type": "application/json",
  "Authorization": "Basic " + encoded,
};
var options = {
  'contentType': 'application/json',
  'method': 'GET',
  'headers': headers,
  'muteHttpExceptions': true,
  'followRedirects': false,
};

function reqMartketingEvents() {
  var shopifyURL = `https://${SHOP_ID}.myshopify.com/admin/api/${API_VERSION}/marketing_events.json`;
  var response = UrlFetchApp.fetch(shopifyURL, options);
  Logger.log('reqMartketingEvents: '+response.getContentText());
  return JSON.parse(response.getContentText());
}

function reqReports() {
  var shopifyURL = `https://${SHOP_ID}.myshopify.com/admin/api/${API_VERSION}/reports.json`;
  var response = UrlFetchApp.fetch(shopifyURL, options);
  Logger.log('reqReports: '+response.getContentText());
  return JSON.parse(response.getContentText());
}

function reqOrderClosed() {
  var shopifyURL = `https://${SHOP_ID}.myshopify.com/admin/api/${API_VERSION}/orders.json?status=closed&limit=1`;
  var response = UrlFetchApp.fetch(shopifyURL, options);
  Logger.log('reqOrderClosed: '+response.getContentText());
  return JSON.parse(response.getContentText());
}

function check() {
  var res1 = reqMartketingEvents()
  var res2 = reqReports()
  var res3 = reqOrderClosed()
}

 

 

お伺いしたい点は、2点ございます。

①アプローチが誤っているのでしょうか?

②marketing_eventsやreportsからの戻りが空になっているのはどのような原因が考えられますでしょうか?

 

どうぞよろしくお願いいたします。

1件の返信1

Qcoltd
Shopify Partner
1407 545 520

@fu10ta 様

 

私の英文読解が誤っているかもしれませんが、

Reportについては、

https://shopify.dev/docs/api/admin-rest/2023-10/resources/report#top

You can use the Report resource to publish reports to the Reports page in the Shopify admin. For example, a shirt fulfillment app could publish a report that compares the sales of shirts by marketing campaign. The reports are based on queries written in ShopifyQL.

Reports are scoped to the app that created them. When an app creates a report, other apps can't view, modify, or delete that report. Also, apps can't access reports that were created from the Shopify admin.

上記の、第二パラグラフを見ると、

「アプリが作成したレポートのみがスコープされる」ようです。

また、「アプリはShopify管理画面で生成されたリポートにアクセスできない」ともあり、

カスタムアプリではReportにアクセスできないのではないかと思います。

 

marketing_eventsについても、

https://shopify.dev/docs/api/admin-rest/2023-10/resources/marketingevent#get-marketing-events

Marketing events represent actions taken by your app, on behalf of the merchant, to market products, collections, discounts, pages, blog posts, and other features. These actions target multiple potential customers, rather than specific individuals. For example, you should model your marketing event at the email campaign level, rather than on a per-email basis.

Marketing eventsは、あなたのアプリによってなされたアクションを表す、と冒頭にあり、

こちらもあなたのアプリによって発生したマーケティングイベントしか取得できないのではないかと思いました。

 

なお、

私もサンプルコードをPostmanから実行してみましたが、

どちらのAPIも、質問者様と同様に、レスポンスの中身は空でした。

 

ご参考まで。

(キュー田辺)

株式会社Q (キュー)
グラフィックデザイン、アパレル事業、Web制作など色々やっている渋谷区代々木の会社です。ShopifyでのECサイトの運営・開発も行なっています。
私たちについて: https://web.q-co.jp/ テックブログ: https://techlab.q-co.jp/