{"id":11143,"date":"2024-08-20T12:46:09","date_gmt":"2024-08-20T12:46:09","guid":{"rendered":"https:\/\/spreecommerce.org\/?post_type=cpt_integrations&#038;p=11143"},"modified":"2024-08-21T13:23:23","modified_gmt":"2024-08-21T13:23:23","slug":"easypost-and-spree-integration","status":"publish","type":"cpt_integrations","link":"https:\/\/spreecommerce.org\/integrations\/easypost-and-spree-integration\/","title":{"rendered":"EasyPost and Spree integration"},"content":{"rendered":"\n<p><a href=\"https:\/\/www.easypost.com\/\">EasyPost<\/a>&nbsp;was founded in 2012 as the first RESTful API for shipping. The company has thousands of customers shipping millions of packages each month. It allows users to buy postage labels, check rates, verify an address, track their shipments, and more with all of the major shipping companies, including&nbsp;<a href=\"https:\/\/spreecommerce.org\/integrations\/usps-integration-with-spree\/\">USPS<\/a>,&nbsp;<a href=\"https:\/\/spreecommerce.org\/integrations\/ups-integration-with-spree\/\">UPS<\/a>,&nbsp;<a href=\"https:\/\/spreecommerce.org\/integrations\/dhl-integration-with-spree\/\">DHL<\/a>, and FedEx.<br>The benefits of using EasyPost for your ecommerce business:<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Modern Flexible Restful API<\/h3>\n\n\n\n<p>EasyPost gives you a modern, flexible RESTful API that connects to all the major carriers without the hassle and makes it easy to add shipping and tracking to your app.<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Shipping API<\/li>\n<\/ul>\n\n\n\n<p>Purchase shipping labels for USPS, UPS, FedEx, and&nbsp;<a href=\"https:\/\/www.easypost.com\/carriers\">100+ other carriers<\/a><\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Tracking API<\/li>\n<\/ul>\n\n\n\n<p>Track packages across all major carriers<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Shipping Insurance<\/li>\n<\/ul>\n\n\n\n<p>Shipping insurance for all items sent with EasyPost<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Address verification<\/li>\n<\/ul>\n\n\n\n<p>Validate domestic and international addresses<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Rating API<\/li>\n<\/ul>\n\n\n\n<p>Rate across all your carriers<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Fulfillment<\/li>\n<\/ul>\n\n\n\n<p>The tech-forward solution for all order fulfillment needs<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Freight Shipping<\/li>\n<\/ul>\n\n\n\n<p>Move freight via carriers offering competitive rates and enhanced supervision<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>International &amp; Customs<\/li>\n<\/ul>\n\n\n\n<p>Learn how to handle international shipping seamlessly<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">How to integrate EasyPost with Spree<\/h2>\n\n\n\n<h2 class=\"wp-block-heading\">Installation<\/h2>\n\n\n\n<ol class=\"wp-block-list\">\n<li>Add&nbsp;<a href=\"https:\/\/github.com\/ShopFelixGray\/spree_easypost\">this extension<\/a>&nbsp;to your Gemfile with this line:<\/li>\n<\/ol>\n\n\n\n<pre class=\"wp-block-preformatted\">gem 'spree_easypost', github: 'ShopFelixGray\/spree_easypost'<\/pre>\n\n\n\n<ol start=\"2\" class=\"wp-block-list\">\n<li>Install the gem using Bundler:<\/li>\n<\/ol>\n\n\n\n<pre class=\"wp-block-preformatted\">bundle install<\/pre>\n\n\n\n<ol start=\"3\" class=\"wp-block-list\">\n<li>Copy &amp; run migrations<\/li>\n<\/ol>\n\n\n\n<pre class=\"wp-block-preformatted\">bundle exec rails g spree_easypost:install\nrake db:migrate<\/pre>\n\n\n\n<ol start=\"4\" class=\"wp-block-list\">\n<li>This goes into a new file called&nbsp;<code>config\/initializers\/easy_post.rb<\/code>:<\/li>\n<\/ol>\n\n\n\n<pre class=\"wp-block-preformatted\">EasyPost.api_key = 'YOUR_API_KEY_HERE'<\/pre>\n\n\n\n<ol start=\"5\" class=\"wp-block-list\">\n<li>Restart your server<\/li>\n<\/ol>\n\n\n\n<p>If your server was running, restart it so that it can find the assets properly.<\/p>\n\n\n\n<ol start=\"6\" class=\"wp-block-list\">\n<li>Add Carrier Accounts<\/li>\n<\/ol>\n\n\n\n<p>Make sure to add accounts (separated by commas but NO spaces) to the EasyPost settings in the admin section configuration. The account ids can be found in your EasyPost dashboard under the carrier section.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\"><a href=\"https:\/\/github.com\/ShopFelixGray\/spree_easypost#usage\"><\/a>Usage<\/h2>\n\n\n\n<ol class=\"wp-block-list\">\n<li>Validating An Address<\/li>\n<\/ol>\n\n\n\n<p>To validate an address with this gem, call&nbsp;<code>.easypost_address_validate<\/code>&nbsp;on an instance of the&nbsp;<code>Spree::Address<\/code>&nbsp;model.<\/p>\n\n\n\n<p>Example:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">Spree::Address.find(1).easypost_address_validate<\/pre>\n\n\n\n<p>This method will not run the model validations that already exist in your application, nor will it save or update an address for you. This method is only designed to run the address through the EasyPost API and return a hash with suggestions to update the address if successful or return EasyPost error message is unsuccessful.<\/p>\n\n\n\n<ol start=\"2\" class=\"wp-block-list\">\n<li>Response from the&nbsp;<code>.easypost_address_validate<\/code>&nbsp;method<\/li>\n<\/ol>\n\n\n\n<p>This method will respond with a hash containing a key which will be either&nbsp;<code>:suggestions<\/code>&nbsp;(if the address is determined deliverable) or&nbsp;<code>:errors<\/code>&nbsp;(if the address is invalid or not deliverable).<\/p>\n\n\n\n<p>Given the following address hash:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">{\n  firstname: \"Bob\",\n  lastname: \"Seger\",\n  address1: \"624 W 139th St\",\n  address2: \"Apt 2C\",\n  city: \"New York\",\n  state_id: \"3561\",\n  zipcode: \"10031\",\n  country_id: \"232\",\n  phone: \"1234567890\"\n}<\/pre>\n\n\n\n<p>The suggestion hash will return the following \u2013 changing some of the formatting and moving address 2 to the address 1 line:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">{\n  suggestions: {\n    address1: \"624 W 139TH ST APT 2C\",\n    address2: \"\",\n    city: \"NEW YORK\",\n    zipcode: \"10031-7329\"\n  }\n}<\/pre>\n\n\n\n<ol start=\"3\" class=\"wp-block-list\">\n<li>Error responses from the&nbsp;<code>.easypost_address_validate<\/code>&nbsp;method<\/li>\n<\/ol>\n\n\n\n<p>If the EasyPost API does not validate the address, you will receive an array of errors in the response hash.<\/p>\n\n\n\n<p>Example error messages:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">{\n  errors: {\n    address1: [\"can't be blank\"],\n    address2: [\"Missing secondary information(Apt\/Suite#)\"],\n    address: [\n      \"Invalid city\/state\/ZIP\",\n      \"Address not found\"\n    ]\n  }\n}<\/pre>\n\n\n\n<p>Errors will be returned under the&nbsp;<code>address<\/code>&nbsp;key if they are not particular to a specific part of the address such as when the address does not exist or if the error is related to multiple parts of the address (such as city\/state\/zip mismatch).<\/p>\n\n\n\n<h2 class=\"wp-block-heading\"><a href=\"https:\/\/github.com\/ShopFelixGray\/spree_easypost#testing\"><\/a>Testing<\/h2>\n\n\n\n<p>First bundle your dependencies, then run&nbsp;<code>rake<\/code>.&nbsp;<code>rake<\/code>&nbsp;will default to building the dummy app if it does not exist, then it will run specs. The dummy app can be regenerated by using&nbsp;<code>rake test_app<\/code>.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">bundle\nbundle exec rake<\/pre>\n\n\n\n<p>When testing your applications integration with this extension you may use its factories. Simply add this require statement to your spec_helper:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">require 'spree_easypost\/factories'<\/pre>\n\n\n\n<h2 class=\"wp-block-heading\">Example of EasyPost and Spree integration<\/h2>\n\n\n\n<p><a href=\"https:\/\/shopfelixgray.com\/\">Felix Gray<\/a>&nbsp;is a New York based producer of innovative glasses designed for healthier, happy eyes. Since the online store launched in 2016, hundreds of thousands of glasses have been sold. Felix Grays are worn in the offices of companies like Apple, Spotify, and Google. The company uses Spree to run a custom ecommerce platform and EasyPost for its shipping needs.<\/p>\n\n\n\n<p>Read&nbsp; more:&nbsp;<a href=\"https:\/\/spreecommerce.org\/stories\/spree-allows-felix-gray-run-a-custom-ecommerce-platform-and-process-prescriptions-for-lenses\/\">Felix Gray\u2019s success story<\/a><\/p>\n\n\n\n<figure class=\"wp-block-image aligncenter\"><img decoding=\"async\" width=\"570\" height=\"570\" src=\"https:\/\/spreecommerce.org\/wp-content\/uploads\/2019\/01\/felix-mbp.png\" alt=\"Felix Gray Spree Commerce Success Story\" class=\"wp-image-2711\" srcset=\"https:\/\/spreecommerce.org\/wp-content\/uploads\/2019\/01\/felix-mbp.png 570w, https:\/\/spreecommerce.org\/wp-content\/uploads\/2019\/01\/felix-mbp-150x150.png 150w, https:\/\/spreecommerce.org\/wp-content\/uploads\/2019\/01\/felix-mbp-300x300.png 300w, https:\/\/spreecommerce.org\/wp-content\/uploads\/2019\/01\/felix-mbp-100x100.png 100w\" sizes=\"(max-width: 570px) 100vw, 570px\" \/><\/figure>\n","protected":false},"excerpt":{"rendered":"<p>EasyPost&nbsp;was founded in 2012 as the first RESTful API for shipping. The company has thousands of customers shipping millions of packages each month. It allows users to buy postage labels, check rates, verify an address, track their shipments, and more with all of the major shipping companies, including&nbsp;USPS,&nbsp;UPS,&nbsp;DHL, and FedEx.The benefits of using EasyPost for [&hellip;]<\/p>\n","protected":false},"featured_media":0,"template":"","meta":{"_acf_changed":true,"_seopress_robots_primary_cat":"","_seopress_titles_title":"","_seopress_titles_desc":"","_seopress_robots_index":""},"cpt_integrations_category":[988],"class_list":["post-11143","cpt_integrations","type-cpt_integrations","status-publish","hentry","cpt_integrations_category-shipping"],"acf":[],"_links":{"self":[{"href":"https:\/\/spreecommerce.org\/wp-json\/wp\/v2\/cpt_integrations\/11143","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/spreecommerce.org\/wp-json\/wp\/v2\/cpt_integrations"}],"about":[{"href":"https:\/\/spreecommerce.org\/wp-json\/wp\/v2\/types\/cpt_integrations"}],"wp:attachment":[{"href":"https:\/\/spreecommerce.org\/wp-json\/wp\/v2\/media?parent=11143"}],"wp:term":[{"taxonomy":"cpt_integrations_category","embeddable":true,"href":"https:\/\/spreecommerce.org\/wp-json\/wp\/v2\/cpt_integrations_category?post=11143"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}