Shippo: невозможно получить тарифы на почтовые услуги USPS и DHL

Я хочу получить расценки от UPS и DHL, используя shippo, это учетные записи операторов https://api.goshippo.com/carrier_accounts/ которые я использую для создания переходов, но не могу получить ставки доставки между двумя адресами. Я установил этот пакет NPM https://www.npmjs.com/package/shippo Вот мой код.

var addressFrom  = {
    "name":"Ms Hippo",
    "company":"Shippo",
    "street1":"215 Clayton St.",
    "city":"San Francisco",
    "state":"CA",
    "zip":"94117",
    "country":"US", //iso2 country code
    "phone":"+1 555 341 9393",
    "email":"support@goshippo.com",
};

// example address_to object dict
var addressTo = {
    "name":"Ms Hippo",
    "company":"Shippo",
    "street1":"803 Clayton St.",
    "city":"San Francisco",
    "state":"CA",
    "zip":"94117",
    "country":"US", //iso2 country code
    "phone":"+1 555 341 9393",
    "email":"support@goshippo.com",
};

// parcel object dict
var parcelOne = {
    "length":"5",
    "width":"5",
    "height":"5",
    "distance_unit":"in",
    "weight":"2",
    "mass_unit":"lb"
};

var parcelTwo = {
    "length":"5",
    "width":"5",
    "height":"5",
    "distance_unit":"in",
    "weight":"2",
    "mass_unit":"lb"
};

var shipment = {
    "address_from": addressFrom,
    "address_to": addressTo,
    "parcels": [parcelOne, parcelTwo],
};

shippo.transaction.create({
    "shipment": shipment,
    "servicelevel_token": "usps_priority",
    "carrier_account": "b2824c5558024db9adfc3ceb0d0d34b1",
    "label_file_type": "png"
})
    .then(function(transaction) {
        shippo.transaction.list({
            "rate": transaction.rate
        })
            .then(function(mpsTransactions) {
                mpsTransactions.results.forEach(function(mpsTransaction){
                    if(mpsTransaction.status == "SUCCESS") {
                        console.log("Label URL: %s", mpsTransaction.label_url);
                        console.log("Tracking Number: %s", mpsTransaction.tracking_number);
                    } else {
                        // hanlde error transactions
                        console.log("Message: %s", mpsTransactions.messages);
                    }
                });
            }).catch(err=>{
                console.log(err);
        })
    }, function(err) {
        // Deal with an error
        console.log("There was an error creating transaction : %s", err.detail);
    });

И вот ошибка, которую я получаю от API

{ 
   [Error: The data you sent was not accepted as valid]
   type: 'ShippoAPIError',
   rawType: undefined,
   code: undefined,
   param: undefined,
   message: 'The data you sent was not accepted as valid',
   detail: '{"detail":" is not a valid object_id"}',
   raw:
      { message: 'The data you sent was not accepted as valid',
      detail: '{"detail":" is not a valid object_id"}' } 
}

0 ответов

Другие вопросы по тегам