Discussions

Ask a Question
Back to All

Unexpected error when testing website api

const fetch = require('node-fetch');

const url = 'https://api.easyship.com/v2/rates';
const options = {
method: 'POST',
headers: {
Accept: 'text/plain',
'Content-Type': 'application/json',
Authorization: 'Bearer '
},
body: JSON.stringify({
origin_address: {
line_1: 'BLK 54 02#84 Pipit Road',
state: 'Singapore',
city: 'Singapore',
postal_code: '370054',
contact_name: 'Eswaran Saravanan',
contact_phone: '96559015',
contact_email: '[email protected]'
},
destination_address: {
country_alpha2: 'US',
line_1: '777 Brockton Avenue, Abington MA 2351',
city: 'Abington ',
postal_code: '02351',
state: 'Massachusetts ',
contact_name: 'Eswaran Saravanan',
contact_phone: '96559015',
contact_email: '[email protected]'
},
incoterms: 'DDU',
insurance: {is_insured: 'false'},
courier_selection: {apply_shipping_rules: 'true'},
shipping_settings: {units: {weight: 'kg', dimensions: 'cm'}, output_currency: 'USD'},
parcels: [
{
total_actual_weight: '1.0',
box: {length: 10, width: 10, height: 4},
items: [
{
quantity: '1',
dimensions: {},
category: 'accessory_no_battery',
description: 'micro-controllers',
actual_weight: 0.5,
declared_currency: 'US',
declared_customs_value: 20,
sku: 'tryStandard'
}
]
}
]
})
};

fetch(url, options)
.then(res => res.json())
.then(json => console.log(json))
.catch(err => console.error('error:' + err));