Use API to get custom field into a PHP variable

007

Member
Hello all,

I'm struggling to use the PHP API to get the value from a custom field of a subscriber into a PHP variable.

Here is what I'm trying to do (the question marks are where I need guidance. See code notes for my intentions):
PHP:
$listUid    = '1234';
$endpoint   = new MailWizzApi_Endpoint_ListSubscribers();

    // get subscriber's existing id, using the value from a form submission, and add the id to the subscriber_id variable
    $response = $endpoint->emailSearch($listUid, $_POST['EMAIL']);
    $subscriber_id = ???

    // use the id from above to get the subscriber's custom field value, and add it to the subscriber_custom_field_value variable
    $response = $endpoint->getSubscriber($listUid, $subscriber_id);
    $subscriber_custom_field_value = ???

Does anyone have some ideas that could help?

Thanks!
 
@007 - use
PHP:
var_dump( $response->body );
To see what data you got back from the api call, then you can access the data in the $response->body array like
PHP:
$response->body['whateverkey'];
 
Thanks twisted1919,

I was able to get it working by tweaking it a bit to access the second level of the array

PHP:
    // get subscriber's existing id
        $response = $endpoint->emailSearch($listUid, $subscriber_email);
        // get the second level array into a new variable
        $second_level_array = $response->body['data'];
        // get the key from the new variable
        $subscriber_uid = $second_level_array['subscriber_uid'];
 
Last edited:
Back
Top