Forgive me as I'm new to all of this (including go)...
I've been trying to do:
mailchimpConnection := gochimp3.New(mailchimpAPIKey)
mailchimpMembers, err := mailchimpConnection.NewListResponse("XXXXXX").GetMembers(
&gochimp3.MemberQueryParams{
ExtendedQueryParams: gochimp3.ExtendedQueryParams{
BasicQueryParams: gochimp3.BasicQueryParams{
Fields: []string{"total_items,members.id,members.location"}, // Return less data
},
Count: 3,
},
Location: &gochimp3.MemberLocation{
CountryCode: "US",
},
},
)
if err != nil {
fmt.Println("Failed to get list...")
os.Exit(1)
}
//// Total US Beta Requestors
fmt.Printf("Total US Beta Requestors: %d\n", mailchimpMembers.TotalItems)
This kind of works... I get three replies:
{
"total_items": 53555,
"_links": null,
"list_id": "",
"members": [
{
"email_address": "",
"status": "",
"language": "",
"vip": false,
"location": {
"latitude": 0,
"longitude": 0,
"gmtoff": 0,
"dstoff": 0,
"timezone": "",
"country_code": "US"
},
"id": "cbf746b69e309c90552499690c45b6c3",
"list_id": "",
"unique_email_id": "",
"email_type": "",
"stats": {
"avg_open_rate": 0,
"avg_click_rate": 0
},
"member_rating": 0,
"last_changed": "",
"email_client": "",
"last_note": {
"note_id": 0,
"created_at": "",
"created_by": "",
"note": ""
}
},
{
"email_address": "",
"status": "",
"language": "",
"vip": false,
"location": {
"latitude": 0,
"longitude": 0,
"gmtoff": 0,
"dstoff": 0,
"timezone": "",
"country_code": "US"
},
"id": "e3dc49211a2ed16d3a7e4950dbefd145",
"list_id": "",
"unique_email_id": "",
"email_type": "",
"stats": {
"avg_open_rate": 0,
"avg_click_rate": 0
},
"member_rating": 0,
"last_changed": "",
"email_client": "",
"last_note": {
"note_id": 0,
"created_at": "",
"created_by": "",
"note": ""
}
},
{
"email_address": "",
"status": "",
"language": "",
"vip": false,
"location": {
"latitude": 0,
"longitude": 0,
"gmtoff": 0,
"dstoff": 0,
"timezone": "",
"country_code": "AR"
},
"id": "9d370d0f280f60805ec59d37f767d7c2",
"list_id": "",
"unique_email_id": "",
"email_type": "",
"stats": {
"avg_open_rate": 0,
"avg_click_rate": 0
},
"member_rating": 0,
"last_changed": "",
"email_client": "",
"last_note": {
"note_id": 0,
"created_at": "",
"created_by": "",
"note": ""
}
}
]
}
Total US Beta Requestors: 53555
Now, Location params isn't supported currently (as far as I can tell), so I've added them to the members.go:
type MemberQueryParams struct {
ExtendedQueryParams
Location *MemberLocation `json:"location,omitempty"`
Type string `json:"type"`
}
// Params MemberQueryParams
func (q MemberQueryParams) Params() map[string]string {
m := q.ExtendedQueryParams.Params()
m["location"] = fmt.Sprintf("%v", q.Location)
m["type"] = q.Type
return m
}
. . .
func (list ListResponse) GetMembers(params *MemberQueryParams) (*ListOfMembers, error) {
if err := list.CanMakeRequest(); err != nil {
return nil, err
}
endpoint := fmt.Sprintf(members_path, list.ID)
response := new(ListOfMembers)
err := list.api.Request("GET", endpoint, params, nil, response)
if err != nil {
return nil, err
}
for _, m := range response.Members {
m.api = list.api
}
prettyList1, err := json.MarshalIndent(response, "", " ")
if err != nil {
fmt.Println("Failed to json pretty list...")
os.Exit(1)
}
fmt.Printf("%s\n", string(prettyList1))
prettyList2, err := json.MarshalIndent(params, "", " ")
if err != nil {
fmt.Println("Failed to json pretty list...")
os.Exit(1)
}
fmt.Printf("%s\n", string(prettyList2))
return response, nil
}
{
"Status": "",
"SortField": "",
"SortDirection": "",
"Fields": [
"total_items,members.id,members.location.country_code"
],
"ExcludeFields": null,
"Count": 3,
"Offset": 0,
"location": {
"latitude": 0,
"longitude": 0,
"gmtoff": 0,
"dstoff": 0,
"timezone": "",
"country_code": "US"
},
"type": ""
}
Shouldn't this return only US country_code entries? Am I misunderstanding how all of this works?