Skip to main content
Published: December 07 2004, 4:44:00 PMUpdated: July 19 2022, 2:09:57 AM

   Question:

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");
heSecurity.addNamespaceDeclaration(
"ebl",
"urn:ebay:apis:eBLBaseComponents");
heSecurity.addChildElement("eBayAuthToken","ebl").addTextNode(theToken);
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

 

Answer:

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>");

apiContext.setApiServerUrl("https://api.ebay.com/wsapi");
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);
System.exit(1);
}
}

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.

 

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