0

I want to use the eBay-API to get my sold items. Here is my code:

ApiContext apiContext = new ApiContext();
ApiCredential credential = apiContext.getApiCredential();
ApiAccount acc = new ApiAccount();
acc.setApplication("app-id");
acc.setDeveloper("dev-id");
acc.setCertificate("cert");
eBayAccount eBayAccount = new eBayAccount();
eBayAccount.setPassword("ebay user");
eBayAccount.setUsername("ebay password");
credential.setApiAccount(acc);
credential.seteBayAccount(eBayAccount);
apiContext.setApiServerUrl("https://api.ebay.com/wsapi");
GetMyeBaySellingCall call = new GetMyeBaySellingCall(apiContext);
GetMyeBaySellingRequestType requestType = new GetMyeBaySellingRequestType();
call.setMyeBaySellingRequest(requestType);
ItemListCustomizationType lc = new ItemListCustomizationType();
lc.setInclude(new Boolean(true));
lc.setIncludeNotes(new Boolean(true));
lc.setSort(ItemSortTypeCodeType.BID_COUNT);
requestType.setActiveList(lc);

lc = new ItemListCustomizationType();
lc.setInclude(new Boolean(true));
lc.setIncludeNotes(new Boolean(true));
lc.setSort(ItemSortTypeCodeType.PRICE);
requestType.setSoldList(lc);

lc = new ItemListCustomizationType();
lc.setInclude(new Boolean(true));
lc.setIncludeNotes(new Boolean(true));
lc.setSort(ItemSortTypeCodeType.END_TIME);
requestType.setUnsoldList(lc);

lc = new ItemListCustomizationType();
lc.setInclude(new Boolean(true));
lc.setIncludeNotes(new Boolean(true));
lc.setSort(ItemSortTypeCodeType.START_TIME);
requestType.setScheduledList(lc);

call.getMyeBaySelling();

GetMyeBaySellingResponseType resp = call.getReturnedMyeBaySellingResponse();

The APIAccount is configured with the data from the developers site of ebay, the eBayAccount is filled with the credentials of the account I want to fetch items for. However, this results in the following exception:

Exception in thread "main" com.ebay.sdk.SdkSoapException: No XML <RequestPassword> or <RequestToken> was found in XML Request.
    at com.ebay.sdk.SdkSoapException.fromSOAPFaultException(Unknown Source)
    at com.ebay.sdk.ApiCall.executeByApiName(Unknown Source)
    at com.ebay.sdk.ApiCall.execute(Unknown Source)
    at com.ebay.sdk.call.GetMyeBaySellingCall.getMyeBaySelling(GetMyeBaySellingCall.java:150)

The user is authenticated for the application and the API-URL is correct. Also, app and user are authenticated for production.

halfer
  • 19,824
  • 17
  • 99
  • 186
ItFreak
  • 2,299
  • 5
  • 21
  • 45

2 Answers2

0

I'd like to give a more detailed example. My app downloads orders from eBay for my account (and my account only). In this case, I do not need to provide App ID, Dev ID or Cert ID. I only need to generate Auth'n'Auth token on eBay and use that as my credential.

Azure function:

@FunctionName("LoadOrders")
public void run(@TimerTrigger(name = "keepAliveTrigger", schedule = "0 5 3 3 * *") String timerInfo, ExecutionContext context)
        throws ApiException, SdkException, Exception {

    ZonedDateTime startDate = ZonedDateTime.now(Constants.TIMEZONE)
        .minusMonths(1)
        .with(TemporalAdjusters.firstDayOfMonth())
        .withHour(0)
        .withMinute(0)
        .withSecond(0)
        .withNano(0);

    ZonedDateTime endDate = ZonedDateTime.now(Constants.TIMEZONE)
        .with(TemporalAdjusters.firstDayOfMonth())
        .withHour(0)
        .withMinute(0)
        .withSecond(0)
        .withNano(0)
        .minusSeconds(1);

    GetOrdersCall call = new GetOrdersCall(apiContext());
    call.setCreateTimeFrom(GregorianCalendar.from(startDate));
    call.setCreateTimeTo(GregorianCalendar.from(endDate));

    for (OrderType orderType : call.getOrders()) {
        System.out.println(orderType);
    }
}

The apiContext() method is defined as follows:

public final static String EBAY_TOKEN = "AgAAAA**AQAA.....a4A9t+/";

public final static String API_SERVER_URL = "https://api.ebay.com/wsapi";

private ApiContext apiContext() {
    // credential
    ApiCredential credential = new ApiCredential();
    credential.seteBayToken(EBAY_TOKEN);

    // context
    ApiContext apiContext = new ApiContext();
    apiContext.setApiCredential(credential);
    apiContext.setApiServerUrl(API_SERVER_URL);
    apiContext.setCallRetry(callRetry());

    return apiContext;
}

And just in case you need it...

private CallRetry callRetry() {
    CallRetry retry = new CallRetry();
    retry.setMaximumRetries(3);
    retry.setDelayTime(3000);
    return retry;
}

You can get the "eBay token" at https://developer.ebay.com/my/auth/?env=production (as of 12/25/2019).

Here's what the screen looks like:

ebay screen shot

anton1980
  • 979
  • 3
  • 10
  • 20
-1
        ApiContext apiContext = new ApiContext();
        ApiCredential credential = apiContext.getApiCredential();
        credential.seteBayToken("token from developer central");
        apiContext.setApiServerUrl("https://api.ebay.com/wsapi");
        GetMyeBaySellingCall call = new GetMyeBaySellingCall(apiContext);
ItFreak
  • 2,299
  • 5
  • 21
  • 45