Home
Find the answer to your question
Retrieving Item Specific data with GetItem in JAVA SDK
Detail Description
Item Specific data is returned in GetItem response if DetailLevel is set to ItemReturnAttributes. Following code sample illustrates on how to retrieve sport ticket item's attributes. Before using the code, you need to find the event ticket's attributes (check the KB article Example and sample code for how to list with Item Specifics for details).
private void getItem() {
String itemId = "";
GetItemCall request = new GetItemCall(apiContext);
ItemIDType itemID = new ItemIDType(itemId);
request.setDetailLevel(new DetailLevelCodeType[]{
DetailLevelCodeType.ReturnAll,
DetailLevelCodeType.ItemReturnAttributes
});
request.setItemID(itemID);
ItemType itemReturned =null;
try {
itemReturned = request.getItem();
AttributeSetArrayType attrSetArrayType =itemReturned.getAttributeSetArray();
if (attrSetArrayType != null){
AttributeSetType[] attributes = attrSetArrayType.getAttributeSet();
for (int index=0; index<attributes.length; index++){
AttributeSetType theSet = attributes[index];
//check if it's an event ticket attributeSet
if (theSet.getAttributeSetID() ==1){
getTicketAttr(theSet,itemReturned);
}
}
}
}catch (Exception e) {
if( e instanceof SdkSoapException ){
SdkSoapException sdkExe = (SdkSoapException)e;
ErrorType errs = sdkExe.getErrorType();
System.out.println("SdkSoapException error code " +errs.getErrorCode()+ "error shot message" + errs.getShortMessage());
}
if (e instanceof ApiException ){
ApiException apiExe = (ApiException)e;
ErrorType[] errs = apiExe.getErrors();
for (int j=0; j<errs.length; j++){
System.out.println("ApiException error code " +errs[j].getErrorCode()+ "error shot message" + errs[j].getShortMessage());
}
}
}finally{}
}
/*
* obtain event ticket item specific data
*/
private void getTicketAttr(AttributeSetType attrSet,ItemType item ){
// create a TicketBean object for storing the attribute data
// or you can store data to a Collection
TicketBean ticket = new TicketBean();
ticket.setItemId(item.getItemID().getValue());
ticket.setStartPrice(item.getStartPrice().getValue());
AttributeType[] attrTypeArray = attrSet.getAttribute();
for(int attrIndex=0; attrIndex<attrTypeArray.length; attrIndex++){
AttributeType theAttr = attrTypeArray[attrIndex];
//<Attribute labelVisible='true' id='10399' > <Label><![CDATA[Row]]
if (theAttr.getAttributeID()== 10399){
ticket.setRow(theAttr.getValue(0).getValueLiteral());
}
//<Attribute labelVisible='true' id='10400' > <Label><![CDATA[Section]]>
if (theAttr.getAttributeID() ==10400){
ticket.setSection(theAttr.getValue(0).getValueLiteral());
}
//<Attribute labelVisible='true' IsRequired='true' id='1' > <Label><![CDATA[Number of Tickets]]>
if (theAttr.getAttributeID()==1){
ticket.setNumOfTicket(theAttr.getValue(0).getValueLiteral());
}
// <Attribute labelVisible='true' id='2' > <Label><![CDATA[Month]]>
if (theAttr.getAttributeID()==2){
ticket.setMonth(theAttr.getValue(0).getValueLiteral());
}
//<Attribute labelVisible='true' id='44812' parentAttrId='2' > <Label><![CDATA[Day]]>
if (theAttr.getAttributeID()==44812){
ticket.setDay(theAttr.getValue(0).getValueLiteral());
}
//<Attribute labelVisible='true' id='44811' > <Label><![CDATA[Year]]>
if (theAttr.getAttributeID()==44811){
ticket.setYear(theAttr.getValue(0).getValueLiteral());
}
//<Attribute labelVisible='true' id='63' parentAttrId='10' > <Label><![CDATA[Venue Name]]>
if (theAttr.getAttributeID()==63){
ticket.setVenueName(theAttr.getValue(0).getValueLiteral());
}
}
System.out.println("The itemId : "+ ticket.getItemId());
System.out.println("The ticket's ROW -> " + ticket.getRow());
System.out.println("The number of ticket -> " + ticket.getNumOfTicket());
System.out.println("The Venue Name: " +ticket.getVenueName());
System.out.println("The ticket is on " +ticket.getMonth()+" "+ticket.getDay()+", "+ticket.getYear());
System.out.println("The Item's start price : "+ticket.getStartPrice());
}
The code example above was based on the versions specified below:
API Schema Version | 477 |
Java SDK Version | javasdk v471.0 full release |