Re: SOAP into XML into PHP variable example?

Anonymous
Not applicable

SOAP into XML into PHP variable example?

On our website, I'm trying to use SOAP to get a cookied user's information and store it into a PHP array. Here's a simple ask that I'm having trouble coding out:

User has already filled out a form, is a known lead.
Record specific user's First Name and Last Name as PHP variables.

I imagine this would be pretty easy to code up, I just don't have enough experience with SOAP, XML, and turning that data into something I can work with in PHP. I saw the Java documentation, but that didn't really help me too much.

Can anyone help me out with some functional sample code? I learn best through example! I promise to reward the Community with a cool tool once I get this piece figured out.

Best,
Edward Unthank
Marketing Operations Specialist
Yesler
Tags (1)
4 REPLIES 4
Anonymous
Not applicable

Re: SOAP into XML into PHP variable example?

Edward- Take a look at the php code same for the getLead API at http://developers.marketo.com/documentation/soap/getlead/
Anonymous
Not applicable

Re: SOAP into XML into PHP variable example?

Thanks, Travis! That's been very helpful so far. I've established the connected on the dev server and can get the response by cookie.

Now I need to get at the FirstName attribute value. Is there a robust way to get this? The only thing I can think of is: 
echo $lead->result->leadRecordList->leadRecord->leadAttributeList->attribute[9]->attrValue;

But just choosing the a specific index for "attribute" scares me in case anything changes, where fields are added or deleted.

(Sorry for asking basic questions—I'm teaching myself along the way, and general online searching can't answer all my questions.)


Best,
Edward Unthank
Anonymous
Not applicable

Re: SOAP into XML into PHP variable example?

Hey Edward,

I'm not 100% familiar with php but these resources might point you in the right direction in manipulating your data.

http://stackoverflow.com/questions/2583572/php-how-to-store-xml-data-in-an-array

http://stackoverflow.com/questions/4383914/how-to-get-single-value-from-php-array

I
'm currently using python to work with Marketo API. Sorry I couldn't be of further assistance.

Tell Anika and the Yesler gang Ish from PAPL says hello 🙂
Anonymous
Not applicable

Re: SOAP into XML into PHP variable example?

Thanks, Ish! I'll tell them. 🙂 It was a bit more complicated than that, but I figured it out eventually:

// A function to return the value requested
function returnAttr ($query, $array, $default="blank"){
  $i = -1;
  foreach ( $array as $attribute )
  { 
   $i++;
 
 if ($array[$i]->attrName == $query){
  return $array[$i]->attrValue;
  exit;
 }
  }
  return $default; // optional value if the one for which you're searching is blank
}
 
echo returnAttr("FirstName", $leadAttributes);

In case anyone else comes across the same need in the future.


Edward Unthank
Marketing Operations Specialist
Yesler