How to get the attribute value from getLead Java | Community
Skip to main content
December 4, 2013
Solved

How to get the attribute value from getLead Java

  • December 4, 2013
  • 3 replies
  • 1271 views
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.
This post is no longer active and is closed to new replies. Need help? Start a new post to ask your question.
Best answer by
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());

}


 


3 replies

December 4, 2013
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/
Accepted solution
December 12, 2013
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());

}


 


December 18, 2013
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.


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