Shopify 是出海电商独立站首选建站工具,Shopify 不仅提供了强大的电商支持,也为开发者提供了丰富的 API 功能,我们可以直接通过 API 操作店铺产品上架、订单管理、退货退款、物流信息等。
本文通过手把手教搭建搭建一套 Shopify 极简订单产品管理系统来带领大家认识 Shopify API
一. Shopify API 获取权限
操作 Shopify API 前,我们要先拿到自己店铺的 API 调用 Key 及给它授权。
在店铺后台找到「应用开发」并创建应用,在你创建的应用里找到 API 凭证获取 API key
https://{username}:{password}@{shop}.myshopify.com/admin/api/2022-04/{resource}.json
使用 Basic authentication 方式鉴权需要通过 base64 转换一下。即把「API 密钥 : API 访问令牌」以:
冒号连接,用 base64 转换后生产最终的鉴权密钥。
然后在「配置」里,设置 API 访问权限,这样你的 API 已经准备好了,接下来我们可以开始搭建工具了。
二. 通过 shopify API 搭建后台管理系统
Shopify 第三方后台管理系统的前端开发需要会 JS、CSS、HTML,但我们也可以使用类似卡拉云这种快速搭建后台管理工具的开发平台来直接开发。使用卡拉云无需会任何前端技能,只需拖拽即可快速生成前端 UI 组件。
接下来我来讲解,如何使用卡拉云调用 Shopify API 搭建简单的 Shopify 订单管理系统
(1)接入 Shopify API 数据源
在卡拉云里接入 API 非常简单,只需要把对应的 end point
填进去即可。
(2)调用 Shopify API 数据
在卡拉云里调用 Shopify API 非常容易,与 Postman 的操作基本一致。这里演示的是产品管理,如果想拉取订单,Shopify 调 orders.json
即可,搭建过程一样。
(3)通过拖拽搭建 Shopify 前端工具界面
在卡拉云中组件与后端数据连接只需要一行代码即可。上图为将 Shopify API 拉取的数据映射到表格组件中,卡拉云的表格组件可以直接显示图片。
三. Shopify api 接口文档说明
(1)Prouduct 属性
GET /admin/api/2022-04/products.json
返回值说明:
{
'id': 5932984696983, //商品ID
'title': '新款韩国东大门韩版休闲女孩印花短袖', //商品标题
'body_html': '本公司为出口贸易公司,大部分均出口韩国,产品都是严格按照出口标准生产', //商品描述
'vendor': 'JustBeautiful', //店名
'product_type': 'Snowboard', //商品类型
'status': "active",//上架状态
"created_at": "2022-05-04T18:28:48+09:00",
"handle": "新款韩国东大门韩版休闲女孩印花短袖",
"updated_at": "2022-05-04T18:46:06+09:00",
"published_at": "2022-05-04T18:28:49+09:00", //发布时间
'template_suffix': '', //模板
'published_scope': 'web', //发布方式 web在线商店 global在线商店和销售点
'tags': '', //标签
'admin_graphql_api_id': 'gid://shopify/Product/6818477047940', //api管理ID
'variants':
[{
'id': 37227313561751,
'title': 'Default Title',
'price': '13.90', //价格
'sku': '',//商店里的产品变种需要一个唯一标识符,这样才能完成服务
'position': 1, //仓位
'inventory_policy': 'deny', //当产品缺货时,是否允许客户下订单。有效值:deny 当前位置如果产品缺货,客户不得下订单,continue 当前位置如果产品缺货,客户可以下订单
'compare_at_price': '9.90', //原价 调价调整或出售前项目的原始价格
'fulfillment_service': 'manual', //与产品变量相关的履行服务。有效值: 手册或履行服务的句柄。
'inventory_management': 'shopify',//跟踪产品变量库存项目数量的履行服务 :shopify您正在使用管理员自己跟踪库存,null 当前位置你没有跟踪变体的库存情况,
'option1': 'Default Title',
'option2': None,
'option3': None,
"created_at": "2022-05-04T18:28:48+09:00",
"updated_at": "2022-05-04T18:42:45+09:00",
'taxable': True, //是否收税
'barcode': '',//产品的条形码、 UPC 或 ISBN 号
'grams': 0, //产品变量的重量,以克为单位。
'image_id': None,
'weight': 0.0, //重量
'weight_unit': 'kg',//重量单位
'inventory_item_id': 39320107647127, //库存ID
'inventory_quantity': 5, //库存
'old_inventory_quantity': 5, // 旧存货数量
'requires_shipping': True, //需要运输
'admin_graphql_api_id': 'gid://shopify/ProductVariant/37227313561751' //api管理ID
},
],
'options': //[option(7523204006039)],
[{
'id': 7523204006039,
'product_id': 5932984696983,
'name': 'Title',
'position': 1,
'values': ['Default Title']
},],
'images': [image(21951771607191)],
'image': image(21951771607191)
}
GET /admin/api/2022-04/products.json
Retrieves a list of products 检索产品列表GET /admin/api/2022-04/products/count.json
Retrieves a count of products 检索产品计数GET /admin/api/2022-04/products/{product_id}.json
Retrieves a single product 检索单个产品POST /admin/api/2022-04/products.json
Creates a new product 创建一个新产品PUT /admin/api/2022-04/products/{product_id}.json
Updates a product 更新产品DELETE /admin/api/2022-04/products/{product_id}.json
Deletes a product 删除产品
(2)Orders 属性
GET /admin/api/2022-04/orders.json
返回值说明:
{
'id': 2900896612503,
'email': '',
'closed_at': None,//关闭时间
'created_at': '2020-10-27T14:34:01+08:00',
'updated_at': '2020-10-27T14:34:02+08:00',
'number': 1,
'note': '这里是备注',
'token': '3378ad6d7b57251ed0ab48f2bf556989',
'gateway': 'manual', //支付通道:人工
'test': False,
'total_price': '16.26', //总计
'subtotal_price': '13.90', //小计 = 总价 - 折扣
'total_weight': 0, //总重
'total_tax': '2.36',//税费
'taxes_included': False, //含税
'currency': 'CNY', //币种
'financial_status': 'pending', //pending待处理,authorized已授权,partially_paid 部分支付,paid已支付,partially_refunded已部分退款,refunded已退款,voided作废
'confirmed': True, //是否确认
'total_discounts': '0.00', //折扣
'total_line_items_price': '13.90', //商品总价
'cart_token': None, //与订单关联的购物车的ID
'buyer_accepts_marketing': False, //买家接受营销
'name': '#1001',
'referring_site': None, //参考网站
'landing_site': None, //登录网址
'cancelled_at': None, //取消订单的日期和时间
'cancel_reason': None, //取消原因 customer客户:客户取消了订单, fraud欺诈:订单是欺诈性的,inventory库存:订单中的商品库存不足,declined拒绝:付款被拒绝,other其他
'total_price_usd': '2.43',//总美金
'checkout_token': None, //检验token
'reference': None, //引用
'user_id': 65982202007,
'location_id': 56822038679,
'source_identifier': None, //源标识符
'source_url': None, //来源地址
'processed_at': '2020-10-27T14:34:01+08:00',
'device_id': None, //设备id
'phone': None,//手机
'customer_locale': None, //客户地区
'app_id': 1354745,
'browser_ip': None,
'landing_site_ref': None,
'order_number': 1001, //订单号
'discount_applications': [],//折扣应用程序
'discount_codes': [],//折扣代码
'note_attributes': [],
'payment_gateway_names': ['manual'],
'processing_method': 'manual',
'checkout_id': None,
'source_name': 'shopify_draft_order', //来源名字:shopify草稿订单
'fulfillment_status': None, //fulfilled已完成,null未发货,partial部分发货,restocked缺货
'tax_lines': [tax_line(None)], //税费对象数组
'tags': '',
'contact_email': None,
'order_status_url': 'https://weshop1234.myshopify.com/50213322903/orders/3378ad6d7b57251ed0ab48f2bf556989/authenticate?key=7ae88aece4fe483232fc021626c7b03f',
'presentment_currency': 'CNY',
'total_line_items_price_set': total_line_items_price_set(None), //总行项目价格设置
'total_discounts_set': total_discounts_set(None), //总折扣设置
'total_shipping_price_set': total_shipping_price_set(None), //总运费
'subtotal_price_set': subtotal_price_set(None), //小计价格设置
'total_price_set': total_price_set(None), //总价格设置
'total_tax_set': total_tax_set(None), //总税费设置
'line_items': //[line_item(6249679061143)],
[{
'id': 6249750626455,
'variant_id': 37227313561751,
'title': 'Burton Custom Freestyle 151',
'quantity': 1,//数量
'sku': '',
'variant_title': None,
'vendor': 'weshop1234',
'fulfillment_service': 'manual',
'product_id': 5932984696983,
'requires_shipping': True,
'taxable': True,
'gift_card': False,
'name': 'Burton Custom Freestyle 151',
'variant_inventory_management': 'shopify',
'properties': [],
'product_exists': True,
'fulfillable_quantity': 1,//发货数量
'grams': 0,
'price': '13.90',
'total_discount': '0.00',
'fulfillment_status': None,
'price_set': price_set(None),
'total_discount_set': total_discount_set(None),
'discount_allocations': [discount_allocation(None)],
'admin_graphql_api_id': 'gid://shopify/LineItem/6249750626455',
'tax_lines': [tax_line(None)]
},],
'fulfillments': [ //物流 保存物流记录
{
'id': 2720493699223,
'status': 'cancelled',
'created_at': '2020-10-27T15:07:44+08:00',
'service': 'manual',
'updated_at': '2020-10-27T15:09:48+08:00',
'tracking_company': None,
'shipment_status': None,
'location_id': 56822038679,
'line_items': [line_item(6249750626455)],
'tracking_number': None,
'tracking_numbers': [],
'tracking_url': None,
'tracking_urls': [],
'receipt': receipt(None),
'name': '#1003.1',
'admin_graphql_api_id': 'gid://shopify/Fulfillment/2720493699223'
},
],
'refunds': [], //退款详情
'total_tip_received': '0.0', //总收款
'admin_graphql_api_id': 'gid://shopify/Order/2900896612503',
'shipping_lines': [ //配送相关信息
{
'id': 2343690797207,
'title': '运费',
'price': '10.00',
'code': 'custom',
'source': 'shopify',
'phone': None,
'requested_fulfillment_service_id': None,
'delivery_category': None,
'carrier_identifier': None,
'discounted_price': '10.00',
'price_set': price_set(None),
'discounted_price_set': discounted_price_set(None),
'discount_allocations': [],
'tax_lines': []
},
],
//已付款则会出现以下信息
'current_total_price': '32.52',
'current_total_price_set': current_total_price_set(None),
'total_outstanding': '16.26',
'current_subtotal_price': '27.80',
'current_subtotal_price_set': current_subtotal_price_set(None),
'current_total_tax': '4.72',
'current_total_tax_set': current_total_tax_set(None),
'current_total_discounts': '0.00',
'current_total_discounts_set': current_total_discounts_set(None)
}
四. 无需配置开发环境,直接搭建后台管理工具
在使用任何前端框架搭建 Shopify 后台管理工具时,开发者要处理一系列前端问题,从构建器的选择,到组件的开发,再到打包上线。每一步都费时费力,有没有一种开箱即用,无需管任何前端问题,让开发者专注在开发需求上的工具呢?推荐一下卡拉云,帮你快速搭建企业内部工具。
卡拉云是一套快速搭建企业内部工具的开发平台,因为 Shopify API 需要付费,我就用卡拉云搭建一套 「SQL admin」管理工具作为 DEMO 演示吧,试试里的功能,你也可以用 10 分钟搭建一套属于你的后台管理工具,了解更多。
你开发完的管理工具可直接分享给同事使用:https://my.kalacloud.com/apps/8z9z3yf9fy/published
卡拉云是新一代低代码开发平台,与 Vue 这类框架相比,卡拉云无需配置开发环境,直接注册即可开始搭建。开发者无需处理任何前端问题,简单拖拽即可生成表格、表单、富文本等功能组件,一键接入数据库及 API,快速完成企业内部工具搭建,还可以分享给团队成员共享使用,数周的开发时间,缩短至 1 小时。
扩展阅读: