I am trying to get shipping rates from Shippo API using go-shippo. At first it worked fine and I was getting the rates in the specified currency but now its not.

// create a sending address
    addressFromInput := &shippomodels.AddressInput{
        Name:    from.ShippingName,
        Street1: from.Street1,
        City:    from.CityName,
        State:   from.State,
        Zip:     from.Zip,
        Country: models.GetCountryCode(from.ShippingCountry),
        Phone:   from.Phone,
        Email:   from.ShippingEmail,
    }
    shippoClient := initializeShippo()
    _, err := shippoClient.CreateAddress(addressFromInput)
    if err != nil {

        logrus.Warn("Couldn't create from address:", err)
    }

    // create a receiving address
    addressToInput := &shippomodels.AddressInput{
        Name:    to.ShippingName,
        Street1: to.Street1,
        City:    to.CityName,
        State:   to.State,
        Zip:     to.Zip,
        Country: models.GetCountryCode(to.ShippingCountry),
        Phone:   to.Phone,
        Email:   to.ShippingEmail,
    }
    _, err = shippoClient.CreateAddress(addressToInput)
    if err != nil {

        logrus.Warn("Couldn't create to address:", err)
    }
    logrus.Info("AddressTo:", addressToInput)
    logrus.Info("AddressFrom:", addressFromInput)

    // create a parcel
    parcelInput := &shippomodels.ParcelInput{
        Length:       strconv.FormatFloat(art.Length, 'E', -1, 64),
        Width:        strconv.FormatFloat(art.Thickness, 'E', -1, 64),
        Height:       strconv.FormatFloat(art.Height, 'E', -1, 64),
        DistanceUnit: shippomodels.DistanceUnitCentiMeter,
        Weight:       strconv.FormatFloat(art.Weight, 'E', -1, 64),
        MassUnit:     shippomodels.MassUnitKiloGram,
    }
    parcel, err := shippoClient.CreateParcel(parcelInput)
    if err != nil {
        logrus.Warn("Shippo Error:", err)
    }
    // create a shipment
    shipmentInput := &shippomodels.ShipmentInput{
        AddressFrom:   addressFromInput,
        AddressTo:     addressToInput,
        Parcels:       []string{parcel.ObjectID},
        AddressReturn: addressFromInput,
        Async:         false,
    }
    shipment, err := shippoClient.CreateShipment(shipmentInput)
    logrus.Info(shipment.Status)
    if err != nil {
        logrus.Warn("Shippo:shippingcontroller:", err)
    }
    
    rates, err := shippoClient.GetShippingRates(shipment.ObjectID, "USD")
    if err != nil {
        logrus.Warn("Shippo rates error:", err, "Status:", shipment.Status)
    }
    return rates, err

I checked the shipment object does have rates in the local currency and the currency of where the package is from. However, retrieving the rates in the specified currency is where it fails. Giving me :Error returned from API: [404] {\"detail\":\"Not found.\"}

I have checked if the issue is that the shipment object doesn't exist but it does. so it has to be something else that is not found

0

There are 0 best solutions below