Integrating Your Shopify Story With The Infusionsoft Via The API

One of the most powerful things about Infusionsoft is how easy it is to integrate with your existing business. A versatile marketing platform is going to play nicely with whatever you’re using to build your business.

Infusionsoft has fantastic ecommerce handling built in, but we know that many Infusionsoft customers are using third-party solutions for shopping carts. One of our favorites is Shopify, and we want to make it easy for Shopify store owners to get their customer data into Infusionsoft.

Besides the Infusionsoft suite, one of my favorite tools for the small business entrepreneur is Shopify. They make it easy to setup a full featured ecommerce platform that’s easy to use, SEO optimized, and deploys in just minutes. Their software makes it easy to sell products, and together with Infusionsoft they form a potent combination that makes it easy to both sell and market.

In this tutorial, we’ll be using the Shopify and Infusionsoft API’s to add customers from Shopify into our Infusionsoft marketing database. This allows us to send them follow up emails, collect feedback, and turn them from one time buyers into lifetime customers — all without having to do the heavy lifting of manual list building or transferring.

How Does This Work?

The Shopify API has “Webhooks.” When certain events happen, the Shopify API will take the data associated with that event and send it in a request to an external URL. So when someone checks out in your store, you can enable a Webhook that sends all the order information to the Infusionsoft API.

How Do We Set This Up?

First, we need to enable webhooks in Shopify. This is an easy process.

  1. Login to your account, select Preferences and then Notifications.
  2. From the bottom of that page, select “Add a webhook subscription.”
  3. For our purposes, we’ll ask for a JSON encoded object of the “Customer Creation” webhook.

    The downside to Webhooks is that the application you’re developing must be publicly accessible for Shopify to be able to send the data to it. In order to trouble shoot more effectively I recommend using http://PostCatcher.In They give you a throw away URL you can use to catch the output from Shopify. The JSON returned from Shopify is able to be assigned as a string in PHP, so you can work on your program’s logic without needing to constantly test with Shopify.

    The output is then displayed for you in a web based interface. Here’s a sample of the output:

     


    In the example code you’ll notice that I hard coded in the response so that I could work on the logic without having to fight with the API. When it’s time to move into production, just comment out the hard coded JSON.

 

Subtleties

  1. The Shopify API doesn’t send their data with the _POST variable. Instead, they send it in the request body. You’ll need to use PHP’s stream to access the data. In one line, we can get the data, and then JSON decode it.
  2. Shopify is persistent in that they’ll keep trying to deliver the information you want. Once you’ve gotten what you need, it’s courteous to send an HTTP 200 back to let them know all is right with the world.
  3. Since this is public facing, and inputs data into a database, you’ll want to make sure you’re checking that the sender is who they say they are. One way of doing this is including a _GET variable at the end of the URL like, http://youprodurl.com/shopify-ifs.php?key=456 and then checking for it’s existence before executing the code. Shopify also offers a header, “x-shopify-shop-domain” that includes the URL of your store.
  4. Since there is no output from the program, it can be difficult to trouble shoot problems. Using file_put_contents is a helpful way to get a sense of what’s happening. Additionally, if you have error logging enabled you might find some more information in error_log.
  5.  

     

    Shopify To Infusionsoft Webhook Handler