Solved

Ebay XML

Posted on 2006-11-22
2
812 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

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

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

Preface This article introduces an authentication and authorization system for a website.  It is understood by the author and the project contributors that there is no such thing as a "one size fits all" system.  That being said, there is a certa…
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…
Viewers will learn about arithmetic and Boolean expressions in Java and the logical operators used to create Boolean expressions. We will cover the symbols used for arithmetic expressions and define each logical operator and how to use them in Boole…
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…

816 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

9 Experts available now in Live!

Get 1:1 Help Now