Tap Forms – Organizer Database App for Mac, iPhone, and iPad › Forums › Script Talk › Suggestions for working with Mailchimp API?
- This topic has 21 replies, 5 voices, and was last updated 3 years, 11 months ago by Sam Moffatt.
-
AuthorPosts
-
November 10, 2020 at 11:06 AM #42548
Paul WirthParticipantHi folks,
I have a Tap Forms database where I track client info. Clients are also in my Mailchimp email list. I’d like to be able to have my Tap Forms database update itself with any changes (unsubscribes, new subscribers, email address changes, etc) on Mailchimp, and vice versa using their API.
If anyone’s done this already, or something similar, I’d be grateful for any pointers. I have a beginner-level acquaintance with javascript—mostly in the sense that I am sometimes able to tweak existing scripts to do what I want. I’m not at all familiar with working with an API, however.
Grateful for any help!
November 10, 2020 at 12:18 PM #42552
Daniel LeuParticipantLooking at the API example:
curl -sS \ "https://${dc}.api.mailchimp.com/3.0/ping" \ --user "<code>anystring</code>:${apikey}"
I don’t think Tap Forms can work with the Mailchimp API as user authentication is not supported with the current Tap Forms Javascript API :(
November 10, 2020 at 1:11 PM #42554
Paul WirthParticipantThanks for looking into it! That’s too bad. Do you have any idea if it’s planned?
November 10, 2020 at 3:06 PM #42557
Daniel LeuParticipantThanks for looking into it! That’s too bad. Do you have any idea if it’s planned?
That’s a question for @brendan.
November 11, 2020 at 8:56 PM #42566
Sam MoffattParticipantOne of the workarounds I have for this is to leverage the built-in Apache web server and PHP which then handles the connections. It also makes it a little easier to work and debug because I can develop outside of Tap Forms and when I’m done, hook into Tap Forms. It gives me a lot more flexibility in coding as well because I have an entire PHP ecosystem to leverage. This allows hybrid functionality. It only really works on my own network or computer (depending on how I’ve done the scripts) but if that fits your use case it’s a great way to be able to handle more functionality in making web requests.
November 21, 2020 at 12:54 PM #42682
Paul WirthParticipantThanks Sam, and sorry for the delayed reply. My mac was in the shop for a week. Can you point me to a resource that would help me understand how to set something like that up? I’m somewhat familiar with using the built-in Apache for web development (using local Nginx now, however).
November 22, 2020 at 3:50 PM #42694
Sam MoffattParticipantIf you’re already doing local web development, just modify your scripts to call http://localhost in Tap Forms and call out to your local environment. Then you can use the scripting language of your choice in that environment to call in with the extra headers to the other APIs.
November 22, 2020 at 7:46 PM #42695
Paul WirthParticipantOk, thanks, that gives me a starting place. I was also in touch with Brendan, who seems to be interested in implementing authorization in Tap Forms.
November 22, 2020 at 9:35 PM #42698
BrendanKeymasterI’ve been working on this (as a side project to the big project).
Since I already have a Campaign Monitor account, I found they have a REST API too:
function Fetch_From_Campaign_Monitor() { var api_key = 'my-campaign-monitor-api-key:x'; var api_key_encoded = Utils.encodeBase64String(api_key); console.log(api_key_encoded); var response = Utils.getJsonFromUrlWithHeaders('https://api.createsend.com/api/v3.2/clients.json?pretty=true', {"Authorization" : "Basic " + api_key_encoded}); return response[0]; } Fetch_From_Campaign_Monitor();
Seems to work. I had to add the
Utils.encodeBase64String()
function because I couldn’t find a way to do that with JavaScriptCore.November 22, 2020 at 11:49 PM #42700
BrendanKeymasterHey Paul,
Interested in becoming a Tap Forms beta tester?
I’ve implemented the above feature, but not in the latest build submitted to Apple for review or posted on my website. The update after that will have the above feature.
Thanks,
Brendan
November 23, 2020 at 7:42 PM #42708
Paul WirthParticipantSure, Brendan, I’d love to test it, and thanks for implementing it so quickly!
November 23, 2020 at 10:19 PM #42712
Sam MoffattParticipantIs the headers intended to be a dictionary of user provided headers? Is there any validation on the keys?
November 24, 2020 at 1:21 AM #42714
BrendanKeymasterYes, a dictionary and nope, no validation. You do what you want with it.
The object and keys in the provided dictionary are added to the existing headers which already has the
Content-Type : application/json
key/value added to it.November 25, 2020 at 3:11 PM #42722
Paul WirthParticipantThank you so much, Brendan, for getting this feature started so quickly! Adapting your example, and after some messing around with the Mailchimp API docs and
curl
, I came up with the following:function Fetch_From_Mailchimp() { var server_prefix = 'server-prefix'; // log in to mailchimp; the base url will be something like 'us19.admin.mailchimp.com'. in that example, 'us19' is the server prefix var api_key = 'mailchimp-api'; var list_id = 'id-of-audience-list' var response = Utils.getJsonFromUrlWithHeaders('https://' + server_prefix + '.api.mailchimp.com/3.0/lists/' + list_id + '/members?fields=members.id&count=10&offset=0', {"authorization" : "Basic " + api_key}); return response; } Fetch_From_Mailchimp();
This returns a list of the first 10 member id’s from the given list id.
Next I’ll need to work on parsing member info through the API and updating the Tap Forms list. I’m a beginner with javascript, so that’ll be a learning project.
November 25, 2020 at 6:24 PM #42723
BrendanKeymasterExcellent Paul!
Did you not have to base64 encode the api_key? I did with Campaign Monitor.
November 25, 2020 at 6:29 PM #42724
Paul WirthParticipantNope, the key only worked when it was not encoded.
December 23, 2020 at 10:39 AM #42959
ThomasParticipantHi Folks – I just tried the Utils.getJsonFromUrlWithHeaders() and it works great for me (MacOS fresh download and install from Website).
But I am missing a counterpart with basic authentication support for addPhotoFromUrlToField().
I tried addPhotoFromUrlToFieldWithHeaders() but that does not seem to exist.Will something like that be provided? Would be nice to not have to work around using a local web server to redirect the authenticated REST calls that fetch image content.
Thanks for the help!
January 11, 2021 at 7:44 PM #43161
BrendanKeymasterHi Thomas,
Thanks for the suggestion. That’s a good idea to add
Utils. addPhotoFromUrlToFieldWithHeaders()
.Thanks,
Brendan
January 13, 2021 at 11:01 AM #43167
ThomasParticipantThanks Brendan for the reply.
I don’t want to get greedy but since we are talking about REST calls:
Read/Fetch use cases are OK to implement with the current functionality (especially once a Utils. addPhotoFromUrlToFieldWithHeaders() will be available :-) ).But syncing status back from Tap Forms to an external source via REST is not effectively possible today. Support for PUT and POST and PATCH (with authentication/headers of course) is missing. Are there any plans to add something like that to Utils?
January 17, 2021 at 9:39 AM #43201
Sam MoffattParticipantFor the moment that’s why I suggest using a bridge, MacOS ships with Apache and PHP out of the box that can be relatively easily enabled and Homebrew can be used to upgrade versions if that doesn’t work. PHP gives you access to it’s APIs for making HTTP requests as well as the ability to use libcurl to make requests for anything more complicated. Obviously if PHP isn’t your thing there are other options for building a web server that provides a bridge between TF and the services you need to interact with. For myself I have a bunch of PHP scripts that handle this using curl to add in extra headers or options that TF doesn’t permit some even provide a caching layer to avoid redundant requests.
In the long run I think if there were a JSC implementation of Fetch that could be added that’d be great but I don’t see anything. I feel leveraging an existing spec makes sense because it provides a framework of what needs to be built and a suggestion for an API. The closest I found was a gist with some code in it but far from a full implementation.
January 17, 2021 at 11:06 AM #43206
ThomasParticipantThanks for the reply.
I do use a PHP bridge running locally on my Mac right now. To work around the missing addPhotoFromUrlToFieldWithHeaders() and the missing PUT/POST/PATCH.
But to me it does not feel right to have two units of maintenance with two place where code is, written in two languages and having to remember to start up two things before a sync (a server process in addition to the app) and maintaining access credentials in two places. All for a bit of functionality that is commodity these days.
My PHP code in the bridge is only a handful of lines of code. But to me that is not an argument for it but against it. For something so trivial I should not have to run a seperate server.
January 17, 2021 at 3:00 PM #43213
Sam MoffattParticipantI agree it’d be great if it was in TF directly, however it’s unfortunately on one person to build the requisite library to implement it all and doing a full blown mapping of a HTTP client is a non-trivial amount of work. That’s why I went out looking for if someone else using JSC had done it and I couldn’t find anything.
-
AuthorPosts
You must be logged in to reply to this topic.