For full functionality of this site it is necessary to enable JavaScript.
Here are the instructions how to enable JavaScript in your web browser.

Knowledge base

Find the answer to your question

Advanced Search PView

Search terms
Search Type
Sort by

What are the best ways to get our API credentials and tokens used in Java with SOAP and the SDK?

  • Answer ID 221
  • Published 12/07/2004 03:44 PM
  • Updated 10/20/2013 06:41 AM
  • Permalink
In the Soap help there is a code snippet for java which is as follows

private void createTokenHeader(SOAPHeader envHeader) throws Exception {
SOAPElement heSecurity = envHeader.addChildElement("RequesterCredentials",
"api", "urn:ebay:api:eBayAPI");
SOAPElement userNameToken = heSecurity.addChildElement("Credentials","ebl");
userNameToken.addChildElement("AppId", "ebl").addTextNode("YourAppId");
userNameToken.addChildElement("DevId", "ebl").addTextNode("YourDevId");
userNameToken.addChildElement("AuthCert", "ebl").addTextNode("YourCertId");

I would like to know how is the envHeader which is an object of SOAPHeader being created.I am trying to execute getItem() using Soap.
A complete code snippet would be of great help

For the SDK, you need to use an ApiContext object to handle everything. This is by far the easiest method:

ApiContext apiContext = new ApiContext();
ApiCredential cred = apiContext.getApiCredential();
ApiAccount ac = cred.getApiAccount();
eBayAccount ec = cred.geteBayAccount();

ac.setDeveloper("<Your DevId Here>");
ac.setApplication("<Your AppId Here>");
ac.setCertificate("<Your CertId Here>");

cred.seteBayToken("<Your user token here>");

The above is cut-n-paste from a simple test app that I use regularly for troubleshooting individual calls. This code snippet (with actual values filled in of course) stays the same and I just create a quick call object for whatever call I'm troubleshooting.

With SOAP the issue is a little more complicated and the method of setting up the security headers has changed from when the intro documentation was written.

What I use is a function like this:

private static void setupAPIInterface(String baseURL,
String callName,
int siteId,
int version) {
ClientCredentialHandler.setDevId("<Your DevId Here>");
ClientCredentialHandler.setAppId("<Your AppId Here>");
ClientCredentialHandler.setAuthCert("<Your CertId Here>");
ClientCredentialHandler.setToken("<Your User Token Here>");

try {
String requestURL = baseURL +
"?callname=" + callName +
"&siteid=" + siteId +
"&appid=" + ClientCredentialHandler.getAppId() +
"&version=" + version;
binding = new EBayAPIInterfaceServiceLocator().geteBayAPI(new URL(requestURL));
((EBayAPISoapBindingStub) binding).setTimeout(60000);
catch (Exception e) {
System.err.println("Error locating eBay API Interface: " + e);

to set up for making calls. The URL needs to be changed whenever you change the type of call you are making. The binding object is of type EBayAPIInterface and is the object you make the call against. The ClientCredentialHandler class is a custom SOAP header class that takes care of the custom headers. You'll need this class and a replacement client_config.wsdd (both are attached) to successfully make SOAP calls.
File Attachments

How well did this answer your question?

Answers others found helpful

Print Email This Page Delicious Digg Facebook Reddit StumbleUpon Twitter