javascriptnode.jsapicontrollereasypost

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.

How do I run multiple tracking numbers through the API?

All help is greatly appreciated.

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)

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

Tracker Object (Provided By Easy Post)

        const tracker = new api.Tracker({

        tracking_code: tracking,
        carrier: carrier
    });

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

})
}

Solution

  • @kfunk This worked, but I will look into the other method for the alternative format you suggested.

    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);
    
            });
        });`