Tradera.com logotype

Tradera Developer Program

PHP5 and classic ASP code samples

Documentation Version 2 > PHP5 and classic ASP code samples

Code samples for calling the API GetItem method from PHP5 and Classic ASP.

PHP5

PHP needs to to have the SOAP extension enabled and available.

01: <?php
02:  
03: 	try {
04:  
05: 		$serviceUrl = "http://api.tradera.com/v2/PublicService.asmx";
06: 
07: 		$client = new SoapClient($serviceUrl . "?WSDL",
08: 			array("location" => $serviceUrl . 
09: 			"?appId=yourAppId&appKey=yourAppServiceKey"));
10: 
11: 		// Use some active auction's Id
12: 		// (for example, one of the Guldkorn
13: 		// auctions from the Tradera.com mainpage)
14: 		$params->itemId = 0;
15: 		$objectresult = $client->GetItem($params);
16: 	?>
17: 
18: 		<h1>
19: 			GetItem, item #<?php echo ($objectresult->GetItemResult->Id) ?>
20: 		</h1>
21: 
22: 	<?php
23: 		echo "<h2>Long description</h2><pre>" . 
24: 			  $objectresult->GetItemResult->LongDescription . "</pre>";
25: 
26: 	} catch(SoapFault $soapFault) {
27: 		echo "Error: " . $soapFault->faultstring;
28: 	}
29: 
30: ?>

Remarks

  • You must replace yourAppId and yourAppServiceKey with your own application Id and application service key on line 09.
  • Get an active auction's Id from the Tradera.com site to use on line 14.

PHP5 with complex type parameter

PHP needs to to have the SOAP extension enabled and available.

01: <?php
02: 
03: 	try {
04: 
05: 		$serviceUrl = "http://api.tradera.com/v2/PublicService.asmx";
06: 
07: 		$client = new SoapClient($serviceUrl . "?WSDL",
08: 			array(
09: 				"location" => $serviceUrl . "?appId=yourAppId&appKey=yourAppServiceKey",
10: 				"encoding" => "iso-8859-1"
11: 			)
12: 		);
13: 		  
14: 		$params->query = new SoapVar(
15: 			array(
16: 				"SearchWords" => "ipod",
17: 				"CategoryId" => 0,
18: 				"SearchInDescription" => false,
19: 				"Mode" => "AllWords",
20: 				"PriceMinimum" => 0,
21: 				"PriceMaximum" => 0,
22: 				"BidsMinimum" => 1,
23: 				"BidsMaximum" => 10,
24: 				"ZipCode" => "",
25: 				"CountyId" => 0,
26: 				"Alias" => "",
27: 				"OrderBy" => "BidsDescending",
28: 				"ItemStatus" => "Active",
29: 				"ItemType" => "Auction",
30: 				"OnlyAuctionsWithBuyNow" => false,
31: 				"OnlyItemsWithThumbnail" => true,
32: 				"ItemsPerPage" => 3,
33: 				"PageNumber" => 1
34: 			),
35: 			XSD_ANYTYPE,
36: 			"Query",
37: 			"http://api.tradera.com"
38: 		);
39: 		  
40: 		$objectresult = $client->GetSearchResultAdvanced($params);
41: 
42: 		?>
43: 
44: 		<h1>
45: 			GetSearchResultAdvanced
46: 		</h1>
47: 		<p>
48: 			Total number of items: <?php echo ($objectresult->GetSearchResultAdvancedResult->TotalNumberOfItems) ?> on
49: 			<?php echo ($objectresult->GetSearchResultAdvancedResult->TotalNumberOfPages) ?> pages.
50: 		</p>
51: 
52: 		<?php
53: 
54: 		foreach($objectresult->GetSearchResultAdvancedResult->Items as $item) {
55: 			echo "<h2>" . $item->ShortDescription . " (" . $item->Id . ")</h2>";
56: 			echo "<p>Bids: " . $item->TotalBids . "</p>";
57: 			echo '<img src="'. $item->ThumbnailLink . '" alt="' . $item->ShortDescription . '" />';
58: 			echo "<pre>" . $item->LongDescription . "</pre>";
59: 		}
60: 
61: 	} catch(SoapFault $soapFault) {
62: 		echo "Error: " . $soapFault->faultstring;
63: 
64: 	} catch(Exception $e) {
65: 		echo "Error: " . $e;
66: 	}
67: 
68: ?>

Remarks

  • You must replace yourAppId and yourAppServiceKey with your own application Id and application service key on line 09.

Classic ASP

01: <%
02: 
03: 	Dim itemId
04: 
05: 	' Use some active auction's Id
06: 	' (for example, one of the Guldkorn
07: 	' auctions from the Tradera.com mainpage)
08: 	itemId = 0
09: 
10: 	Dim httpRequest
11: 	Set httpRequest = CreateObject("MSXML2.XMLHTTP")
12: 
13: 	'Create the SOAP Envelope, check the example page for each method
14: 	' (for instance http://api.tradera.com/v2/PublicService.asmx?op=GetItem)
15: 	Dim soapEnvelope
16: 	soapEnvelope = _
17: 	"<soap:Envelope xmlns:xsi=""http://www.w3.org/2001/XMLSchema-instance"" xmlns:xsd=""http://www.w3.org/2001/XMLSchema"" xmlns:soap=""http://schemas.xmlsoap.org/soap/envelope/"">" & _
18: 	"  <soap:Body>" & _
19: 	"    <GetItem xmlns=""http://api.tradera.com"">" & _
20: 	"      <itemId>" & itemId &  "</itemId>" & _
21: 	"    </GetItem>" & _
22: 	"  </soap:Body>" & _
23: 	"</soap:Envelope>"
24: 
25: 
26: 	Dim applicationId, applicationKey
27: 
28: 	' This should be your application Id
29: 	applicationId = yourApplicationId
30: 
31: 	' This should be your application key
32: 	applicationKey = "yourApplicationKey"
33: 
34: 	httpRequest.Open "POST", "http://api.tradera.com/v2/PublicService.asmx?appId=" & applicationId & "&appKey=" & applicationKey, False
35: 	httpRequest.SetRequestHeader "Content-Type", "text/xml"
36: 
37: 	' Set a header for the method to be called
38: 	httpRequest.SetRequestHeader "SOAPAction", "http://api.tradera.com/GetItem"
39: 
40: 	' Make the SOAP call
41: 	httpRequest.send soapEnvelope
42: 
43: 	If httpRequest.Status = 200 Then
44: 
45: 		' Create XML document from response
46: 		Dim xmlDoc
47: 		Set xmlDoc = CreateObject("Microsoft.XMLDOM")
48: 		xmlDoc.load(httpRequest.responseBody)
49: 
50: 		' Select the long description into an XML node
51: 		Dim longDescriptionNode
52: 		Set longDescriptionNode = xmlDoc.selectSingleNode("//LongDescription")
53: 
54: 		' Write out the long description
55: 		Response.Write "<h1>Long description for item #" & itemId & "</h1><pre>" & longDescriptionNode.Text & "</pre>"
56: 
57: 	Else
58: 		Response.Write "<h1>Status</h1><p>" & httpRequest.Status & " (" & httpRequest.StatusText & ")</p>"
59: 
60: 	End If
61: 
62: %>

Remarks

  • Get an active auction's Id from the Tradera.com site to use on line 08.
  • You must replace yourAppId and yourAppServiceKey with your own application Id and application service key on line 29 and 32.

XHTML CSS