Sending email via API
I'm trying to use the send email API call - https://app.swaggerhub.com/apis-docs/WildApricot/wild-apricot_public_api/2.1.0#/Emailing.Operations/SendEmail but not having any luck.
I've tried from the API browser and via a Google Apps script. In both, I just get a 400 error.
I'm POSTing to https://api.wildapricot.org/v2.1/rpc/<ACCOUNT>/email/sendemail, with this as my body:
{
"Subject": "test email",
"Body": "test email",
"Recipients": [
{
"Id": 0,
"Type": "IndividualRecipient",
"Name": "test",
"Email": "<HIDDEN>"
}
],
"EventId": <EVENTID>
}
(account, email and event id have been hidden). Each time, I get a 400 error: Parameter is required: EmailDraftParam.
The swagger documentation doesn't mention a "EmailDraftParam". What am I doing wrong?
-
Robin Sapiro commented
Problem resolved - amazing what a good night's sleep and my morning espresso can do.
In HTML string copied from an original email sent from WA, converted all " to ', %20 to just a space and then added in the macros by just typing in {macroname}.
I can even embed my site banner and any other images stored in WA in the email.
I am now a happy camper and only need to determine the Saved Search ID so that I can send to a specified set of recipients
-
Robin Sapiro commented
Successfully sending an email with the API from the https://api.wildapricot.org/ui/home/RequestOAuthToken page.
Works great when my Body is just plain text.
However SwaggerHub documentation for the SendEmail parameters says that this can be HTML and include macros (see attached screenshot).
However all attempts to include HTML result in error message: invalid JSON: Unexpected token in JSON at position NN.
Is there any sample code available that would show how to insert the HTML code?
Additionally - how would a macro be included - or is it as simple as typing in {macroname} inside the text or HTML. -
Mark commented
That worked, thanks!
-
Mark, your first request is almost correct, you need only to delete a comma after "EventAttendees_All"
-
Mark commented
Thanks for this info! This helps me understand how this API call works.
In this case, I want the second option - sending email to everyone registered for an event, and not the wait list. (we're sending a post-event feedback email, and manually sending it each time)
Unfortunately, I still don't quite have the body right. Using event 1000 as an example, I've tried
{
"Subject": "test email",
"Body": "test email",
"Recipients": [
{
"Type": "EventAttendees_All",
}
],
"EventId": 1000
}and
{
"Subject": "test email",
"Body": "test email",
"Type": "EventAttendees_All",
"EventId": 1000
}But still getting a 400. What should I be sending instead?
-
If you want to send email to individual recipient, then you have to provide valid contact id (id:0 is not a valid contact id) and don't need to provide eventId.
If you want to send email to event-related recipients, then Type should be set to one of EventAttendees_All, EventAttendees_Selected, EventWaitlist_All, EventWaitlist_Selected.