Skip to main content
Published: October 12 2006, 2:43:00 PMUpdated: November 28 2020, 2:52:33 PM

 Using Java SDK framework to execute your first API Call


   This sample illustrates on how to use eBay Java SDK framework to execute the GeteBayOfficialTime call.   For using this sample you must have:
   1. got your sandbox keys that include three IDs (DevID, AppID, and CertID) and API Token.
   2. obtained and installed the eBay Java SDK package.

  Attached to this article is a zipped project implementing the GeteBayOfficialTime code.

Detailed Description 

   Creating a standalone eBay Project named eBayApiRequest, which consists the file structure as below.   
       1. Java Source files
       2. Build, batch and properties files
       3. Plug your own devid, appid, cert, and token into the file.

       NOTE. This sample has been tested against the sandbox API service

   Add Java Source Code
   Now you need to write the java code as below or you can download the project package. 
   GeteBayOfficialTime is the simplest eBay api call that has no call-specific inputs. If the call succeeds and it returns the official eBay system time in GMT. However; please keep in mind that when you print the time out, the time will be displayed in a local time.

   Each call to the eBay SOAP API must specify and register a set of the required properties into ApiContext object to pass to the HTTP header,
   In the example, the devid, appid, cert,  token and apiServer properties are stored in the config file and are read into the helper class for populating ApiCredential and ApiContext object.
   The api executing, api retrying and logging setting up are all done in the class.

package ebayapi;

import com.ebay.sdk.*;
import com.ebay.soap.eBLBaseComponents.*;
import com.ebay.sdk.util.eBayUtil;
import com.ebay.sdk.helper.ConsoleUtil;
import java.util.*;  

public class AppGeteBayTime {
          private String configFile= "";
          private ApiContext _apiContext;
          private ApiCall _apiCall;

                    RequestHeaderParam requestHeaderParam = new  RequestHeaderParam();
                   _apiContext = requestHeaderParam.createContext(configFile);
                   _apiCall  = new com.ebay.sdk.ApiCall(_apiContext);
                    //Enable logging
                   ApiLogging logging = new ApiLogging();

          //Main method
          public static void main(String[] args) {
                 AppGeteBayTime thisapp = new AppGeteBayTime();

                 GeteBayOfficialTimeCall request = new GeteBayOfficialTimeCall(thisapp._apiContext);
                // Retry
                CallRetry callretry = new CallRetry();

                org.apache.axis.types.Token [] apiErrorCodes =  new org.apache.axis.types.Token[]{
                         new org.apache.axis.types.Token("502"),

                java.lang.Class[] tcs = new java.lang.Class[]{
              try {
                    // execute the request and assign the returned eBay time to the Calendar object 
                   Calendar currenttime = request.geteBayOfficialTime();
                   String rightnow = currenttime.getTime().toString();
             }catch (Exception e) {}
} //END OF AppGeteBayTime () class

package ebayapi;

import com.ebay.sdk.*;
import com.ebay.soap.eBLBaseComponents.*;
import java.util.Properties;

public class RequestHeaderParam {

        public ApiContext createContext(String file){

      // Load the properties file into a Properties object
       Properties config = new Properties();
       try {
              config.load(new FileInputStream(file));
        } catch (IOException e) {
                System.out.println(" file is missing from the current working directory.");
                return null;
// Create ApiContext object
       ApiContext context = new ApiContext();
// add ApiCredential to ApiContext
       ApiCredential credential= context.getApiCredential();

       // Register Token property
       credential.seteBayToken(config.getProperty("token") );
// register the ApiServerUrl in ApiContext
// define the SiteCodeType to US that the request is routed to siteID=0
       // tell eBay api server returning the error message in English


}// END OF RequestHeaderParam() class

Compiling and executing the project

Compile :
 ant -f build.xml


The Executing result
- Sending SOAP request to:
- HTTP Compression: send gzip request...
- HTTP Compression - gzip decompress response: ContentLength=320
- Request Message: Length=1,575
- <?xml version="1.0" encoding="UTF-8"?>
<soapenv:Envelope xmlns:soapenv="" xmln
s:xsd="" xmlns:xsi="
  <ebl:RequesterCredentials soapenv:mustUnderstand="0" xmlns:ebl="urn:ebay:apis:
   <ebl:eBayAuthToken xmlns:ebl="urn:ebay:apis:eBLBaseComponents">AXXX</ebl:eBayAuthToken>
  <GeteBayOfficialTimeRequest xmlns="urn:ebay:apis:eBLBaseComponents">
- Response Message: Length=528
- <?xml version="1.0" encoding="UTF-8"?>
<soapenv:Envelope xmlns:soapenv="" xmln
s:xsd="" xmlns:xsi="
  <GeteBayOfficialTimeResponse xmlns="urn:ebay:apis:eBLBaseComponents">

Version Info

The code example above was based on the versions specified below:

API Schema Version 549
Java SDK Version javasdk v549.0 Full release

Additional Resource 

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