Solved

Ebay XML

Posted on 2006-11-22
2
808 Views
Last Modified: 2013-11-19
Hi,
I am trying to use Ebay XML api.
That's wat I do

    xmlText := TStringList.Create;
    aToken := 'AgAAAA**AQAAAA**aAAAAA**Z01kRQ**nY+sHZ2PrBmdj6wVnY+sEZ2PrA2dj6wFk4CkC5mLoAidj6x9nY+seQ**rZcAAA**AAMAAA**wvmb8PMie6nN6ShhK3a7iBLyifKcwVSAKPA2moRQmC8IsUqIsSr6dW2Y4RC14kE5X49X5D8HObyX735CmQoWSeA9BE72ULdki+1WtVl';
    aToken := aToken + 'cOd7ilz2gI9nYjMpLe0quWj8z5jkc2LV4fuQSoWumkVv9itCEPAY+9tq9rXS15tpGYVYYLKXPiZW6UiNPsS5rhCsnfqzSPDAIQbb4ZkdqjjDntnOqATq48yomTCotpoPViQWnrUMcubz6xPeH6AsGJHIXZNxHab3CV5JinDEcy6nt1QJIhs9A6gfhPudd1UgTJwPQQkXdi+8Z0o';
    aToken := aToken + '6mEXTSGg+7pkeLf+LxcwUE1kjf8p+PyCWETsbAghAchnVSuLERiaEqNaeDr6wBniwoMbahoHZ7RGXnDWFfN05HUH6PmKaT2y0D5Eoyl+k53dd2zD52jsoC4Ou4ghx7rX89NWShfk1cSmbIRxFlI0DxhayBftsP8NaePavWGv9AsMihTdWi4rT9vPPq1KRF13ULQtD2molZWqWoQ';
    aToken := aToken + '4Eqj+WuNox2D8dusCNeKW3fVZ6+dxciiCDbM5lh+LRoN4THVq/t6MV1cL0sNzevmnl0FWDNrp/wklY3Bo6SuKAkKDcp2MUfug53M/V57hTZrT5AD+3iL4g4AwvVGAVvgvRClTwP9cEwesDcpm92jN4skXkQk71BSeylPtNHbZHDFkVd/voK/aku1IbWRh15NMQCEjP41sllppa/';
    aToken := aToken + 'DCSJkaXOo60l9DXoI03YqWfvZWG1vFOoEpye5EsXAkih';

            xmlText.Add('<?xml version="1.0" encoding="utf-8" ?>');
            xmlText.Add('<GetItemRequest xmlns="urn:ebay:apis:eBLBaseComponents">');
            xmlText.Add('<RequesterCredentials><eBayAuthToken>'+aToken+'</eBayAuthToken></RequesterCredentials>');
            xmlText.Add('<ItemID>'+Edit1.Text+'</ItemID>');
            xmlText.Add('</GetItemRequest>');

    //memo1.Text := xmlText;

    xmlDocChargeCustomer  := CreateOleObject('MSXML2.DOMDocument.3.0') as IXMLDOMDocument;
    oXMLHTTP := CreateOleObject('MSXML2.XMLHTTP.3.0')     as IXMLHTTPRequest;
    xmlDocChargeCustomer.loadXML(xmlText.Text);
    oXMLHTTP.open('POST', 'https://api.sandbox.ebay.com/ws/api.dll', False,'','');
    oXMLHTTP.setRequestHeader('ENCODING', 'UTF-8');
    oXMLHTTP.setRequestHeader('CONTENT-ENCODING', 'UTF-8');
    oXMLHTTP.setRequestHeader('X-EBAY-API-COMPATIBILITY-LEVEL', '433');
    oXMLHTTP.setRequestHeader('X-EBAY-API-DEV-NAME', 'xxxxx');
    oXMLHTTP.setRequestHeader('X-EBAY-API-APP-NAME', 'xxx');
    oXMLHTTP.setRequestHeader('X-EBAY-API-CERT-NAME', 'xxx ');
    oXMLHTTP.setRequestHeader('X-EBAY-API-CALL-NAME', 'GetItem');
    oXMLHTTP.setRequestHeader('X-EBAY-API-SITEID', '3');
    oXMLHTTP.send(xmlDocChargeCustomer.XML);
    ResponseText := Trim(oXMLHTTP.ResponseText);
    ResponseHeaders := oXMLHTTP.getAllResponseHeaders;
    showmessage(ResponseHeaders);
    memo1.Text :=ResponseText;

but the response I get is
<?xml version="1.0" encoding="UTF-8"?>
<GetItemResponse xmlns="urn:ebay:apis:eBLBaseComponents"><Timestamp>2006-11-22T15:14:56.376Z</Timestamp><Ack>Failure</Ack><Errors><ShortMessage>Invalid request encoding.</ShortMessage><LongMessage>Invalid request encoding. Please use utf-8 encoding and eliminate any non utf-8 encoding in request content.</LongMessage><ErrorCode>20400</ErrorCode><SeverityCode>Error</SeverityCode><ErrorParameters ParamID="0"><Value>GetItem</Value></ErrorParameters><ErrorClassification>RequestError</ErrorClassification></Errors><Version>485</Version><Build>e485_intl_Bundled_3857952_R1</Build></GetItemResponse>

How can I specify the encoding?
0
Comment
Question by:bilgehanyildirim
2 Comments
 
LVL 28

Expert Comment

by:2266180
ID: 18038900
some xml parsers are strict about case sensitivity of some elements. like the enconding. so instead of
xmlText.Add('<?xml version="1.0" encoding="utf-8" ?>');
try to use
xmlText.Add('<?xml version="1.0" encoding="UTF-8" ?>');
I never used the ebay API so I am just guessing.

you might also try soemthing like:

 oXMLHTTP.send(AnsiToUtf8(xmlDocChargeCustomer.XML));
0
 
LVL 26

Accepted Solution

by:
EddieShipman earned 500 total points
ID: 18039082
It may be that the CRLF's and other whitespace in the XML is causing the problem.
I would have done something like this:

var
  sStream: TStringStream;
  oXMLHTTP: IXMLHTTPRequest;
begin
  sStream := TStringStream.Create('');
  try

    aToken := 'AgAAAA**AQAAAA**aAAAAA**Z01kRQ**nY+sHZ2PrBmdj6wVnY+sEZ2PrA2dj6wFk4CkC5mLoAidj6x9nY+seQ**rZcAAA**AAMAAA**wvmb8PMie6nN6ShhK3a7iBLyifKcwVSAKPA2moRQmC8IsUqIsSr6dW2Y4RC14kE5X49X5D8HObyX735CmQoWSeA9BE72ULdki+1WtVl';
    aToken := aToken + 'cOd7ilz2gI9nYjMpLe0quWj8z5jkc2LV4fuQSoWumkVv9itCEPAY+9tq9rXS15tpGYVYYLKXPiZW6UiNPsS5rhCsnfqzSPDAIQbb4ZkdqjjDntnOqATq48yomTCotpoPViQWnrUMcubz6xPeH6AsGJHIXZNxHab3CV5JinDEcy6nt1QJIhs9A6gfhPudd1UgTJwPQQkXdi+8Z0o';
    aToken := aToken + '6mEXTSGg+7pkeLf+LxcwUE1kjf8p+PyCWETsbAghAchnVSuLERiaEqNaeDr6wBniwoMbahoHZ7RGXnDWFfN05HUH6PmKaT2y0D5Eoyl+k53dd2zD52jsoC4Ou4ghx7rX89NWShfk1cSmbIRxFlI0DxhayBftsP8NaePavWGv9AsMihTdWi4rT9vPPq1KRF13ULQtD2molZWqWoQ';
    aToken := aToken + '4Eqj+WuNox2D8dusCNeKW3fVZ6+dxciiCDbM5lh+LRoN4THVq/t6MV1cL0sNzevmnl0FWDNrp/wklY3Bo6SuKAkKDcp2MUfug53M/V57hTZrT5AD+3iL4g4AwvVGAVvgvRClTwP9cEwesDcpm92jN4skXkQk71BSeylPtNHbZHDFkVd/voK/aku1IbWRh15NMQCEjP41sllppa/';
    aToken := aToken + 'DCSJkaXOo60l9DXoI03YqWfvZWG1vFOoEpye5EsXAkih';
    sStream.WriteString('<?xml version="1.0" encoding="UTF-8" ?>');
    sStream.WriteString('<GetItemRequest xmlns="urn:ebay:apis:eBLBaseComponents">');
    sStream.WriteString('<RequesterCredentials><eBayAuthToken>'+aToken+'</eBayAuthToken></RequesterCredentials>');
    sStream.WriteString('<ItemID>'+Edit1.Text+'</ItemID>');
    sStream.WriteString('</GetItemRequest>');

    oXMLHTTP := CreateOleObject('MSXML2.XMLHTTP.3.0') as IXMLHTTPRequest;
    try
      oXMLHTTP.open('POST', 'https://api.sandbox.ebay.com/ws/api.dll', False,'','');
      oXMLHTTP.setRequestHeader('ENCODING', 'UTF-8');
      oXMLHTTP.setRequestHeader('CONTENT-ENCODING', 'UTF-8');
      oXMLHTTP.setRequestHeader('X-EBAY-API-COMPATIBILITY-LEVEL', '433');
      oXMLHTTP.setRequestHeader('X-EBAY-API-DEV-NAME', 'xxxxx');
      oXMLHTTP.setRequestHeader('X-EBAY-API-APP-NAME', 'xxx');
      oXMLHTTP.setRequestHeader('X-EBAY-API-CERT-NAME', 'xxx ');
      oXMLHTTP.setRequestHeader('X-EBAY-API-CALL-NAME', 'GetItem');
      oXMLHTTP.setRequestHeader('X-EBAY-API-SITEID', '3');
      oXMLHTTP.send(sStream.DataString);
      ResponseText := Trim(oXMLHTTP.ResponseText);
      ResponseHeaders := oXMLHTTP.getAllResponseHeaders;
    finally
      oXMLHTTP := nil;
    end;
    // Showmessage(ResponseHeaders);
    Memo1.Text := ResponseText;
  finally
    sStream.Free;
  end;
end;
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Most of the sites are being standardized with W3C Web Standards. W3C provides lot of web standard services to the web. They have the web specification, process and documentation for all the web standards. You can apply HTML, CSS and Accessibility st…
What is Node.js? Node.js is a server side scripting language much like PHP or ASP but is used to implement the complete package of HTTP webserver and application framework. The difference is that Node.js’s execution engine is asynchronous and event…
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.
HTML5 has deprecated a few of the older ways of showing media as well as offering up a new way to create games and animations. Audio, video, and canvas are just a few of the adjustments made between XHTML and HTML5. As we learned in our last micr…

930 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now