I am migrating from MailChimp to CiviCRM with Sparkhost (seemingly a great option for installations on Bluehost or other hosts which don't support VERP.)
I have a few places where the MailChimp API is used to add contacts to our email list. I am having trouble figuring out how to replace these with similar calls to CiviCRM, to trigger a double opt-in confirmation email.
I created a simple profile to collect email and a newsletter group signup field. This works for situations where I can embed this form into a page. But I can't duplicate this behavior for situations where I need to trigger the subscription programatically.
If I use the CiviCRM API to call 'Profile' 'submit', it seems to ignore the profile setting to "Update the matching contact" and just creates duplicate contacts with the same email address. It also sets the status to 'Added (by API)' rather than sending an email confirmation.
If I use the API to call 'GroupContact' 'create', I can't get it to send a confirmation email. With no status set, it just adds the contact. With status of 'pending' set, it marks the contact as 'Pending (API)' without sending the confirmation email.
It looks like I could do something like:
Look up whether the email exists yet, with 'Email' 'get'.
If any results, check the contact associated with each result to make sure it's not deleted.
If more than 1 valid result, take a best guess at which contact to use.
If 0 valid results, create the contact and create the associated email record.
Call 'MailingEventSubscribe' 'create' to trigger the double opt-in process.
This is doable, but the initial steps seem to be reinventing the wheel. Am I missing something to make this simpler? Thanks!