Tradera.com logotype

Tradera Developer Program

Adding an Item (Tradera Direct)

Documentation Version 2 > Adding an Item (Tradera Direct)

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.

To create a Tradera Direct item, you need to specify the ItemType when creating a new Item Request. You also need to set the StartQuantity property (when using the AddItem call) or the StartQuantity element (when using the AddItemXml call) to a number between 1 and 10. You also need to specify an Item price in the BuyItNowPrice property.

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 with two images
18: 		Tradera.Api.ItemRequest itemRequest = new Tradera.Api.ItemRequest();
19: 		itemRequest.Title = "My Direct Item (with images!)";
20: 		itemRequest.Description = "The description for My Direct Item";
21: 		itemRequest.AcceptedBidderId = 3; // International
22: 		itemRequest.BuyItNowPrice = 50;
23: 		itemRequest.ExpoItemIds = new int[] { 2, 3, 4 }; // Minibild, Galleri, Fetstil
24: 		itemRequest.InternetPaymentIds = new int[] { 1 }; // Payson
25: 		itemRequest.CategoryId = 280403; // Övrigt > Specialauktioner > Övrigt
26: 		itemRequest.Duration = 11; // 11 days
27: 		itemRequest.OwnRef = "MyOwnReference124";
28: 		itemRequest.ShippingOptionId = 1; // Buyer pays shipping
29: 		itemRequest.BuyerPaysShippingType = 1; // Posten
30: 		itemRequest.BuyerPaysShippingCost = 20; // Required when specifiying BuyerPaysShippingType.
31: 		itemRequest.ItemType = 2; // Tradera Direct item
32: 		itemRequest.StartQuantity = 3; // Must be between 1-10
33: 		itemRequest.AutoCommit = false;
34: 
35: 		int reservedItemId = restrictedService.AddItem(itemRequest);
36: 
37: 		byte[] byteArray = null;
38: 		using(FileStream fileStream = File.OpenRead(@"C:\Image1.jpg")) {
39: 			byteArray = new byte[fileStream.Length];
40: 			fileStream.Read(byteArray, 0, byteArray.Length);
41: 		}
42: 		restrictedService.AddItemImage(reservedItemId, byteArray, Tradera.Api.ImageFormat.Jpeg, true);
43: 
44: 		using(FileStream fileStream = File.OpenRead(@"C:\Image2.jpg")) {
45: 			byteArray = new byte[fileStream.Length];
46: 			fileStream.Read(byteArray, 0, byteArray.Length);
47: 		}
48: 		restrictedService.AddItemImage(reservedItemId, byteArray, Tradera.Api.ImageFormat.Jpeg, false);
49: 
50: 		restrictedService.AddItemCommit(reservedItemId);
51: 
52: 		Console.ReadLine();
53: 
54: 	} catch(Exception exception) {
55: 
56: 		Console.WriteLine("Error: {0}", exception.Message);
57: 		Console.WriteLine(exception.StackTrace);
58: 		Console.ReadLine();
59: 	}
60: }

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, 42 and 48.
  • Uncomment line 15 to use the Sandbox environment.

XHTML CSS