forked from exobin/go-mailchimp
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathautomation.go
More file actions
44 lines (36 loc) · 1.19 KB
/
automation.go
File metadata and controls
44 lines (36 loc) · 1.19 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
package gochimp
import (
"fmt"
"io/ioutil"
)
// EnqueueEmail will enqueue the given email address to the emailID trigger of the configured workflow.
func (c *Client) EnqueueEmail(workflowID string, emailID string, email string) error {
params := struct {
Email string `json:"email_address"`
}{email}
resp, err := c.do("POST", fmt.Sprintf("/automations/%s/emails/%s/queue", workflowID, emailID), ¶ms)
if err != nil {
return err
}
defer resp.Body.Close()
// Allow any success status (2xx)
if resp.StatusCode/100 == 2 {
return nil
}
// Read the response body
data, err := ioutil.ReadAll(resp.Body)
if err != nil {
return err
}
// Request failed
errorResponse, err := extractError(data)
if err != nil {
return err
}
// Dang. We should be able to match this based on the "Type", but …
// {"type":"http://developer.mailchimp.com/documentation/mailchimp/guides/error-glossary/","title":"Bad Request","status":400,"detail":"You\u2019ve already sent this email to the subscriber.","instance":""}
if errorResponse.Status == 400 && errorResponse.Detail == ErrThisMailAlreadySentToThisSubscriber.Error() {
return ErrThisMailAlreadySentToThisSubscriber
}
return errorResponse
}