Note: Many APIs are available from eBay. However, the eBay Java SDK supports only the Trading API. |
In order to make an SDK call to the Trading Service at an eBay site, your application first instantiate ApiContext, which is a singleton: all SDK calls to eBay during your application session use the same Apicontext instance. Your application then sets at least two properties on that ApiContext object:
After ApiContext is created and its properties set, you instantiate the SDK call wrapper you want to use, for example, AddItemCall if you want to list (AddItem) an item on eBay. Supply any needed input data, send the request, and handle the response:
Each eBay Java SDK program needs to import the following classes:
In order to use the SDK classes, you need to import these classes:
The following code sample shows the bare minimum of code needed to send a call to eBay.
The following code is adapted from the helloWorld sample located in the SDK subdirectory $JSDK/samples/helloWorld. This code gets the current eBay time at the US site and displays it in a console window.
public class ApplicationHelloWorld { public static void main(String[] args) { try { // Instantiate ApiContext and initialize with token and Trading API URL ApiContext apiContext = getApiContext(); //Create call object and execute the call GeteBayOfficialTimeCall apiCall = new GeteBayOfficialTimeCall(apiContext); Calendar cal = apiCall.geteBayOfficialTime(); //Handle the result returned System.out.println("Official eBay Time : " + cal.getTime().toString()); } //try catch(Exception e) { System.out.println("Fail to get eBay official time."); e.printStackTrace(); } } // main // Initializes ApiContext with token and eBay API server URL private static ApiContext getApiContext() throws IOException { String input; ApiContext apiContext = new ApiContext(); //set Api Token to access eBay Api Server ApiCredential cred = apiContext.getApiCredential(); input = ConsoleUtil.readString("Enter your eBay Authentication Token: "); cred.seteBayToken(input); //set Api Server Url input = ConsoleUtil.readString("Enter eBay SOAP server URL (e.g., https://api.ebay.com/wsapi): "); apiContext.setApiServerUrl(input); return apiContext; } //getApiContext } //ApplicationHelloWorld
In the sample code, notice that the call wrapper class's constructor typically expects one parameter, the ApiContext object. Notice also that the user (authorization) token and the API server URL are both supplied from console input for the sake of simplicity only. For a discussion on authorization tokens and how to handle tokens in multi-user applications see Handling Authorization in Your Application.
Finally, notice that you execute an API call by calling the call wrapper's execute method. The execute method's name is typically the same as the call's name, but in accord with Java naming conventions, it begins with a lower case letter.
All SDK requests must be sent to either the eBay Sandbox or Production API Gateway. This authenticated service uses secure endpoints. Notice that these are the SOAP endpoints because the Trading Service uses SOAP.
Sandbox Gateway URL (endpoint):
https://api.sandbox.ebay.com/wsapi
Production Gateway URL (endpoint):
https://api.ebay.com/wsapi
The SDK automatically supplies required HTTP headers and URL parameters.
The SDK is prebuilt to use the WSDL version indicated in the SDK release. However, in rare cases, advanced eBay developers may wish to update the SDK kernel to the latest WSDL.
If you must update the SDK kernel to a more recent WSDL, you can download WSDLs from https://developer.ebay.com/webservices/Version/ebaySvc.wsdl, where Version is replaced by the version number of the WSDL release to be downloaded, for example, https://developer.ebay.com/webservices/687/ebaySvc.wsdl.
The latest released WSDL version can always be found at https://developer.ebay.com/webservices/latest/ebaySvc.wsdl.
You use the sandbox environment to test your application. The sandbox supports all Trading API calls unless stated otherwise in the Trading API documentation. For more information about the Sandbox testing environment, see Testing Applications.
© 2008–2010 eBay Inc. All rights reserved.
eBay and the eBay logo are registered trademarks of eBay Inc.
All other brands are the property of their respective owners.