Output subscriber details not as an array using PHP wrapper

I would like to display user details, each field as a separate parameter and not an array.

I use the PHP sample code from the CM library

$wrap = new CS_REST_Subscribers($ListAll, $ApiKey);    
$result = $wrap->get('test@test.com');
if($result->was_successful()) { var_dump($result); }

The output is just standard array.

This is what I need:

$name = $result->Name;
$email = $result->EmailAddress;
$Customfield1 = $result ->Customfield1;
and so on ...

Can you tell me how the code should look like ?

The user will come to the landing page, I will pass parameters through URL and then I want to display formular with predefined fields, that is I need to have every single value from the array.

Thanks

tobyb tobyb, 5 years ago

Hey tomasz,

The PHP samples are written to allow you to quickly determine the structure of the returned objects. The result returned from the API call is an instance of CS_REST_Wrapper_Result while the response is the deserialised JSON response. In the samples we use var_dump to show the available properties of the response object, these properties may be accessed just like a normal object member, as you have suggested e.g.

$name = $result->response->Name
$email = $result->response->EmailAddress

For more information about working with objects and arrays, take a look at the PHP manual, specifically here and here.

tomasz, 5 years ago

Super, this is what I need. thanks ;-)

tomasz, 5 years ago

Hey again,

actually it doesn't work with custom fields. I got Undefined index: Phone (this is one of my custom fields) ....

Any suggestions please?

tomasz, 5 years ago

Finally got it ;-)

print_r($result->response->CustomFields[1]->Value);

Thanks for the really solid support guys (David and Toby) ;-)

Mitch, 5 years ago

Hello there

This thread got me half-way—I'm using this $result->response->CustomFields to get to the custom fields—but the x in CustomFields[x] keeps changing because there's a multi-value custom field above it.

The number is always six less than the 10 here:

array(10) {
  [0]=>
...

So maybe there's some trick with math, but otherwise I don't know how to get to the specific custom field I'm after.

Thanks in advance!

PDD2010, 4 weeks ago

This is quite useful:

print_r($result->response->CustomFields[1]->Value);

But what I would like to do is this:



print_r($result->response->CustomFields[Key='name-of-key']->Value);

How to do this ?

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