Solved

Ebay XML

Posted on 2006-11-22
2
819 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

Enroll in May's Course of the Month

May’s Course of the Month is now available! Experts Exchange’s Premium Members and Team Accounts have access to a complimentary course each month as part of their membership—an extra way to increase training and boost professional development.

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 Since I wrote the original article about Handling Date and Time in PHP and MySQL several years ago, it seemed like now was a good time to update it for object-oriented PHP.  This article does that, replacing as much as possible the pr…
Viewers will learn one way to get user input in Java. Introduce the Scanner object: Declare the variable that stores the user input: An example prompting the user for input: Methods you need to invoke in order to properly get  user input:
The viewer will learn how to dynamically set the form action using jQuery.

751 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