Tradera.com logotype

Tradera Developer Program

Adding an Item (Auction)

Documentation Version 2 > Adding an Item (Auction)

Please read the tutorial on how to use the RestrictedService before continuing.

Important! When experimenting with AddItem, please use the Sandbox enviroment.

There are two possible methods to use when adding an Item, AddItem and AddItemXml. The XML version should only be used by clients that cannot send SOAP objects.

When adding an Item, a request is placed in a queue, which is then processed by the Tradera system. If you want to add images to the Item, you need to set the property AutoCommit to false on the ItemRequest, and then call the method AddItemImage for each image. When done, call AddItemCommit. Note that the call to AddItemCommit is not neccessary if AutoCommit was set to true when you added the Item.

After the Item has been processed, it will, if accepted by the system, either be visible on the main Tradera site or under Sandbox Items in the Developer Center if the request was for the Sandbox. If the request was rejected, the reason will be visible under the calling Application's log in the Developer Center.

Code example

01: [STAThread]
02: static void Main(string[] args) {
03: 
04: 	try {
05: 		string appId = "yourAppId"; // Use your application Id
06: 		string appServiceKey = "yourAppServiceKey"; // Use your application service key
07: 		int userId = 0; // The user Id of the user that you want to impersonate
08: 		string token = "yourToken"; // The Token for the specific user and application
09: 
10: 		Tradera.Api.RestrictedService restrictedService = new Tradera.Api.RestrictedService();
11: 		restrictedService.Url += string.Format("?appId={0}&appKey={1}", appId, appServiceKey);
12: 		restrictedService.Url += string.Format("&userId={0}&token={1}", userId, token);
13: 		
14: 		// Uncomment the next line to make a Sandbox call
15: 		//restrictedService.Url += "&sandbox=1";
16: 
17: 		// Add Item without images
18: 		Tradera.Api.ItemRequest itemRequest1 = new Tradera.Api.ItemRequest();
19: 		itemRequest1.Title = "My first Item";
20: 		itemRequest1.Description = "The description for My First Item";
21: 		itemRequest1.AcceptedBidderId = 3; // International
22: 		itemRequest1.StartPrice = 16;
23: 		itemRequest1.ReservePrice = 20;
24: 		itemRequest1.BuyItNowPrice = 50;
25: 		itemRequest1.ExpoItemIds = new int[] { 4 }; // Fetstil 
26: 		itemRequest1.InternetPaymentIds = new int[] { 1 };
27: 		itemRequest1.CategoryId = 280403; // Övrigt > Specialauktioner > Övrigt
28: 		itemRequest1.Duration = 10; // 10 days
29: 		itemRequest1.OwnRef = "MyOwnReference123";
30: 		itemRequest1.AutoCommit = true;
31: 
32: 		restrictedService.AddItem(itemRequest1);
33: 
34: 		// Add Item with two images
35: 		Tradera.Api.ItemRequest itemRequest2 = new Tradera.Api.ItemRequest();
36: 		itemRequest2.Title = "My second Item (with images!)";
37: 		itemRequest2.Description = "The description for My second Item";
38: 		itemRequest2.AcceptedBidderId = 3; // International
39: 		itemRequest2.StartPrice = 16;
40: 		itemRequest2.ReservePrice = 20;
41: 		itemRequest2.BuyItNowPrice = 50;
42: 		itemRequest2.ExpoItemIds = new int[] { 2, 3, 4 }; // Minibild, Galleri, Fetstil
43: 		itemRequest2.InternetPaymentIds = new int[] { 1 };
44: 		itemRequest2.CategoryId = 280403; // Övrigt > Specialauktioner > Övrigt
45: 		itemRequest2.Duration = 11; // 11 days
46: 		itemRequest2.OwnRef = "MyOwnReference124";
47: 		itemRequest2.AutoCommit = false;
48: 
49: 		int reservedItemId = restrictedService.AddItem(itemRequest2);
50: 
51: 		byte[] byteArray = null;
52: 		using(FileStream fileStream = File.OpenRead(@"C:\Image1.jpg")) {
53: 			byteArray = new byte[fileStream.Length];
54: 			fileStream.Read(byteArray, 0, byteArray.Length);
55: 		}
56: 		restrictedService.AddItemImage(reservedItemId, byteArray, Tradera.Api.ImageFormat.Jpeg, true);
57: 
58: 		using(FileStream fileStream = File.OpenRead(@"C:\Image2.jpg")) {
59: 			byteArray = new byte[fileStream.Length];
60: 			fileStream.Read(byteArray, 0, byteArray.Length);
61: 		}
62: 		restrictedService.AddItemImage(reservedItemId, byteArray, Tradera.Api.ImageFormat.Jpeg, false);
63: 
64: 		restrictedService.AddItemCommit(reservedItemId);
65: 
66: 		Console.ReadLine();
67: 
68: 	} catch(Exception exception) {
69: 
70: 		Console.WriteLine("Error: {0}", exception.Message);
71: 		Console.WriteLine(exception.StackTrace);
72: 		Console.ReadLine();
73: 	}
74: }

Remarks

  • Add your application Id and application service key on lines 5 and 6.
  • Supply the Id and token for the current user on line 7 and 8.
  • Use the name you gave your web reference in place of the Tradera.Api prefix used in lines 10, 18, 35, 56 and 62.
  • Uncomment line 15 to use the Sandbox environment.

XHTML CSS