I'm working on a project where I'm using shippo to get my shipping labels. Recently, my computer restarted, and I had an issue where mongodb
wasn't connecting. I finally, got mongodb
to reconnect by reinstalling and then reconnecting it, but when it did none of my data was there, so I ended up recreating most of it. I've been trying to create new test orders since my old ones are no longer available, but I can't because now my shippo integration is not working, and I am getting POST http://127.0.0.1:5000/api/shippo/ net::ERR_CONNECTION_REFUSED
in my console. I don't understand why this is happening, since everything was working properly before the restart. I tried to run a debugger and it's giving me an error stating: Exception has occurred: SyntaxError: Unexpected token < in JSON at position 0
.
This is what I have:
import express from 'express';
import shippo from 'shippo';
import expressAsyncHandler from 'express-async-handler';
import User from './models/userModel.js';
const shippoToken = "";
const shippoClient = shippo(shippoToken);
const shippoRouter = express.Router();
shippoRouter.post(
'/',
expressAsyncHandler(async (req, res) => {
var addressFrom = {
"name": "req.body.name1",
"street1": "req.body.street11",
"city": "req.body.city1",
"state": "req.body.state1",
"zip": "req.body.zip1",
"country": "req.body.country1"
};
var addressTo = {/*shippoClient.address.create({*/
"name": req.body.name,
"street1": req.body.street1,
"street2": req.body.street2,
"city": req.body.city,
"state": req.body.state,
"zip": req.body.zip,
"country": req.body.country,
"phone": req.body.phone,
"email":req.body.email,
"validate": true,
};
//function(err, address) {
// asynchronously called
//});
// asynchronously called
/*console.log(req.body);
console.log(addressFrom)
console.log(addressTo)*/
var parcel = {
"length": "5",
"width": "3",
"height": "2",
"distance_unit": "in",
"weight": ".7",
"mass_unit": "lb"
};
shippoClient.shipment.create({
"address_from": addressFrom,
"address_to": addressTo,
"parcels": [parcel],
"async": false
})
.catch(function(err) {
// Deal with an error
console.log("There was an error creating shipment: %s", err);
}).then(async function(shipment) {
console.log(shipment)
const shippingId = shipment.object_id
})
I'm getting both of the addresses and the parcel information, but console.log(shipment)
within
.then(async function(shipment) {
console.log(shipment)
const shippingId = shipment.object_id
})
is giving me undefined
. Does anyone know why this could be happening?