Table of Contents
Custom Shipping Code GoShippo Integration
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.
Requirements
- A Foxy store on version 2.0
- At least one category configured with a delivery type of “Shipped using live shipping rates”
- An active Shippo account
Installation
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"); }
Steps
- Log in to your store's Foxy administration
- Head to the “Shipping” page
- Scroll down until you see the “Custom Shipping Code” option, and check the option for “use custom code”.
- In the code editor that appears, copy and paste the code shown above. Don't save it just yet.
- In a new tab, log in to your Shippo account
- Go to Settings and then API
- Within the “Tokens” section, click the “Generate Token” button under “Live Tokens”
- Copy the API key generated to your clipboard, and in the code you pasted into your Foxy admin above on this line:
let myshippo = require('shippo')('YOUR_SHIPPO_LIVE_API_KEY');
Replace theYOUR_SHIPPO_LIVE_API_KEY
text with your copied API key - Click the “Update” button to save your new settings
- Wait ~15-20 seconds and refresh the page (the custom shipping code feature is a separate system, so takes a moment to initialize, you should see your custom code again after refreshing if it was successful)
- You're done! Now you can test it out!
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.
Taking It Further
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.