Solved

Ebay XML

Posted on 2006-11-22
2
804 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:ciuly
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

Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

Join & Write a Comment

Preface In the first article: A Better Website Login System (http://www.experts-exchange.com/A_2902.html) I introduced the EE Collaborative Login System and its intended purpose. In this article I will discuss some of the design consideratio…
This article covers the basics of the Sass, which is a CSS extension language. You will learn about variables, mixins, and nesting.
Viewers will learn about the different types of variables in Java and how to declare them. Decide the type of variable desired: Put the keyword corresponding to the type of variable in front of the variable name: Use the equal sign to assign a v…
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…

760 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

19 Experts available now in Live!

Get 1:1 Help Now