Support from Acquia helps fund testing for Drupal Acquia logo

Comments

Perignon created an issue. See original summary.

Perignon’s picture

Tested this patch and it works correctly with the API library and inserts subscribers with the interest group attached to their profile.

ruscoe’s picture

Status: Reviewed & tested by the community » Postponed (maintainer needs more info)
FileSize
153.06 KB

I may need some information on how to reproduce the issue. It looks like this patch would change code that's already working.

I've attached a screenshot showing the structure of the interests array in a debugger. The nested foreach exists because each interest ID / status is nested under the interest group ID.

Perignon’s picture

I want to compare what you are doing to what I am doing. Can you give me your input to the function mailchimp_subscribe_process()?

Perignon’s picture

Typed up a response and lost it.

I think one issue here is structure of the data the mailchimp module wants. You guys are processing and taking the interest data very differently than the new API documents it. You guys are using an array with group ID's with the interest ID's under them, the API documentation doesn't show it that way and hence why you guys are doing a double nested foreach statement.

I wrote my code working off of the API documentation which only talks about the interest ID's. So one of two things I think needs to happen. You either documentation the data structure the module wants or use the data structure the API uses.

But I also think there is a bug here. The properties of the object key's must be boolean. The data you show in your screenshot is invalid for the API, I tested it using PAW against the API with tech support on chat while they watched my API calls.

Here is a valid call to the API:

{
    "email_address": "person@domain.com",
    "status_if_new": "subscribed",
    "interests": {
        "914f2a603e": true,
        "4d0221bbff": false,
        "2a791dc6c8": true
    },
    "merge_fields": {
        "LNAME": "Smith"
    }
}
ruscoe’s picture

I've attached the input of mailchimp_subscribe_process() and the structure of interest data that is sent to the API. This all happens inside mailchimp_subscribe_process().

Our subscription forms group interests by interest group, which is how the submitted data ends up in this format. We then convert it to the format the API expects.

Perignon’s picture

Status: Postponed (maintainer needs more info) » Active

So I guess if you guys want to stay with this data structure it just needs to be documented because it conflicts with the v3 API documentation from Mailchimp.

My last $0.02 would be, the group data is not necessary and is thrown away in this nested foreach so I would say there is an argument for changing this. It is an extra step and extra processing for no reason.

tomdisher’s picture

I'm also confused by this one.

I was building some functionality to programmatically enroll users in interest groups. I assumed the $interests array I should pass to the mailchimp_subscribe would be something like:

"interests": {
        "914f2a603e": true,
        "4d0221bbff": false,
        "2a791dc6c8": true
}

This is pretty much exactly what you get from looking up a user's info with mailchimp_get_memberinfo().

What does mailchimp_subscribe expect as input in the $interests array? I can't find the documentation anywhere.

Perignon’s picture

Correct, it is not documented. Just like I stated in #7, it needs to be either documented or changed to coincide with the rest of the code and with the API.

As the module is currently written you have to pass a double nested array.

"interests": {
        "123123123": {
            "914f2a603e": true,
            "4d0221bbff": false,
            "2a791dc6c8": true
         }
}

Where "123123123" is the group ID number that is not used at all so you can just fill that with a random string of numbers. If you use my patch, it eliminates this and you use a simple array of interest IDs like you stated in #8.

tomdisher’s picture

My last $0.02 would be, the group data is not necessary and is thrown away in this nested foreach so I would say there is an argument for changing this. It is an extra step and extra processing for no reason.

I'd have to agree with Perignon - if we're throwing away the group data the module should probably just eliminate it. In the meantime I guess the solution is to generate a random number that mailchimp_subscribe_process can ignore.

Perignon’s picture

Thinkshout, What is the status of this issue?

Can we change this to reflect the official MailChimp documentation? The group ID is not needed nor required by Mailchimp V3 API.

ruscoe’s picture

Assigned: Unassigned » ruscoe
ruscoe’s picture

I'm in the process of making this change now. The change is a good idea, it just needs a bit more work on top of altering how mailchimp_subscribe_process() processes interest groups. The code that's currently passing interest data to that function also needs to be updated.

Perignon’s picture

If you want help, I will be glad to do it.

  • ruscoe committed 2dfd234 on 7.x-4.x
    Issue #2767865 by Perignon: Double nested array processing for Interests...
ruscoe’s picture

@Perignon I wasn't able to use your patch, but this commit should give you what you need.

The MailChimp module still splits interests into interest groups because we show interests that way on subscription forms / fields, but there was no need for us to parse that inside mailchimp_subscribe_process(). I've moved that code into the form submit handler.

You can now pass interests as an array like this:

[
  '914f2a603e' => TRUE,
  '4d0221bbff' => FALSE,
]

Does that work for your use case?

Perignon’s picture

Cool thanks!!!

Also, check out the PR I did on Github for the function mailchimp_subscribe_process() returning something on error.

I had a DB full of email addresses that could not be submitted but my code was not failing. I found the reason was because even on error, nothing gets returned from the aforementioned function.

ruscoe’s picture

Assigned: ruscoe » Unassigned
Status: Active » Fixed

GitHub PR merged!

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.