Search code examples
jsonapi-designmailchimp-api-v3.0

MailChimp and SquareSpace API integration


I need to integrate two APIs (SquareSpace and MailChimp) - take information from the first and input it into the latter. The two APIs don't have support for each other, and I know I need to create a custom solution formatted in JSON.

When the user makes a purchase on a SquareSpace website, I need to know what they have purchased and then subscribe them to a mailing list tagging them with the name of their purchase.

I have Linux and Windows servers available to work with. I can use either PHP or Node to write my code, but would prefer PHP as I'm more comfortable with it.

The SquareSpace Commerce API notes can be found at: https://developers.squarespace.com/commerce-api

The MailChimp API notes can be found here: http://developer.mailchimp.com/documentation/mailchimp/reference/overview/

Is this possible?


Solution

  • Introduction

    The SquareSpace docs are not particularly comprehensive, but usually there is an HTTP trigger (sometimes known as a callback) that gets called at certain event points (e.g. product purchase). This is hinted at here:

    Using the data we provide access to through our API, you can:

    • Connect to a third-party fulfillment or shipping application

    You will need to look in your SquareSpace control panel to see if any such thing exists. If it does, you can get SquareSpace to notify you when purchase events occur. Services like PayPal do this.

    Design suggestions

    If it does not, you could instead operate your code on a scheduler, and periodically check for new orders, using the Orders API. Essentially you need to sync the information in the SquareSpace database with a local database, so you can then push that to MailChimp. Since it is not important to get the information into MailChimp quickly, you could do this every 15 minutes or so.

    For customer privacy, I suggest you only sync the bare minimum information, such as order number, product code, first name and email address. If you are not familiar with API programming, and suffer a security breach as a result, then your customers will rightly not be happy with you - so be careful, and get your work security-checked if you can. I would also suggest that you delete your sync information when it is successfully pushed to MailChimp.

    To sync, the only information you need to permanently store is the "last updated time". When you then do the next sync, you can ignore any orders older than that, since you will already have pushed them.

    You will need to check for MailChimp push failures though, e.g. data validation problems. That data will still need to be stored in your intermediate server so you can manually repair the data, which should sync on the next push.

    API calls

    To make an API call, you can use PHP's curl module. There is an example here and many more here. I recommend trying this on your development machine to see if you can make a successful orders request to SquareSpace.