I am trying to call eBay API through Delphi. After long time searching through Google and StackOverflow, I can get "GeteBayTime" (Shopping API) and "findItemsByKeywords" (Finding API) work properly now.
When I started to test with Trading API, I have no idea where and how to insert seller's account info (userid and password). My first program for trading API is shown below and it is started with API call "GetSellingManagerSoldListings".
Can any one show me some clue to make Trading API work? And if anything else needs to be added to HTTP.header or Paramters?
Thanks.
procedure TForm1.btnEBayGetSoldListClick(Sender: TObject);
var
sURL, sResponse, sEndpoint: String;
jResult: TJSONObject;
sCallName, sSiteID, sVersion: String;
k: Integer;
sParameters: String;
sHeaders: TStringList;
sRequestBody: TStringStream;
begin
// Trading API
sEndpoint := 'https://api.sandbox.ebay.com/ws/api.dll';
sCallName := 'GetSellingManagerSoldListingsRequest';
sSiteID := '15';
sVersion := '967';
sAppID := 'myAppID';
sDevID := 'myDevID';
sToken : 'myToken'; // OAuth Token?
sURL := sEndpoint
+ '?callname=' + sCallName
+ '&siteid=' + '15';
sHeaders := TStringList.Create;
with sHeaders do begin
Add('X-EBAY-API-COMPATIBILITY-LEVEL' + '=' + sVersion);
Add('X-EBAY-API-DEV-NAME' + '=' + sDevID);
Add('X-EBAY-API-APP-NAME' + '=' + sAppID);
Add('X-EBAY-API-CERT-NAME' + '=' + sCertID);
Add('X-EBAY-API-CALL-NAME' + '=' + sCallName);
Add('X-EBAY-API-SITEID' + '=' + sSiteID);
end;
objHTTP.Request.ContentType := 'text/xml';
with objHTTP.Request.CustomHeaders do begin
Clear;
AddStdValues(sHeaders);
end;
sHeaders.Free;
sParameters := '<GetSellingManagerSoldListingsRequest xmlns="urn:ebay:apis:eBLBaseComponents">'
+ ' <RequesterCredentials>'
+ ' <eBayAuthToken>' + sToken + '</eBayAuthToken>'
+ ' <Filter>' + 'PaidNotShipped' + '</Filter>'
+ ' </RequesterCredentials>'
+ '</GetItemTransactionsRequest>';
sRequestBody := TStringStream.Create(sParameters, TEncoding.UTF8);
try
sResponse := objHTTP.Post(sURL, sRequestBody);
memHTML.Lines.Add(sResponse);
memHTML.Lines.Add('');
except
sResponse := objHTTP.ResponseText;
memHTML.Lines.Add(sResponse);
memHTML.Lines.Add('');
end;
end;
Here You go: Complete working GetSellingManagerSoldListingsRequest SOAP envelope:
You may omit "search" tags to get full listing. Most of the trading api requests work this way.
Simplest way to do it in delphi:
Just put THTTPReqResp from WebServices tab on the form instead of TidHTTP, set url (THTTPReqResp1.URL) and run with THTTPReqResp1.Execute(const DataMsg: String; Resp: TStream); where DataMsg is provided SOAP envelope and response is saved to TStream (e.g TStringStream). You may also need to set InvokeOptions -> soIgnoreInvalidCerts in some cases.
Although it is possible to "assemble" request the way You did, i'd recomend to use WSDL wizard, import EBAY WSDL use WSDL Pruner Tool to cut less important functions (to avoid "E2491 Maximum VIRDEF count exceeded; check for recursion") and proceed with auto-generated unit.