Skip to main content
Published: January 08 2007, 12:16:00 PMUpdated: July 29 2022, 1:19:50 PM

 how can I use GetMyMessageCall to get the messages in MyeBay

Detailed Description

 GetMyMessages does not have data filters for reducing the volume of the response so that we suggest you follow the GetMyMessages 'Controlling the Volume of the Response'  guide to control  the volume of  the response. The sample project below illustrates how  to use DetailLevel filter to accomplish the goal .

  1. Make GetMyMessages call with DetailLevelCodeType.ReturnHeaders to get  a complete list of alert and message headers with their corresponding alert ID and message ID values.

  2. If there are Alerts or Messages, make GetMyMessages call again with DetailLevelCodeType.ReturnMessages to retrieve specific alerts and specific messages. Keep in mind you can only specify ten AlertIDs and ten MessageIDs at a time.

  You need to include the attached RequestHeaderParam.java source file and the request_param.properties properties file in order to run this sample as a standalone application.

NOTE. This sample only retrieves Messages but by taking the retrieveMessages() function as a reference, you can easily add a functionality to obtain Alerts .

/*
© 2007-2013 eBay Inc., All Rights Reserved
Licensed under CDDL 1.0 - http://opensource.org/licenses/cddl1.php
*/

/*
 * AppGetMyMessage.java
 */

package ebay.dts;
import com.ebay.soap.eBLBaseComponents.*;
import com.ebay.sdk.*;
import com.ebay.sdk.call.*;

/** 
 */
public class AppGetMyMessage {
    private String configFile= "request_header_param.properties";
    private ApiContext apiContext;
    private boolean _isCore =true;
    private ApiCall _apiCall;


    /** Creates a new instance of AppGetMyMessage */
    public AppGetMyMessage() {
        RequestHeaderParam requestHeaderParam = new  RequestHeaderParam();
        apiContext = requestHeaderParam.createContext(configFile);
        apiContext.setErrorLanguage("en_US");
        //Enable logging
        ApiLogging logging = new ApiLogging();
        apiContext.setApiLogging(logging);
    }


    public static void main(String [] args){
        AppGetMyMessage agmm = new AppGetMyMessage();
        GetMyMessagesCall apiCall = new GetMyMessagesCall(agmm.apiContext);
        DetailLevelCodeType[] detailLevels = new DetailLevelCodeType[] {

       // Using DetailLevel.ReturnHeaders filter 
       // to get a complete list alert and message headers with their corresponding alert ID and message ID values.

            DetailLevelCodeType.ReturnHeaders,
        };
        apiCall.setDetailLevel(detailLevels);
        try{
            apiCall.getMyMessages();
           
            MyMessagesMessageType[] msgs= apiCall.getReturnedMyMessages();

            // If there are Messages
            if (msgs !=null){
                int page=1, totalPages=0;
                //  retrieve ten messages at a time ( a page)
                if (msgs.length%10 !=0 ){
                    totalPages = msgs.length/10 + 1;                 
                }else {
                    totalPages= msgs.length;
                } 
                  // make second GetMyMessages call 
   
                  agmm .retrieveMessages(apiCall,page,totalPages,msgs);
            }
           
        }catch (Exception e) {
            if ( e instanceof SdkSoapException ) {
                SdkSoapException sdkSoapExe = (SdkSoapException)e;
                ErrorType error = sdkSoapExe.getErrorType();
                System.out.println("error code: " +error.getErrorCode()+ ", error shot message :"
                        + error.getShortMessage());
            }
            if (e instanceof ApiException ){
                ApiException apiExe = (ApiException)e;
                ErrorType[] errs = apiExe.getErrors();
                for (int i=0; i<errs.length; i++){
                    ErrorType error = errs[i];
                    System.out.println("error code " +error.getErrorCode()+ "error shot message"
                            + error.getShortMessage());
                }
            }
        }
       
    }
   
   
    public void retrieveMessages(GetMyMessagesCall api, int page,int totalPages,MyMessagesMessageType[] msgs){
        MyMessagesMessageIDType[] msgIds =null;
        int  start =0, end =0;
       
        start = (page-1)*10;
        if (totalPages ==1 || page==totalPages) {
            end = msgs.length;
        } else end = (page*10) ;
        msgIds = new MyMessagesMessageIDType[end-start];
       
        for (int i=start; i<end; i++){
            if ( msgs[i] !=null){
                    for ( int j=0; j<(end-start); j++){
                    msgIds[j] =  msgs[i].getMessageID();        
                }
            }
        }
        DetailLevelCodeType[] detail = new DetailLevelCodeType[] {
            // retrieve specific ten alerts and ten specific messages at a time 
            //with DetailLevel.ReturnMessages

            DetailLevelCodeType.ReturnMessages,
        }; 
        api.setDetailLevel(detail);
        api.setMessageIDs(msgIds);
        try{
            api.getMyMessages();

            // make another GetMyMessage call when there are more than ten messages
            if (page<totalPages){
                retrieveMessages(api, ++page,totalPages,msgs);
            }
        }catch (Exception e) { }
    }
   
}

 

Additional Resource

 

How well did this answer your question?
Answers others found helpful

Got thoughts? Click the feedback button – your insights help us improve!