Suggestions for working with Mailchimp API?

Tap Forms – Organizer Database App for Mac, iPhone, and iPad Forums Script Talk Suggestions for working with Mailchimp API?

Viewing 17 reply threads
  • Author
    Posts
  • November 10, 2020 at 11:06 AM #42548

    Paul Wirth
    Participant

    Hi 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 Leu
    Participant

    Looking 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 Wirth
    Participant

    Thanks 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 Leu
    Participant

    Thanks 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 Moffatt
    Participant

    One 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 Wirth
    Participant

    Thanks 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 Moffatt
    Participant

    If 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 Wirth
    Participant

    Ok, 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

    Brendan
    Keymaster

    I’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.

    • This reply was modified 1 month, 3 weeks ago by Brendan.
    • This reply was modified 1 month, 3 weeks ago by Brendan.
    November 22, 2020 at 11:49 PM #42700

    Brendan
    Keymaster

    Hey 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 Wirth
    Participant

    Sure, Brendan, I’d love to test it, and thanks for implementing it so quickly!

    November 23, 2020 at 10:19 PM #42712

    Sam Moffatt
    Participant

    Is 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

    Brendan
    Keymaster

    Yes, 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 Wirth
    Participant

    Thank 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

    Brendan
    Keymaster

    Excellent 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 Wirth
    Participant

    Nope, the key only worked when it was not encoded.

    December 23, 2020 at 10:39 AM #42959

    Thomas
    Participant

    Hi 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

    Brendan
    Keymaster

    Hi Thomas,

    Thanks for the suggestion. That’s a good idea to add Utils. addPhotoFromUrlToFieldWithHeaders().

    Thanks,

    Brendan

    January 13, 2021 at 11:01 AM #43167

    Thomas
    Participant

    Thanks 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?

Viewing 17 reply threads

You must be logged in to reply to this topic.