Beefy Boxes and Bandwidth Generously Provided by pair Networks
Clear questions and runnable code
get the best and fastest answer
 
PerlMonks  

Mail:Chimp3 Updating Groups/Interests

by JEWebDes (Novice)
on Jan 30, 2020 at 23:40 UTC ( [id://11112147]=perlquestion: print w/replies, xml ) Need Help??

JEWebDes has asked for the wisdom of the Perl Monks concerning the following question:

According to the MailChimp API, it should be easy to update a subscribers groups/interests, but that's not been my experience. In my code below, the subscriber is not added to the Group with groupid1, but is removed from the Group with groupid2. Why wasn't the subscriber added to Group groupid1? Makes no sense.

my %groups = ( 'GroupID1' => true, 'GroupID2' => false ); $email_address = lc('member_email'); $subscriber_hash = md5_hex( $email_address ); my $response = $mailchimp->update_member ( list_id => 'listid', subscriber_hash => $subscriber_hash, interests => \%groups );

Replies are listed 'Best First'.
Re: Mail:Chimp3 Updating Groups/Interests
by tangent (Parson) on Jan 31, 2020 at 01:52 UTC
    It looks like you are not using 'use strict' in your script, if you did you would get errors as 'true' and 'false' have no special meaning in Perl:
    use strict; use warnings; my %groups = ( 'GroupID1' => true, 'GroupID2' => false );
    Errors:
    Bareword "true" not allowed while "strict subs" in use Bareword "false" not allowed while "strict subs" in use
    Your hash will be turned into a JSON structure before it is sent to MailChimp, and the way to represent JSON true and false in a Perl hash is:
    my %groups = ( 'GroupID1' => \1, 'GroupID2' => \0 );
    Maybe try that and see.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://11112147]
Front-paged by Corion
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others cooling their heels in the Monastery: (4)
As of 2024-04-20 00:55 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found