Skip to main content
Published: November 07 2008, 12:42:00 AMUpdated: November 28 2020, 4:58:06 PM

Flex Sample for Trading API

Summary

  This sample is implemented in Adobe's Flex program language. The application illustrates how to make Trading API calls and display Trading API request and response xml to TextArea fields.

Image


 Detailed Description

SOFTWARE REQUIREMENTS

USE THE SAMPLE

  • Create a Flex project.
  • Make a folder and name it as 'handler' for the project
  • Download the attached UrlLoaderListener.as file and saved it in the 'handler' folder
  • Copy and save the source code as below into a MXML project file
 

 

<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute">
     
     <mx:Script>
          <![CDATA[
          import flash.net.URLRequest;
          import mx.rpc.events.*;
         import flash.net.*;
         import mx.controls.Alert;
         import flash.events.*;
         import handler.UrlLoaderListener;
         <?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute">
     
     <mx:Script>
          <![CDATA[
          import flash.net.URLRequest;
          import mx.rpc.events.*;
         import flash.net.*;
         import mx.controls.Alert;
         import flash.events.*;
         import handler.UrlLoaderListener;
         

         public static const SERVICE_URL               : String = "https://api.sandbox.ebay.com/ws/api.dll";
          public static const APP_NAME                  : String = "REPLACEME";
          public static const DEV_NAME                 : String = "REPLACEME";
          public static const CERT_NAME               : String = "REPLACEME";
          public static const AUTHTOKEN               : String = "REPLACEME";  
          public static const CONTENT_TYPE         : String = "text/xml";
          public static const VERSION                      : String = "587";
          public static const SITE                               : String = "0";
          public static const XML_VERSION_LINE          : String = "<?xml version='1.0' encoding='utf-8'?>";
          public static const eBay_API_NAME_SPACE       : String = 'urn:ebay:apis:eBLBaseComponents';
         
          public var reqHeaders:Array = new Array();
          [Bindable]     
         public var tradingApiResponse:XML;
         [Bindable]
         public var tradingApiRequest:String;
         
             
         public function setBasicHeaders(devID:String,apiID:String,cert:String):Array{
               
               reqHeaders.push(new URLRequestHeader("X-EBAY-API-COMPATIBILITY-LEVEL", VERSION));
               reqHeaders.push(new URLRequestHeader("X-EBAY-API-SITEID", SITE));
               reqHeaders.push(new URLRequestHeader("Content-Type", CONTENT_TYPE));
               reqHeaders.push(new URLRequestHeader("X-EBAY-API-DEV-NAME", devID));
               reqHeaders.push(new URLRequestHeader("X-EBAY-API-APP-NAME", apiID));
               reqHeaders.push(new URLRequestHeader("X-EBAY-API-CERT-NAME", cert));
               return reqHeaders;
         }
         
         public function setRequestHeaders(callName:String):URLRequest{
              var req:URLRequest = new URLRequest(SERVICE_URL);
              reqHeaders = setBasicHeaders(DEV_NAME,APP_NAME,CERT_NAME);
              reqHeaders.push(new URLRequestHeader("X-EBAY-API-CALL-NAME", callName));
               req.method = URLRequestMethod.POST;
               req.requestHeaders = reqHeaders;
               return req;
                     
         }     
        [Bindable]
        public function getDefaultTradingAPRequestXml():String {          
                var reqBody:XML=<GeteBayOfficialTimeRequest xmlns={eBay_API_NAME_SPACE}>
                           <RequesterCredentials>
                               <eBayAuthToken>{AUTHTOKEN}</eBayAuthToken>
                           </RequesterCredentials>
                           </GeteBayOfficialTimeRequest>
           tradingApiRequest=XML_VERSION_LINE+reqBody.toXMLString();
           return tradingApiRequest;
        }
        
        public function geteBayOfficialTimeRequest():void {
                var req:URLRequest= setRequestHeaders('GeteBayOfficialTime');           
           req.data = apiRequest.text;              
           trace("TEXT IN TEXTARER : "+apiRequest.text);
             var loaderListener:UrlLoaderListener = new UrlLoaderListener();
             loaderListener.loader(req,onGeteBayOfficialTimeComplete);
        }
        
        public function onGeteBayOfficialTimeComplete(event:Event):void {
               trace("onGeteBayOfficialTimeComplete method ");
              var loader:URLLoader = URLLoader(event.target);
              tradingApiResponse = new XML(loader.data);
              
              var status:XMLList = tradingApiResponse.children();
              var childName:String = "Ack";   
              if (status[1].toString() !=null && status[1].toString()=="Success"){                     
                  trace(status[0].toString());
              }              
       }
               
          ]]>
     </mx:Script>
     <mx:Panel x="48" y="72" width="703" height="396" layout="absolute">
          <mx:Button x="19" y="123" label="Submit " width="83" click="{geteBayOfficialTimeRequest()}"/>
          <mx:VBox x="110" y="40" width="545" height="111" backgroundColor="#ffffff">
               <mx:TextArea width="541" height="106" id="apiRequest" text="{getDefaultTradingAPRequestXml()}" editable="true" wordWrap="true">          
               </mx:TextArea>
          </mx:VBox>
          <mx:VBox x="110" y="200" width="545" height="133" backgroundColor="#ffffff">
               <mx:TextArea width="546" height="132" id="apiResponse" text="{tradingApiResponse.toXMLString()}"
                    editable="true" wordWrap="true">
               </mx:TextArea>
          </mx:VBox>
          <mx:VBox x="110" y="10" width="545" height="30" backgroundColor="#703838">
               <mx:Label text="API Request " width="155" color="#ffffff" fontSize="14"/>
          </mx:VBox>
          <mx:VBox x="110" y="159" width="545" height="33" backgroundColor="#703838">
               <mx:Label text="API Response" width="106" fontSize="14" color="#ffffff"/>
          </mx:VBox>
     </mx:Panel>
     
</mx:Application>

        public static const SERVICE_URL               : String = "https://api.sandbox.ebay.com/ws/api.dll";
          public static const APP_NAME                  : String = "CHANGEME";
          public static const DEV_NAME                  : String = "CHANGEME";
          public static const CERT_NAME                 : String = "CHANGEME";
          public static const AUTHTOKEN                 : String = "CHANGEME"; // for inna_test
          public static const CONTENT_TYPE              : String = "text/xml";
          public static const VERSION                   : String = "587";
          public static const SITE                      : String = "0";
          public static const XML_VERSION_LINE          : String = "<?xml version='1.0' encoding='utf-8'?>";
          public static const eBay_API_NAME_SPACE       : String = 'urn:ebay:apis:eBLBaseComponents';
         
          public var reqHeaders:Array = new Array();
          [Bindable]     
         public var tradingApiResponse:XML;
         [Bindable]
         public var tradingApiRequest:String;
         
             
         public function setBasicHeaders(devID:String,apiID:String,cert:String):Array{
               
               reqHeaders.push(new URLRequestHeader("X-EBAY-API-COMPATIBILITY-LEVEL", VERSION));
               reqHeaders.push(new URLRequestHeader("X-EBAY-API-SITEID", SITE));
               reqHeaders.push(new URLRequestHeader("Content-Type", CONTENT_TYPE));
               reqHeaders.push(new URLRequestHeader("X-EBAY-API-DEV-NAME", devID));
               reqHeaders.push(new URLRequestHeader("X-EBAY-API-APP-NAME", apiID));
               reqHeaders.push(new URLRequestHeader("X-EBAY-API-CERT-NAME", cert));
               return reqHeaders;
         }
         
         public function setRequestHeaders(callName:String):URLRequest{
              var req:URLRequest = new URLRequest(SERVICE_URL);
              reqHeaders = setBasicHeaders(DEV_NAME,APP_NAME,CERT_NAME);
              reqHeaders.push(new URLRequestHeader("X-EBAY-API-CALL-NAME", callName));
               req.method = URLRequestMethod.POST;
               req.requestHeaders = reqHeaders;
               return req;
                     
         }     
        [Bindable]
        public function getDefaultTradingAPRequestXml():String {          
                var reqBody:XML=<GeteBayOfficialTimeRequest xmlns={eBay_API_NAME_SPACE}>
                           <RequesterCredentials>
                               <eBayAuthToken>{AUTHTOKEN}</eBayAuthToken>
                           </RequesterCredentials>
                           </GeteBayOfficialTimeRequest>
           tradingApiRequest=XML_VERSION_LINE+reqBody.toXMLString();
           return tradingApiRequest;
        }
        
        public function geteBayOfficialTimeRequest():void {
                var req:URLRequest= setRequestHeaders('GeteBayOfficialTime');           
           req.data = apiRequest.text;              
           trace("TEXT IN TEXTARER : "+apiRequest.text);
             var loaderListener:UrlLoaderListener = new UrlLoaderListener();
             loaderListener.loader(req,onGeteBayOfficialTimeComplete);
        }
        
        public function onGeteBayOfficialTimeComplete(event:Event):void {
               trace("onGeteBayOfficialTimeComplete method ");
              var loader:URLLoader = URLLoader(event.target);
              tradingApiResponse = new XML(loader.data);
              
              var status:XMLList = tradingApiResponse.children();
              var childName:String = "Ack";   
              if (status[1].toString() !=null && status[1].toString()=="Success"){                     
                  trace(status[0].toString());
              }              
       }
               
          ]]>
     </mx:Script>
     <mx:Panel x="48" y="72" width="703" height="396" layout="absolute">
          <mx:Button x="19" y="123" label="Submit " width="83" click="{geteBayOfficialTimeRequest()}"/>
          <mx:VBox x="110" y="40" width="545" height="111" backgroundColor="#ffffff">
               <mx:TextArea width="541" height="106" id="apiRequest" text="{getDefaultTradingAPRequestXml()}" editable="true" wordWrap="true">          
               </mx:TextArea>
          </mx:VBox>
          <mx:VBox x="110" y="200" width="545" height="133" backgroundColor="#ffffff">
               <mx:TextArea width="546" height="132" id="apiResponse" text="{tradingApiResponse.toXMLString()}"
                    editable="true" wordWrap="true">
               </mx:TextArea>
          </mx:VBox>
          <mx:VBox x="110" y="10" width="545" height="30" backgroundColor="#703838">
               <mx:Label text="API Request " width="155" color="#ffffff" fontSize="14"/>
          </mx:VBox>
          <mx:VBox x="110" y="159" width="545" height="33" backgroundColor="#703838">
               <mx:Label text="API Response" width="106" fontSize="14" color="#ffffff"/>
          </mx:VBox>
     </mx:Panel>
     
</mx:Application>

 The SampleVersion Info

The code example in this Knowledge Base article is based on the versions specified below:

Trading API Schema Version 597

How well did this answer your question?
Answers others found helpful