简体   繁体   English

如何使用Easy Post API传递多个参数

[英]How to pass multiple parameters using the Easy Post API

I am working with the Easy Post API (Node.js) and I am able to trigger the API to call and respond with a single tracking number. 我正在使用Easy Post API(Node.js),我能够触发API以使用单个跟踪号码进行呼叫和响应。

How do I run multiple tracking numbers through the API? 如何通过API运行多个跟踪号?

All help is greatly appreciated. 非常感谢所有帮助。

Node.js Node.js的

    app.get("/api/tracking/retrieve", (req, res) => {

    const apiKey = 'My_API_Key';
    const Easypost = require('@easypost/api');
    const api = new Easypost(apiKey);

Test Parameters (Provided By Easy Post) 测试参数(由Easy Post提供)

    tracking = ['EZ6000000006', 'EZ6000000006'];
    carrier = ['UPS', 'UPS'];

Tracker Object (Provided By Easy Post) 跟踪器对象(由Easy Post提供)

        const tracker = new api.Tracker({

        tracking_code: tracking,
        carrier: carrier
    });

tracker.save().then(console.log);

})
}

If I understand your question correctly, you need to call new api.Tracker({...}).save... in a loop: 如果我正确理解了您的问题,则需要new api.Tracker({...}).save...调用new api.Tracker({...}).save...

const Easypost = require('@easypost/api');
const api = new Easypost('<YOUR_TEST/PRODUCTION_API_KEY>');

const trackingCodes = ['9400110898825022579493', '9400110898825022579494'];

trackingCodes.forEach(trackingCode => {
  const tracker = new api.Tracker({
    tracking_code: trackingCode,
    carrier: 'USPS',
  });

  tracker.save().then(console.log);
});


@kfunk This worked, but I will look into the other method for the alternative format you suggested. @kfunk这很有用,但我会研究你建议的替代格式的另一种方法。

Here's the code: 这是代码:

  `trackingCodes.forEach((trackingCode) => {
        carrierCodes.forEach((carrierCode) => {
            const tracker = new api.Tracker({
                tracking_code: trackingCode,
                carrier: carrierCode
            });

            tracker.save().then(console.log);

        });
    });`

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

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