简体   繁体   English

如何使用 Shopify Node JS API 为私有应用程序创建 REST 请求?

[英]How to create a REST request using the Shopify Node JS API for a Private App?

I'm trying to use the Shopify API to query all the orders of a selected Shopify store, using the private app instead of the OAUTH method.我正在尝试使用 Shopify API 查询所选 Shopify 商店的所有订单,使用私有应用程序而不是 OAUTH 方法。 Below I have added the code, can't seem to figure out how to get it to work cause there isn't much documentation for the use of the private apps.下面我添加了代码,似乎无法弄清楚如何让它工作,因为没有太多关于使用私有应用程序的文档。 Does anyone know how I can achieve this or has done this before?有谁知道我如何做到这一点或以前做过吗? I think I maybe wrong but there maybe an error in creating the session.我想我可能错了,但创建会话时可能有错误。

Upon running the below code I get the below error: Error: Missing adapter implementation for 'abstractRuntimeString' - make sure to import the appropriate adapter for your platform运行以下代码后,我收到以下错误: Error: Missing adapter implementation for 'abstractRuntimeString' - make sure to import the appropriate adapter for your platform

const { shopifyApi, ApiVersion, Session, LATEST_API_VERSION } = require('@shopify/shopify-api');
const { randomUUID } = require('crypto');
const { restResources } = require('@shopify/shopify-api/rest/admin/2022-10');


const selectedStore = {
shop: "store.myshopify.com",
api_secret: "",
api_key: "",
private_admin_key: ""
};

const shopify = shopifyApi({
    apiKey: selectedStore.api_key,
    apiSecretKey: selectedStore.api_secret,
    scopes: ['read_orders', 'read_analytics', 'read_customers'],
    hostName: '<ngrok_url>',
    apiVersion: LATEST_API_VERSION,
    isEmbeddedApp: false,
    isPrivateApp: true,
    restResources
});

const session = new Session({
    id: randomUUID(),
    state: 'state',
    shop: selectedStore.shop,
    accessToken: selectedStore.private_admin_key,
    isOnline: true,
})

console.log(session)

const getOrders = async () => {
    const orders = await shopify.rest.Order.all({
        session,
        status: "all"
    })
    return orders
}

getOrders()

If you have a Auth Token from a private App (inside the Shopify Admin), with permissions to read orders, you make a call to the Shopify store using that token.如果您拥有来自私人应用程序(在 Shopify 后台)的授权令牌,并且具有读取订单的权限,您可以使用该令牌调用 Shopify 商店。 Look up the end point you call.查找您调用的终点 Formulate your call.制定你的电话。 Make a GET or POST.进行 GET 或 POST。 Nothing hard to do there.那里没什么难做的。 Shopify assumes you know how to make a GET request with JS. Shopify 假定您知道如何使用 JS 发出 GET 请求。 Provide the Auth Token you gave yourself, and you'll get back all the orders you asked for.提供您给自己的 Auth Token,您将取回您要求的所有订单。 You cannot skip out on learning paging etc.. but again, that is also pretty standard stuff not special to Shopify.你不能跳过学习分页等。但同样,这也是非常标准的东西,对 Shopify 来说并不特别。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM