将 Shopify 数据加载到 BigQuery 中

您可以使用适用于 Shopify 的 BigQuery Data Transfer Service 连接器将数据从 Shopify 加载到 BigQuery。借助 BigQuery Data Transfer Service,您可以安排周期性转移作业,以将 Shopify 中的最新数据添加到 BigQuery。

Shopify 连接器支持从以下资源中转移基于 GraphQL 的资源(例如 Collections 和 Orders)的数据:

  • 订阅式账号
  • 合作伙伴账号

限制

Shopify 数据传输作业受到以下限制:

  • 如需在数据传输作业中包含 GiftCards 对象,与此数据传输作业关联的账号必须具有 ShopifyPlus 订阅。
  • 如需在数据传输中包含以下应用订阅数据对象,Shopify 商店中安装的应用必须是销售渠道应用。
    • AppSubscriptionLineItems
    • AppSubscriptions
    • ProductResourceFeedbacks
  • 如需包含以下需要折扣函数的 Shopify 数据对象,您必须使用 Shopify CLI 创建 Shopify 应用。
    • DiscountsCodeApp
    • DiscountsCodeBasic

准备工作

以下部分介绍了在创建 Shopify 数据传输作业之前需要满足的前提条件。

Shopify 前提条件

  • 您必须拥有 Shopify 账号和 Shopify 商店。
  • 您必须为 Shopify 商店提供自定义 Shopify 应用。如需了解详情,请参阅自定义应用。
  • 您必须有权访问要转移到 BigQuery 的 Shopify 数据对象所需的范围。如需查看每个对象所需的范围列表,请参阅支持的对象和所需范围。

BigQuery 前提条件

所需 BigQuery 角色

如需获得创建 BigQuery Data Transfer Service 数据转移作业所需的权限,请让您的管理员为您授予项目的 BigQuery Admin (roles/bigquery.admin) IAM 角色。 如需详细了解如何授予角色,请参阅管理对项目、文件夹和组织的访问权限。

此预定义角色可提供创建 BigQuery Data Transfer Service 数据转移作业所需的权限。如需查看所需的确切权限,请展开所需权限部分:

所需权限

创建 BigQuery Data Transfer Service 数据转移作业需要以下权限:

  • BigQuery Data Transfer Service 权限:
    • bigquery.transfers.update
    • bigquery.transfers.get
  • BigQuery 权限:
    • bigquery.datasets.get
    • bigquery.datasets.getIamPolicy
    • bigquery.datasets.update
    • bigquery.datasets.setIamPolicy
    • bigquery.jobs.create

您也可以使用自定义角色或其他预定义角色来获取这些权限。

如需了解详情,请参阅授予 bigquery.admin 访问权限。

如果您想要为 Pub/Sub 设置转移作业运行通知,请确保拥有 pubsub.topics.setIamPolicy Identity and Access Management (IAM) 权限。如果您只是要设置邮件通知,则无需 Pub/Sub 权限。如需了解详情,请参阅 BigQuery Data Transfer Service 运行通知。

设置 Shopify 数据传输作业

通过使用以下选项之一设置转移作业配置,将 Shopify 数据添加到 BigQuery 中:

控制台

  1. 前往 Cloud de Confiance 控制台中的“数据转移”页面。

    转到“数据传输”

  2. 点击 创建转移作业。

  3. 在来源类型部分的来源中,选择 Shopify。

  4. 在数据源详细信息部分,执行以下操作:

    • 在 Shop name(商店名称)部分,输入您的 Shopify 商店名称。 例如,如果您的商家账号 ID 为 storename.myshopify.com,则您的商店名称为 storename。
    • 在客户端 ID 和客户端密钥部分,输入 Shopify 应用的客户端 ID 和密钥。如需了解详情,请参阅客户端密钥简介。
    • 对于要转移的 Shopify 对象,请点击浏览:
      • 选择要转移到 BigQuery 目标数据集的任何对象。此外,您还可以在此字段中手动输入要包含在数据转移作业中的任何对象。
  5. 在目标设置部分的数据集中,选择您创建用来存储数据的数据集。

  6. 在转移配置名称部分的显示名称中,输入数据转移作业的名称。

  7. 在时间表选项部分中,执行以下操作:

    • 在重复频率列表中,选择一个选项来指定此数据转移作业的运行频率。如需指定自定义重复频率,请选择自定义。如果您选择按需,则当您手动触发转移作业时,此转移作业会运行。
    • 如果适用,请选择立即开始或从设置的时间开始,并提供开始日期和运行时间。
  8. 可选:在通知选项部分中,执行以下操作:

    • 如需启用电子邮件通知,请点击电子邮件通知切换开关。启用此选项后,转移作业管理员会在转移作业运行失败时收到电子邮件通知。
    • 如需为此转移作业启用 Pub/Sub 转移作业运行通知,请点击 Pub/Sub 通知切换开关。您可以选择主题名称,也可以点击创建主题来创建一个主题。
  9. 点击保存。

bq

输入 bq mk 命令并提供转移作业创建标志 --transfer_config:

bq mk
    --transfer_config
    --project_id=PROJECT_ID
    --data_source=DATA_SOURCE
    --display_name=NAME
    --target_dataset=DATASET
    --params='PARAMETERS'

其中:

  • PROJECT_ID(可选):您的 Cloud de Confiance by S3NS 项目 ID。如果未提供 --project_id 来指定具体项目,则系统会使用默认项目。
  • DATA_SOURCE:数据源,shopify。
  • NAME:数据转移作业配置的显示名称。转移作业名称可以是任何可让您在需要修改转移作业时识别该转移作业的名称。
  • DATASET:转移作业配置的目标数据集。
  • PARAMETERS:所创建转移作业配置的参数(采用 JSON 格式)。例如 --params='{"param":"param_value"}'。以下是 Shopify 数据传输的参数:

    • assets:要转移到 BigQuery 的 Shopify 对象的路径。
    • connector.shopName:Shopify 商店的名称。例如,如果您的商家账号 ID 为 storename.myshopify.com,则您的商店名称为 storename。
    • connector.authentication.accessToken:Shopify Admin API 访问令牌。

以下命令会在默认项目中创建增量 Shopify 数据转移作业。

bq mk
    --transfer_config
    --target_dataset=mydataset
    --data_source=shopify
    --display_name='My Transfer'
    --params='{"assets": ["Orders"]
        "connector.shopName": "storename",
        "connector.authentication.accessToken":"sk_test_123456789"}'
保存转移作业配置后,Shopify 连接器会根据您的安排选项自动触发转移作业运行。在每次转移作业运行时,Shopify 连接器都会将 Shopify 中的所有可用数据转移到 BigQuery。

如需在常规安排之外手动运行数据转移,您可以启动回填运行。

支持的对象和所需范围

下表列出了可转移到 BigQuery 的 Shopify 数据对象以及每个对象所需的范围。

数据对象 必需的范围
AppFeedbacks 无需指定范围
AppSubscriptionLineItems 无需指定范围
AppSubscriptions 无需指定范围
目录 read_products 或 read_product_listings
read_publications
合集 read_products
read_publications
公司 read_customers 或 read_companies
CompanyContactRoleAssignments read_customers 或 read_companies
CompanyContacts read_customers 或 read_companies
CompanyLocations read_customers 或 read_companies
客户 read_customers
write_customers
read_customer_merge
read_locations 或 read_inventory
read_markets
read_orders
DeliveryProfiles read_products
read_shipping
DiscountsAutomaticApp read_discounts
DiscountsAutomaticBasic read_discounts
DiscountsAutomaticBxgy read_discounts
DiscountsCodeApp read_discounts
DiscountsCodeBasic read_discounts
DiscountsCodeBxgy read_discounts
DraftOrders read_customers
read_draft_orders
read_orders
read_payment_terms
文件 read_files
FulfillmentEvents read_orders
FulfillmentOrders read_locations
read_orders
read_assigned_fulfillment_orders、read_merchant_managed_fulfillment_orders或read_third_party_fulfillment_orders
Fulfillment read_fulfillments 或 read_products
read_locations
read_orders
FulfillmentServices read_locations 或 read_inventory
read_fulfillments、read_products、read_custom_fulfillment_services 或 assigned_fulfillment_orders
FulfillmentTrackingInfo read_fulfillments 或 read_products
read_locations
read_orders
GiftCards read_gift_cards
read_orders
read_customers
InventoryItems read_inventory
read_products
位置 read_locations
read_fulfillments
Metafields_Article read_content
Metafields_Blog read_content
Metafields_Collection read_products
read_publications
Metafields_Customer read_customers
write_customers
read_customer_merge
read_locations 或 read_inventory
read_markets
read_orders
Metafields_Draft_Order read_customers
read_draft_orders
read_orders
read_payment_terms
Metafields_Order read_customers
read_inventory
read_locations
read_orders
read_payment_terms
Metafields_Page read_content
Metafields_Product read_products
read_product_listings
read_publications
Metafields_Selling_Plan read_products
Metafields_Shop 无需指定范围
Metafields_Variant read_products
read_shipping
OrderLineItems read_orders
read_products
OrderRiskAssessments read_orders
订单 read_customers
read_inventory
read_locations
read_orders
read_payment_terms
read_draft_orders
read_products 或 read_fulfillments
OrderTransactions read_orders
read_products
PriceLists read_products
ProductMediaImages read_products
ProductOptions read_products
ProductOptionValues read_products
ProductResourceFeedbacks read_resource_feedbacks
read_products
产品 read_products
read_product_listings
read_publications
ProductVariants read_products
read_shipping
发布内容 read_products
read_publications
退款 read_products
read_orders
read_returns
返回结果 read_orders
read_returns
ScriptTags read_script_tags
细分 read_customers
SellingPlanGroups read_products
StorefrontAccessTokens 无需指定范围
UrlRedirects read_online_store_navigation

数据类型映射

下表将 Shopify 数据类型映射到相应的 BigQuery 数据类型:

Shopify 数据类型 BigQuery 数据类型
String STRING
Int INT64
Decimal NUMERIC
Double FLOAT64
Long BIGNUMERIC
Bool BOOL
Datetime TIMESTAMP

价格

将 Shopify 数据转移到 BigQuery 的功能处于预览版阶段时,您无需付费即可使用此功能。

排查转移作业设置问题

如果您在设置数据转移作业时遇到问题,请参阅 Shopify 转移作业问题。

后续步骤

  • 如需大致了解 BigQuery Data Transfer Service,请参阅什么是 BigQuery Data Transfer Service。
  • 如需了解如何使用转移作业,包括获取有关转移作业配置的信息、列出转移作业配置以及查看转移作业的运行历史记录,请参阅管理转移作业。