Tradera.com logotype

Tradera Developer Program

Executing your first SOAP API call

This section walks through the basics of executing a call - specifically, the GetOfficalTime call - for the Tradera SOAP API. The GetOfficalTime call is the simplest call in the API. It is used to get the offical Tradera time, which can then for example be used to calculate how much time is left before an auction ends.

Prerequisites

Before you execute your first API call you must create an API Developer account. You will then have to register an Application, and note down the service key and the application Id.

Step 1: Setup a programming environment

C# Microsoft Visual Studio .NET

The specific steps that you must perform to set up your environment will vary depending on what programming language you use. The first example was written in C# Microsoft Visual Studio .NET.

In Visual Studio, create a console application project, then add a web reference to the Tradera PublicService (Solution Explorer, right-click, Add Web Reference). Enter the URL to the latest Tradera PublicService WSDL:

https://api.tradera.com/v3/PublicService.asmx?WSDL

Then, click Add Reference. This generates stubs from the Tradera PublicService WSDL and adds them to the project so that they are available to your source files. You can see them in the Class View.

PHP 5

When using PHP you only need to check that the Soap extension is installed and available. You can check this with:

$ php -r 'echo extension_loaded("soap") ? "OK" : "Not OK"; echo PHP_EOL;'

Step 2: Add the code

C# Microsoft Visual Studio .NET

In the main method, add the following code:

  0:
  1:
  2:
  3:
  4:
  5:
  6:
  7:
  8:
  9:
 10:
 11:
 12:
 13:
 14:
 15:
 16:
 17:
 18:
 19:
 20:
 21:
 22:
   
[STAThread]
static void Main(string[] args) {

	try {
		string appId = "yourAppId"; // Use your application Id
		string appServiceKey = "yourAppServiceKey"; // Use your application service key

		Tradera.Api.PublicService publicService = new Tradera.Api.PublicService();
		publicService.Url += string.Format("?appId={0}&appKey={1}", appId, appServiceKey);
		
		DateTime officalTraderaTime = publicService.GetOfficalTime();
		 
 		Console.WriteLine("The offical Tradera time is: {0}", officalTraderaTime);
 		Console.ReadLine();

	} catch(Exception exception) {

		Console.WriteLine("Error: {0}", exception.Message);
		Console.WriteLine(exception.StackTrace);
		Console.ReadLine();
	}
}

You must modify some of the code with your information in order for it to work:

  • Add your application Id and application service key on lines 5 and 6.
  • Use the name you gave your web reference in place of the Tradera.Api prefix.

PHP 5

Add the following code to a .php file:

  0:
  1:
  2:
  3:
  4:
  5:
  6:
  7:
  8:
  9:
 10:
 11:
 12:
 13:
 14:
 15:
 16:
 17:
 18:
 19:
 20:
 21:
 22:
 23:
 24:
 25:
 26:
 27:
 28:
 29:
 30:
   
<?php
try {

	// Replace the following variables with your own key management
	// $APPLICATION_KEY
	// $APPLICATION_ID
	$appId = $APPLICATION_ID;
	$appKey = $APPLICATION_KEY;
	$publicServiceUrl = 'https://api.tradera.com/v3/PublicService.asmx';

	$publicServiceUrlWithAuth = $publicServiceUrl
					. '?appId=' . $appId
					. '&appKey=' . $appKey;

	$publicClient = new SoapClient(
		$publicServiceUrl . '?WSDL',
		array('location' => $publicServiceUrlWithAuth)
	);


	// Make Soap call
	$getOfficialTimeResponse = $publicClient->GetOfficalTime();

	// Handle result
	echo 'The official Tradera time is: ' . $getOfficialTimeResponse -> GetOfficalTimeResult . PHP_EOL;
}
catch(SoapFault $soapFault) {
	echo 'Error: ' . $soapFault->faultstring;
}
?>

You must add your application Id and application service key on lines 7 and 8 in order for it to work.

Step 3: Run the sample

C# Microsoft Visual Studio .NET

Now you can build and run the sample.

  • From the menu, choose Build, then Build Solution.
  • Choose Debug, then Start Without Debugging

PHP 5

Navigate to your file in the terminal and run:

php yourFileName.php

Thats it!

You should see output like this:

01: The offical Tradera time is: 2007-06-29 12:16:50     

Congratulations! You have just made your first Tradera API call.

If you prefer, you can use SOAP headers instead of sending the application Id and service key on the querystring. For instructions, please see the sample SOAP requests.

See also the SOAP code samples for PHP and ASP.

XHTML CSS