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

Hi,

I'm trying to work out how I can use WWW::Mailchimp to sign someone up to our list, but also assign the language of the person. Here is what I have thus far:

  my $mailchimp = WWW::Mailchimp->new(apikey => 'xxxx' );
     $mailchimp->listSubscribe( id => "xxx", email_address => $in->{Email}, merge_vars => [ FNAME => $name[0],
                                                      LNAME => $name1, mc_language => "fr", LANG => "fr", LANGUAGE => "fr" ] );


While it works (and asks you to confirm), all the lang variables are ignored. Looking at their documents, I'm a bit confused as to what to use:

https://apidocs.mailchimp.com/api/2.0/lists/subscribe.php

The code "fr" is ok, but I'm unsure what params to pass along to it.

Has anyone had any experience with this before? Apart from the language, it works fine (but I need to be able to send the confirmation emails in their own language, and then also filter down when doing mailings)

Thanks!

Andy

As requested, I have also posted this on SO: http://stackoverflow.com/questions/32976195/adding-language-variable-into-wwwmailchimp-subscription/32976425#32976425
  • Comment on OT: WWW::Mailchimp - pass along the users language as well?

Replies are listed 'Best First'.
Re: OT: WWW::Mailchimp - pass along the users language as well?
by Corion (Patriarch) on Oct 06, 2015 at 21:15 UTC

    Have you asked MailChimp about their API and its use?

    What do you mean by "what params to pass along to it"?

    Have you read the link "Translate Content in a Campaign" linked from the page you linked to?

      Hi,

      For anyone else who may come across this, I have managed to get the v3.0 API going using Perl. Please see the example below:
          use WWW::Curl::Easy;
          use JSON;
          use Digest::MD5;
      
          my $apikey = 'xxxx-us6';
          my $listid = 'xxxx';
          my $email = 'andy@testr.co.uk';
          my $endpoint = "https://us6.api.mailchimp.com/3.0/lists";
      
          my $json = JSON::encode_json({
              'email_address' => $email,
              'status'        => 'pending',
              'merge_fields'  => {
                  'FNAME'     => "andy",
                  'LNAME'     => "newby"
              }
          });
      
          my $curl = WWW::Curl::Easy->new;
      
          my $url = "$endpoint/$listid/members/" . Digest::MD5::md5(lc($email));
      
          $curl->setopt(CURLOPT_HEADER,1);
          $curl->setopt(CURLOPT_URL, $url);
      
          $curl->setopt(CURLOPT_VERBOSE, 1);
          $curl->setopt(CURLOPT_USERPWD, 'user:' . $apikey);
          $curl->setopt(CURLOPT_HTTPHEADER, 'Content-Type: application/json');
          $curl->setopt(CURLOPT_TIMEOUT, 10);
          $curl->setopt(CURLOPT_CUSTOMREQUEST, 'PUT');
          $curl->setopt(CURLOPT_SSL_VERIFYPEER, 0);
          $curl->setopt(CURLOPT_POSTFIELDS, $json);
      
          # A filehandle, reference to a scalar or reference to a typeglob can be used here.
          my $response_body;
          $curl->setopt(CURLOPT_WRITEDATA,\$response_body);
      
          # Starts the actual request
          my $retcode = $curl->perform;
      
          # Looking at the results...
          if ($retcode == 0) {
                  print("Transfer went ok\n");
                  my $response_code = $curl->getinfo(CURLINFO_HTTP_CODE);
                  # judge result and next action based on $response_code
                  print "Received response: $response_body\n";
          } else {
                  # Error code, type of error, error message
                  print "An error happened: $retcode ".$curl->strerror($retcode)." ".$curl->errbuf."\n";
          }
      Hopefully that saves someone a bit of the grief I had trying to get it going :)

      Cheers

      Andy
Re: OT: WWW::Mailchimp - pass along the users language as well?
by stevieb (Canon) on Oct 06, 2015 at 17:49 UTC

    When you cross-post a question on multiple sites, it's considered polite to advise on all of them that you've done so, in order to reduce duplicate efforts.

    -stevieb

      Fair enough. Have updated the OP