Importing multiple subscribers via API issues

I am new to API development and attempting to utilize it in order to integrate Campaign Monitor with my website member registration (I'm using a flat CMS that doesn't have plugins for this sort of thing).

Subscribers will be added to a list with an auto-responder. I want to make sure that if they were deleted or unsubscribed from it in the past, it will still add them—they are paying for a membership and may have unsubscribed from marketing emails in the past (this is a separate list from marketing).

I thought all I would have to do is to add the following at the tail end of the import() call:

            'Resubscribe' => true,
            'QueueSubscriptionBasedAutoResponders' => true,
            'RestartSubscriptionBasedAutoresponders' => true

But when I do that, it throws a syntax error and the documentation on this (https://www.campaignmonitor.com/api/subscribers/#importing_many_subscribers) is not clear on how to add these into import() vs. add()

Here's what I've got:

$result = $wrap->import(array(
                array(
                    'EmailAddress' => $email,
                    'Name' => $fname.' '.$lname,
                    'CustomFields' => array(
                        array(
                            'Key' => 'Track',
                            'Value' => $track
                        ),
                        array(
                            'Key' => 'Buddy',
                            'Value' => $buddyemail
                        )
                    )
                ),
                array(
                    'EmailAddress' =>  $buddyemail,
                    'Name' => $buddyfname.' '.$buddylname,
                    'CustomFields' => array(
                        array(
                            'Key' => 'Track',
                            'Value' => $track
                        ),
                        array(
                            'Key' => 'Buddy',
                            'Value' => $email
                        )
                    )
                )
            ), 
            'Resubscribe' => true,
            'QueueSubscriptionBasedAutoResponders' => true,
            'RestartSubscriptionBasedAutoresponders' => true);
Mercer, 11 months ago

Hi there Erin,

Thanks so much for this great question! It looks like your syntax is just a bit off. You can see this by comparing the Add request (https://github.com/campaignmonitor/createsend-php/blob/master/samples/subscriber/add.php) to the Import request (https://github.com/campaignmonitor/createsend-php/blob/master/samples/subscriber/import.php) in our PHP samples.

It looks like you have closed out the array without including those options in it first. Please make sure that you are matching up your closing and opening parens.

Thanks!

erinanacker, 11 months ago

Hi Mercer,

Thanks so much for the reply!

So I understand what you mean, but I'm still missing something... Maybe we could use the sample as an example.

Here's the original:

$result = $wrap->import(array(
    array(
        'EmailAddress' => 'Subscriber email',
        'Name' => 'Subscriber name',
        'CustomFields' => array(
            array(
                'Key' => 'Field 1 Key',
                'Value' => 'Field Value'
            ),
            array(
                'Key' => 'Field 2 Key',
                'Value' => 'Field Value'
            ),
            array(
                'Key' => 'Multi Option Field 1',
                'Value' => 'Option 1'
            ),
            array(
                'Key' => 'Multi Option Field 1',
                'Value' => 'Option 2'
            )
            )
    ),
    array(
        'EmailAddress' => '2nd Subscriber email',
        'Name' => '2nd Subscriber name',
        'CustomFields' => array(
            array(
                'Key' => 'Field 1 Key',
                'Value' => 'Field Value'
            ),
            array(
                'Key' => 'Field 2 Key',
                'Value' => 'Field Value'
            ),
            array(
                'Key' => 'Multi Option Field 1',
                'Value' => 'Option 1'
            ),
            array(
                'Key' => 'Multi Option Field 1',
                'Value' => 'Option 2'
            )
        )
    )
), false);

The "false" at the end is for the resubscribe param, yes? I've tried changing that to true and adding "true, true, true" to set all three of those params but it did not work.

I'm not sure what I'm missing!

erinanacker, 11 months ago

Actually, this is (kind of) working—if both subscribers are unsubscribed, it only resubscribes the second one.

            $result = $wrap->import(array(
                array(
                    'EmailAddress' => $email,
                    'Name' => $fname.' '.$lname,
                    'CustomFields' => array(
                        array(
                            'Key' => 'Track',
                            'Value' => $track
                        ),
                        array(
                            'Key' => 'Buddy',
                            'Value' => $buddyemail
                        )
                    )
                ),
                array(
                    'EmailAddress' =>  $buddyemail,
                    'Name' => $buddyfname.' '.$buddylname,
                    'CustomFields' => array(
                        array(
                            'Key' => 'Track',
                            'Value' => $track
                        ),
                        array(
                            'Key' => 'Buddy',
                            'Value' => $email
                        )
                    )
                )
            ), true, true, true);
Mercer, 11 months ago

Hi there!

Could you try explicitly stating the parameters? I've built the code out below:

$result = $wrap->import(array(
    array(
        'EmailAddress' => $email,
        'Name' => $fname.' '.$lname,
        'CustomFields' => array(
            array(
                'Key' => 'Track',
                'Value' => $track
            ),
            array(
                'Key' => 'Buddy',
                'Value' => $buddyemail
            )
            )
    ),
    array(
        'EmailAddress' => $buddyemail,
        'Name' => $buddyfname.' '.$buddylname,
        'CustomFields' => array(
            array(
                'Key' => 'Track',
                'Value' => $track
            ),
            array(
                'Key' => 'Buddy',
                'Value' => $email
            )
        )
    )
),
'Resubscribe' => true,
'QueueSubscriptionBasedAutoResponders' => true,
'RestartSubscriptionBasedAutoresponders => true
);

erinanacker, 11 months ago

When I do that, I get this: Parse error: syntax error, unexpected '=>' (T_DOUBLE_ARROW)

Mercer, 11 months ago

Hi Erin,

It was because I neglected to use a single quote in the very last parameter like you can see here: http://cm.d.pr/14AaO/1Vy2lS6m. If you add that quote, it should work as expected.

erinanacker, 11 months ago

I caught that beforehand and still got the syntax error

erinanacker, 11 months ago

Okay—I *thought* I figured it out. In the sample, it has that "), false);" —

$result = $wrap->import(array(
    array(
        'EmailAddress' => 'Subscriber email',
        'Name' => 'Subscriber name',
        'CustomFields' => array(
            array(
                'Key' => 'Field 1 Key',
                'Value' => 'Field Value'
            ),
            array(
                'Key' => 'Field 2 Key',
                'Value' => 'Field Value'
            ),
            array(
                'Key' => 'Multi Option Field 1',
                'Value' => 'Option 1'
            ),
            array(
                'Key' => 'Multi Option Field 1',
                'Value' => 'Option 2'
            )
            )
    ),
    array(
        'EmailAddress' => '2nd Subscriber email',
        'Name' => '2nd Subscriber name',
        'CustomFields' => array(
            array(
                'Key' => 'Field 1 Key',
                'Value' => 'Field Value'
            ),
            array(
                'Key' => 'Field 2 Key',
                'Value' => 'Field Value'
            ),
            array(
                'Key' => 'Multi Option Field 1',
                'Value' => 'Option 1'
            ),
            array(
                'Key' => 'Multi Option Field 1',
                'Value' => 'Option 2'
            )
        )
    ),
    'Resubscribe' => true,
    'QueueSubscriptionBasedAutoResponders' => true,
    'RestartSubscriptionBasedAutoresponders' => true
), false);

So I assumed that was where we'd be passing the params BUT it's not. I don't actually know what that false refers to...

Instead, I put them inside the parenthesis before to test... No dice. Still did not work, though it no longer throws an error.

$result = $wrap->import(array(
    array(
        'EmailAddress' => 'Subscriber email',
        'Name' => 'Subscriber name',
        'CustomFields' => array(
            array(
                'Key' => 'Field 1 Key',
                'Value' => 'Field Value'
            ),
            array(
                'Key' => 'Field 2 Key',
                'Value' => 'Field Value'
            ),
            array(
                'Key' => 'Multi Option Field 1',
                'Value' => 'Option 1'
            ),
            array(
                'Key' => 'Multi Option Field 1',
                'Value' => 'Option 2'
            )
            )
    ),
    array(
        'EmailAddress' => '2nd Subscriber email',
        'Name' => '2nd Subscriber name',
        'CustomFields' => array(
            array(
                'Key' => 'Field 1 Key',
                'Value' => 'Field Value'
            ),
            array(
                'Key' => 'Field 2 Key',
                'Value' => 'Field Value'
            ),
            array(
                'Key' => 'Multi Option Field 1',
                'Value' => 'Option 1'
            ),
            array(
                'Key' => 'Multi Option Field 1',
                'Value' => 'Option 2'
            )
        )
    ),
    'Resubscribe' => true,
    'QueueSubscriptionBasedAutoResponders' => true,
    'RestartSubscriptionBasedAutoresponders' => true
), false);
terryt terryt, 10 months ago

Hi Erin,

I've had a look at the code and I've retried the following code:

$result = $wrap->import(
    array(
        array(
            'EmailAddress' => 'test1@test.com',
            'Name' => 'Subscriber name',
            'CustomFields' => array(
                array(
                    'Key' => 'Field 1 Key',
                    'Value' => 'Field Value'
                ),
                array(
                    'Key' => 'Field 2 Key',
                    'Value' => 'Field Value'
                ),
                array(
                    'Key' => 'Multi Option Field 1',
                    'Value' => 'Option 1'
                ),
                array(
                    'Key' => 'Multi Option Field 1',
                    'Value' => 'Option 2'
                )
            )
        ),
        array(
            'EmailAddress' => 'test2@test.com',
            'Name' => '2nd Subscriber name',
            'CustomFields' => array(
                array(
                    'Key' => 'Field 1 Key',
                    'Value' => 'Field Value'
                ),
                array(
                    'Key' => 'Field 2 Key',
                    'Value' => 'Field Value'
                ),
                array(
                    'Key' => 'Multi Option Field 1',
                    'Value' => 'Option 1'
                ),
                array(
                    'Key' => 'Multi Option Field 1',
                    'Value' => 'Option 2'
                )
            )
        ),
        
    ), 
    true,
    true,
    true
);

This seems to work for me, even if both subscribers are unsubscribed or deleted. If you're still having trouble with the code not subscribing everyone it should would you mind dropping us an email support@campaignmonitor.com? Mention this forum post and mention you'd like to speak directly with Terry Tice. This way I can dig deeper into your API logs and see what the issue might be from there.

Let me know if you have any questions!

Cheers,
Terry Tice


Terry Tice
Campaign Monitor
erinanacker, 10 months ago

Yay! That worked Terry! Thank you so much.

I'm not sure what was happening, as I thought I had tried that as well without success. Strange but glad it's resolved.

Join 200,000 companies around the world that use Campaign Monitor to run email marketing campaigns that deliver results for their business.

Get started for free
1-888-533-8098