Solved

Ebay XML

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

Free Tool: Postgres Monitoring System

A PHP and Perl based system to collect and display usage statistics from PostgreSQL databases.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

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…
Introduction Knockoutjs (Knockout) is a JavaScript framework (Model View ViewModel or MVVM framework).   The main ideology behind Knockout is to control from JavaScript how a page looks whilst creating an engaging user experience in the least …
The viewer will learn how to dynamically set the form action using jQuery.
Learn how to create flexible layouts using relative units in CSS.  New relative units added in CSS3 include vw(viewports width), vh(viewports height), vmin(minimum of viewports height and width), and vmax (maximum of viewports height and width).

820 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