The following page details integrating Shippo into your Foxy store for fetching shipping rates from any of their supported providers, using the Custom Shipping Code functionality available for Foxy stores.
Below is the custom shipping code you'll use to connect to Shippo, and below that is the steps to install it on your store.
let myshippo = require('shippo')('YOUR_SHIPPO_LIVE_API_KEY'); let shipment = cart['_embedded']['fx:shipment']; let addressFrom = { 'state': shipment['origin_region'], 'zip': shipment['origin_postal_code'], 'country': shipment['origin_country'] }; let addressTo = { 'name': shipment['first_name'] + " " + shipment['last_name'], 'company': shipment['company'], 'street1': shipment['address1'], 'city': shipment['city'], 'state': shipment['region'], 'zip': shipment['postal_code'], 'country': shipment['country'], 'is_residential': shipment['is_residential'] }; let parcel = { 'length': '5', 'width': '5', 'height': '5', 'distance_unit': 'in', 'weight': shipment['total_weight'], 'mass_unit': 'lb', }; try { let myshipment = await myshippo.shipment.create({ "address_from": addressFrom, "address_to": addressTo, "parcels": [parcel], "async": false }); let rate_options = await myshippo.shipment.rates(myshipment.object_id); for (var i = 0; i < rate_options.results.length; i++) { rates.add((10000+i), rate_options.results[i]['amount'], rate_options.results[i]['provider'], rate_options.results[i]['servicelevel']['name']); } } catch (e) { console.log(e); rates.error("Sorry, we're unable to get shipping rates at this time. Please try again, or contact us to finalize your order"); }
let myshippo = require('shippo')('YOUR_SHIPPO_LIVE_API_KEY');
Replace the YOUR_SHIPPO_LIVE_API_KEY
text with your copied API key
To test our the new rates after saving, you can simply add a product to your cart that belongs to a live rate shippable category. On the cart or checkout, after entering a shipping address, you should see your rates returning from your Shippo account.
This integration is fairly basic - it just returns all rates from Shippo, and passes it some default values. Shippo provides some optional extras you can use in their API which you could customise the integration above further to make use of.
You can also customise the rates returned, to only output specific rates or work with them further using our custom shipping code API documented here.