标签: shopify-api-node

如何使用nodejs验证shopify webhook api

我无法使用“shopify-node-api”验证来自 shopify 的 webhook 响应。我正在使用以下代码来验证签名。

以下代码位于 app.js 上

app.use(bodyParser.json({
type:'application/json',
limit: '50mb',
verify: function(req, res, buf, encoding) {
     if (req.url.startsWith('/webhook')){
         req.rawbody = buf;
     }
   }
 })
);
app.use("/webhook", webhookRouter);
Run Code Online (Sandbox Code Playgroud)

下面是 webhook.router.js

router.post('/orders/create', verifyWebhook, async (req, res) => {    
    console.log(' We got an order')
    res.sendStatus(200)
 });
Run Code Online (Sandbox Code Playgroud)

下面为验证函数

function verifyWebhook(req, res, next) {
  let hmac;
  let data;
  try {
    hmac = req.get("X-Shopify-Hmac-SHA256");
    data = req.rawbody;
  } catch (e) {
    console.log(`Webhook request failed from: ${req.get("X-Shopify-Shop-Domain")}`);
    res.sendStatus(200);
  }
  if (verifyHmac(JSON.stringify(data), hmac)) { // Problem …
Run Code Online (Sandbox Code Playgroud)

node.js shopify shopify-api-node

6
推荐指数
1
解决办法
6219
查看次数

AppBridgeError INVALID_CONFIG:必须提供主机

我在尝试完成有关开发 Shopify 应用程序的官方 Shopify 教程时遇到错误。

我一直在一步一步地遵循教程,但即便如此,仍然遇到了问题,抛出错误,表明我的配置文件无效,因为它不包含主机。

我的_app.js文件代码如下:

import React from "react";
import App from "next/app";
import Head from "next/head";
import { AppProvider, Frame } from "@shopify/polaris";
import "@shopify/polaris/dist/styles.css";
import translations from "@shopify/polaris/locales/en.json";
import { Provider } from "@shopify/app-bridge-react";
import ClientRouter from "../components/ClientRouter";

class MyApp extends App {
  render() {
    const { Component, pageProps, shopOrigin } = this.props;
    const config = {
      apiKey: API_KEY,
      shopOrigin,
      forceRedirect: true,
    };
    console.log(config);
    return (
      <React.Fragment>
        <Head>
          <title>Sample App</title>
          <meta charSet="utf-8" />
        </Head>
        <Provider …
Run Code Online (Sandbox Code Playgroud)

shopify-app shopify-api-node

6
推荐指数
1
解决办法
5218
查看次数

使用 React 和 Node 问题构建 Shopify Ap

我正在遵循 Shopify 提供的 Shopify 应用程序开发方法,但我的本地主机不断收到错误消息 - 外部服务器错误,终端中的原因是“上下文尚未正确初始化”。请调用 .initialize() 方法来设置您的应用程序上下文对象。但不确定如何在下面的 server.js 文件中执行此操作;

require('isomorphic-fetch');
const dotenv = require('dotenv');
const Koa = require('koa');
const next = require('next');
const { default: createShopifyAuth } = require('@shopify/koa-shopify-auth');
const { verifyRequest } = require('@shopify/koa-shopify-auth');
const session = require('koa-session');

dotenv.config();

const port = parseInt(process.env.PORT, 10) || 3000;
const dev = process.env.NODE_ENV !== 'production';
const app = next({ dev });
const handle = app.getRequestHandler();

const { SHOPIFY_API_SECRET_KEY, SHOPIFY_API_KEY } = process.env;

app.prepare().then(() => {
  const server = new Koa(); …
Run Code Online (Sandbox Code Playgroud)

javascript node.js shopify shopify-app shopify-api-node

5
推荐指数
1
解决办法
6847
查看次数

@shopify/shopify-api jws 依赖不起作用

我是 Shopify 的新手,当我尝试使用 @shopify/shopify-api 时遇到问题。我正在从 API 导入此属性。

import Shopify from '@shopify/shopify-api'
Run Code Online (Sandbox Code Playgroud)

当我进行导入时,出现下一个错误。

Uncaught TypeError: util.inherits is not a function
at node_modules/jsonwebtoken/node_modules/jws/lib/data-stream.js (data-stream.js:39:6)
at __require (chunk-IGMYUX52.js?v=cd28f3b3:40:50)
at node_modules/jsonwebtoken/node_modules/jws/lib/sign-stream.js (sign-stream.js:3:18)
at __require (chunk-IGMYUX52.js?v=cd28f3b3:40:50)
at node_modules/jsonwebtoken/node_modules/jws/index.js (index.js:2:18)
at __require (chunk-IGMYUX52.js?v=cd28f3b3:40:50)
at node_modules/jsonwebtoken/decode.js (decode.js:1:11)
at __require (chunk-IGMYUX52.js?v=cd28f3b3:40:50)
at node_modules/jsonwebtoken/index.js (index.js:2:11)
at __require (chunk-IGMYUX52.js?v=cd28f3b3:40:50)
Run Code Online (Sandbox Code Playgroud)

所以我转到文件中发生错误的行:

node_modules/jsonwebtoken/node_modules/jws/lib/data-stream.js
Run Code Online (Sandbox Code Playgroud)

我发现错误是节点包中的一个属性

如果您在此处看不到图像,请查看代码行。

util.inherits(DataStream, Stream);
Run Code Online (Sandbox Code Playgroud)

所以我查阅了节点文档,发现该方法不鼓励使用,但并未弃用,因此它应该可以工作。

如果您看不到图像,这里是该方法的描述。

不鼓励使用util.inherits()。请使用 ES6 class 和 extends 关键字来获得语言级别的继承支持。另请注意,这两种样式在语义上不兼容。

将原型方法从一个构造函数继承到另一个构造函数。构造函数的原型将被设置为从创建的新对象 superConstructor

这主要是在Object.setPrototypeOf(constructor.prototype, superConstructor.prototype). 作为额外的便利, superConstructor可通过constructor.super_ 酒店抵达。

有问题的包名为 jws,我不太确定这个包的用途,我有修改文件并使用原型继承替换该代码行的想法,但我不知道这样做有多好。此外,我必须对每个存在该问题的文件执行此操作,我还没有在互联网上找到有关此问题的任何信息。

shopify shopify-app shopify-api-node shopify-api

5
推荐指数
0
解决办法
337
查看次数

如何根据Python中动态给出的多个不同标签获取shopify产品?

我正在尝试通过基于标签的过滤来从 Shopify 获取产品。标签将是动态的,不止一个,并且会发生变化。

import json
import time
import requests

API_KEY = 'xxxx'
PASSWORD = 'xxxx'
SHOP_NAME = 'xxxx'
API_VERSION = '2020-04' #change to the API version
shop_url = "https://%s:%s@%s.myshopify.com/admin/api/%s" % (API_KEY, PASSWORD, SHOP_NAME, API_VERSION)

def callShopifyGraphQL(GraphQLString, data):
    headers = {
        "X-Shopify-Storefront-Access-Token": 'xxxxxx',
        "accept":"application/json"      
    }
    response = requests.post(shop_url+'/graphql', json={'query': GraphQLString, 'variables': data}, headers=headers)
    answer = json.loads(response.text)
    return answer['data']

str1 = '0-12'
str2 = 'physical'

graphQLquery7 = """ {
  products(first:100, query:"tag:$tags") {
    edges {
      node {
        id
        tags
        title
        onlineStoreUrl
      }
    } …
Run Code Online (Sandbox Code Playgroud)

shopify graphql shopify-api-node shopify-api

3
推荐指数
1
解决办法
5168
查看次数

结帐时修改 Shopify 运费

我们是否可以通过 API 调用或脚本在结账时添加自定义运费? 在此输入图像描述

我想根据一些规则修改价格,但我不知道如何在 Shopify 中执行此操作。任何帮助将不胜感激。

shopify shopify-app shopify-api-node shopify-api

3
推荐指数
1
解决办法
2035
查看次数

如何在序列异步函数中处理数组

我正在尝试制作一个包含 Shopify 订单和图片链接的表格。但异步循环有问题。每次我运行代码时,控制台中的顺序都会以错误的顺序出现,例如 998、996、1000... 应该是 1000、999、998...\n我尝试在不同的位置添加 async 关键字,并包装一个settimeout 函数中的函数等等,但没有运气。\n如何使订单列表按正确的顺序?\n提前谢谢您。

\n\n

\r\n
\r\n
const\xc2\xa0{google}\xc2\xa0=\xc2\xa0require(\'googleapis\');\r\nconst\xc2\xa0keys\xc2\xa0=\xc2\xa0require(\'./keys.json\');\r\nconst Shopify = require(\'shopify-api-node\');\r\nconst\xc2\xa0client\xc2\xa0=\xc2\xa0new\xc2\xa0google.auth.JWT(\r\n    keys.client_email,\r\n    null,\r\n    keys.private_key,\r\n    [\'https://www.googleapis.com/auth/spreadsheets\',\r\n    \'https://www.googleapis.com/auth/drive.metadata.readonly\']\r\n);\r\nconst shopify = new Shopify({\r\n  shopName: \'name.myshopify.com\',\r\n  apiKey: \'key\',\r\n  password: \'pas\'\r\n});\r\nconst\xc2\xa0sheets\xc2\xa0=\xc2\xa0google.sheets({version:\xc2\xa0\'v4\',\xc2\xa0auth:\xc2\xa0client});\r\nconst\xc2\xa0drive\xc2\xa0=\xc2\xa0google.drive({version:\xc2\xa0\'v3\',\xc2\xa0auth:\xc2\xa0client});\r\n\r\nfunction getLink(){\r\n    client.authorize(()=> gsrun());\r\n}\r\n\r\nasync function runDrive(ord, sku){\r\n    const resDrive = await drive.files.list({\r\n    pageSize:\xc2\xa01,\r\n    q: `name contains "sku"`,\r\n    spaces:\xc2\xa0\'drive\',\r\n    });\r\n    const\xc2\xa0files\xc2\xa0=\xc2\xa0resDrive.data.files;\r\n    let link;\r\n    if\xc2\xa0(files.length)\xc2\xa0{\r\n            link = `https://drive.google.com/file/d/${files[0].id}/view`;\r\n    } else\xc2\xa0{\r\n    // console.log(\'No\xc2\xa0files\xc2\xa0found.\');\r\n    link = \'No\xc2\xa0files\xc2\xa0found.\';\r\n    }\r\n    console.log([ord, sku, link])\r\n}\r\n\r\nasync\xc2\xa0function\xc2\xa0gsrun(){\r\n    // Shopify - Get orders list\r\n    let orders = await shopify.order.list({ limit: 7 …
Run Code Online (Sandbox Code Playgroud)

javascript google-api node.js google-drive-api shopify-api-node

0
推荐指数
1
解决办法
1424
查看次数