-1

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?

Whirlwind
  • 1
  • 3
  • Please read [Under what circumstances may I add “urgent” or other similar phrases to my question, in order to obtain faster answers?](//meta.stackoverflow.com/q/326569) - the summary is that this is not an ideal way to address volunteers, and is probably counterproductive to obtaining answers. Please refrain from adding this to your questions. – halfer Mar 07 '18 at 13:47
  • I have already read it as I wanted to understand why you kept editing my posts. My stating that it was urgent to me was *not* to try and elicit a faster response from anyone who might help. It was to explain my current level frustration. If my question seems lacking in detail, it is because I am stressing out about what I am trying to do. This is the first question I have ever asked on Stack Overflow. It was my attempt at asking whoever might help to be patient with me. – Whirlwind Mar 07 '18 at 13:57
  • I have given an answer below that is as far as I can get with the information currently on offer. I'll add in another link in my answer for your research. We don't write step-by-step tutorials here, and if someone were to do so, they would likely bump into a technical restriction that would render their solution unworkable (and thus would have wasted their time). – halfer Mar 07 '18 at 14:00

2 Answers2

1

Steps:

  1. Pick a language that you know. If you don't know any language, you will have to learn one like JS, Python etc.
  2. Learn how to make HTTP requests. Try several things : GET request type, POST request with JSON body, PUT request with JSON body.
  3. Learn how to parse JSON
  4. Consume one service, parse its json to make it input for other service and make http call to that other service.
halfer
  • 19,824
  • 17
  • 99
  • 186
Sikorski
  • 2,653
  • 3
  • 25
  • 46
0

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.

halfer
  • 19,824
  • 17
  • 99
  • 186
  • **Thank you so much! THIS is what I was trying to get at!** I didn't know how to start the script from the SquareSpace end. I didn't realise that I just couldn't. What I can do is set it to run on the hour every hour on my end and check for new purchases and update the mailchimp list that way. – Whirlwind Mar 07 '18 at 14:10
  • You are welcome, @Whirlwind. I am not certain that SquareSpace does not have callbacks, but yes, a scheduler/cron seems like it would fit your use-case. – halfer Mar 07 '18 at 14:11
  • @Whirlwind: I've added a note about sync push failures too. It's worth planning your system out on paper _before coding_ so you can ensure it will do everything you need it to. – halfer Mar 07 '18 at 14:14
  • Pseudo coding as we speak... so to speak – Whirlwind Mar 07 '18 at 14:18