SOLVED

How to get the attribute value from getLead Java

Go to solution
Anonymous
Not applicable

How to get the attribute value from getLead Java

Background: I am trying to get lead information from Marketo API and insert/update them into SQL server.
I used the getLead sample code. The challenge is that the API gives me back the lead as an JAXBElement. I want to get the attribute value of that JAXBElement.
For example: I want to get the first name value of a lead, say Jack, as a String, and store it as a Java varible so I can put them though to SQL server using JDBC.

JAXBContext context = JAXBContext.newInstance(SuccessGetLead.class);
                        Marshaller m = context.createMarshaller() ;
                        
                        m.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true);
                        //m.marshal(result, System.out);
                        
                        DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
                        dbf.setNamespaceAware(true);
                        DocumentBuilder db = dbf.newDocumentBuilder() ;
                        Document doc = db.newDocument() ;
                        m.marshal(r, doc);
                        
                        //System.out.println(doc.hasAttributes()) ;

                        m.marshal(r, System.out);

The bold part I was trying to marshall the JAXBElement to a Node. But unfornately the node "doc" i have got didn't have anything in it whatsoever.
Any other approaches? Any help?
Thanks a lot.
Tags (1)
1 ACCEPTED SOLUTION

Accepted Solutions
Anonymous
Not applicable

Re: How to get the attribute value from getLead Java

Hi Jack - If you are using the sample code that Breno referred to, you can extract values like this:

You'll want to add null checks as appropriate, but this will print out the email addres of the lead record you requested.

SuccessGetLead result = port.getLead(request, header);

 

JAXBContext context = JAXBContext.newInstance(SuccessGetLead.class);

Marshaller m = context.createMarshaller();

m.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true);

m.marshal(result, System.out);


// Add null checks as appropriate

List<LeadRecord> leadRecordList = result.getResult().getLeadRecordList().getValue().getLeadRecords();

for(int x=0; x < leadRecordList.size(); x++) {

LeadRecord lr = leadRecordList.get(x);

System.out.println("Email: " + lr.getEmail().getValue());

}


 


View solution in original post

3 REPLIES 3
Anonymous
Not applicable

Re: How to get the attribute value from getLead Java

If that sample code from the Community? If so I would suggest the new and updated documentation. I used the Java implentation for a while.
http://developers.marketo.com/documentation/soap/getlead/
Anonymous
Not applicable

Re: How to get the attribute value from getLead Java

Hi Jack - If you are using the sample code that Breno referred to, you can extract values like this:

You'll want to add null checks as appropriate, but this will print out the email addres of the lead record you requested.

SuccessGetLead result = port.getLead(request, header);

 

JAXBContext context = JAXBContext.newInstance(SuccessGetLead.class);

Marshaller m = context.createMarshaller();

m.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true);

m.marshal(result, System.out);


// Add null checks as appropriate

List<LeadRecord> leadRecordList = result.getResult().getLeadRecordList().getValue().getLeadRecords();

for(int x=0; x < leadRecordList.size(); x++) {

LeadRecord lr = leadRecordList.get(x);

System.out.println("Email: " + lr.getEmail().getValue());

}


 


Anonymous
Not applicable

Re: How to get the attribute value from getLead Java

Hi  Travis
Your answers is exactly what I want. Exactly!!!
I was hoping to get your email address to ask you some more specific questions about Java Marketo API, but coundt find it.

Here is another problem.

when using syncLead,
I'd like to add a Timestamp(datetime from SQL) attribute to my lead, DoB for example, but the attribute type is always String, and the value can only be a string.
Can I change it to Timestamp/Datetime or there is another approach.
Thanks a lot.
0EM50000000RJrA.jpg

Also, could you tell me where can I find the full documatation of the API for Java. Class map, methods summary so on so forth.
Cheers