Updating a subscriber

superlever

New Member
So I figured out how to subscribe via the API. But now I want to update via the API, but it doesn't seem to work with the code I have (see below).

I can't store the user ID, but the email address should be the unique key. It's just updating the subscriber using the email address.

This is more or less my subscribe code, but I hoped that changing create to update would magically work. It doesn't. :)

Thanks for your help.

PHP:
<?php
// sub.php file
require_once dirname(__FILE__) . '/setup.php';
$listUid = 'xxxxxxx';// you'll take this from your customers area, in list overview from the address bar.
$email = getCleanParam('email', FILTER_VALIDATE_EMAIL, null);
if (!$email) {
    exit;
}
$fname = getCleanParam('fname');
$lname = getCleanParam('lname');
$username = getCleanParam('username');
$os = getCleanParam('os');
$gender = getCleanParam('gender');
$cntry = getCleanParam('country');
$usertype = getCleanParam('usertype');
$socialconnected = getCleanParam('socialconnected');
$interestsadded = getCleanParam('interestsadded');
$endpoint = new MailWizzApi_Endpoint_ListSubscribers();
$response = $endpoint->update($listUid, array(
    'EMAIL' => $email,
    'FNAME' => $fname,
    'LNAME' => $lname,
    'USERNAME' => $username,
    'OS' => $os,
    'GENDER' => $gender,
    'CNTRY' => $cntry,
    'USERTYPE' => $usertype,
    'SOCIALCONNECTED' => $socialconnected,
    'INTERESTSADDED' => $interestsadded,
));
function getCleanParam($param, $filter=FILTER_SANITIZE_STRING, $default="")
{
    $out = isset($_GET[$param]) && filter_var($_GET[$param], $filter) ? $_GET[$param] : $default;
    return $out;
}
 
Thanks! The createUpdate part fixed it.

I have one extra question.

How do I just update one parameter (using the email as the connector/primary key) without clearing the other parameters from the user record?

Thanks!
 
How do I just update one parameter (using the email as the connector/primary key) without clearing the other parameters from the user record?
Through the api ? As far as i am aware of, if you do not send the other fields, they won't be updated.
 
No they get deleted.

So that call:

PHP:
<?php
// sub.php file
require_once dirname(__FILE__) . '/setup.php';
$listUid = 'xxxxxx';// you'll take this from your customers area, in list overview from the address bar.
$email = getCleanParam('email', FILTER_VALIDATE_EMAIL, null);
if (!$email) {
    exit;
}
$username = getCleanParam('username');
$displayname = getCleanParam('displayname');
$os = getCleanParam('os');
$gender = getCleanParam('gender');
$cntry = getCleanParam('cntry');
$usertype = getCleanParam('usertype');
$socialconnected = getCleanParam('socialconnected');
$instagram = getCleanParam('instagram');
$twitter = getCleanParam('twitter');
$spotify = getCleanParam('spotify');
$connectionrequested = getCleanParam('connectionrequested');
$connectionmade = getCleanParam('connectionmade');
$haschatted = getCleanParam('haschatted');
$interestsadded = getCleanParam('interestsadded');
$endpoint = new MailWizzApi_Endpoint_ListSubscribers();
$response = $endpoint->createUpdate($listUid, array(
    'EMAIL' => $email,
    'USERNAME' => $username,
    'DISPLAYNAME' => $username,
    'OS' => $os,
    'GENDER' => $gender,
    'CNTRY' => $cntry,
    'USERTYPE' => $usertype,
    'SOCIALCONNECTED' => $socialconnected,
    'INSTAGRAM' => $instagram,
    'TWITTER' => $twitter,
    'SPOTIFY' => $spotify,
    'CONNECTIONREQUESTED' => $connectionrequested,
    'CONNECTIONMADE' => $connectionmade,
    'HASCHATTED' => $haschatted,
    'INTERESTSADDED' => $interestsadded,
));
function getCleanParam($param, $filter=FILTER_SANITIZE_STRING, $default="") 
{
    $out = isset($_GET[$param]) && filter_var($_GET[$param], $filter) ? $_GET[$param] : $default;
    return $out;
}

If I just did say one or two of them, it would update the whole profile to have just one or two. Instead of leaving the others alone.

Thanks
 
@superlever - i thing you should do something like this:
PHP:
<?php

<?php
// sub.php file
require_once dirname(__FILE__) . '/setup.php';
$listUid = 'xxxxxx';// you'll take this from your customers area, in list overview from the address bar.
$email = getCleanParam('email', FILTER_VALIDATE_EMAIL, null);
if (!$email) {
    exit;
}
$username = getCleanParam('username');
$displayname = getCleanParam('displayname');
$os = getCleanParam('os');
$gender = getCleanParam('gender');
$cntry = getCleanParam('cntry');
$usertype = getCleanParam('usertype');
$socialconnected = getCleanParam('socialconnected');
$instagram = getCleanParam('instagram');
$twitter = getCleanParam('twitter');
$spotify = getCleanParam('spotify');
$connectionrequested = getCleanParam('connectionrequested');
$connectionmade = getCleanParam('connectionmade');
$haschatted = getCleanParam('haschatted');
$interestsadded = getCleanParam('interestsadded');
$endpoint = new MailWizzApi_Endpoint_ListSubscribers();
$fields = array(
    'EMAIL' => $email,
    'USERNAME' => $username,
    'DISPLAYNAME' => $username,
    'OS' => $os,
    'GENDER' => $gender,
    'CNTRY' => $cntry,
    'USERTYPE' => $usertype,
    'SOCIALCONNECTED' => $socialconnected,
    'INSTAGRAM' => $instagram,
    'TWITTER' => $twitter,
    'SPOTIFY' => $spotify,
    'CONNECTIONREQUESTED' => $connectionrequested,
    'CONNECTIONMADE' => $connectionmade,
    'HASCHATTED' => $haschatted,
    'INTERESTSADDED' => $interestsadded,
);
foreach ( $fields as $name => $value ) {
    if ( empty($value) ) {
        unset($fields[$name]);
    }
}
$response = $endpoint->createUpdate($listUid, $fields);
function getCleanParam($param, $filter=FILTER_SANITIZE_STRING, $default="") 
{
    $out = isset($_GET[$param]) && filter_var($_GET[$param], $filter) ? $_GET[$param] : $default;
    return $out;
}
basically this means you don't send the field at all if it has no value.
 
It works! :)

You're awesome. Thanks so much. I really appreciate it.

You've saved me losing a day trying to get this to work.
 
Back
Top