C# Examples

C# Example for findItemsByKeywords

Sample: Basic Call

Retrieves a set of items based on keywords provided.

Code

Basic C# code to search for items matching "The King":

using System;
using System.Net;
using System.Net.Http;
using System.IO;
using System.Text;
using System.Threading.Tasks;
using System.Collections.Generic;
using System.Text.RegularExpressions;
using System.Globalization;

using Newtonsoft.Json;
using Newtonsoft.Json.Linq;

namespace c_sharp_examples
{
  public class FindItemsByKeywordsExample
  {
    public static void Main (string[] args)
    {
      var dataObject = new
      {
        findItemsByKeywords = new
        {
          keywords = "The King"
        }
      };

      string dataJSON = JsonConvert.SerializeObject(dataObject);

      var url = "http://api.bonanza.com/api_requests/standard_request";
      var content = new StringContent (dataJSON, Encoding.UTF8, "application/json");

      string devId = "myDevId";
      string certId = "myCertId";

      using (var client = new HttpClient()) {
        client.DefaultRequestHeaders.Add("x-bonanzle-api-dev-name", devId);
        client.DefaultRequestHeaders.Add("x-bonanzle-api-cert-name", certId);

        var response = client.PostAsync(url, content).Result;
        string responseStr = response.Content.ReadAsStringAsync().Result;

        var responseJSON = JObject.Parse(responseStr);

        Console.WriteLine (responseJSON);

        var errorMessage = responseJSON["errorMessage"];
        if (errorMessage != null) {
          Console.WriteLine (errorMessage);
        }
      }
    }
  }
}

Data

jsonPayload's value (JSON):

{"keywords":"The King"}

jsonResponse's value (JSON):

{
    "timestamp":"2009-10-31T14:47:13.000Z",
    "version":"1.0",
    "findItemsByKeywordsResponse":{
        "paginationOutput":{
            "totalEntries":2471394,
            "pageNumber":1,
            "entriesPerPage":20
        },
        "item":[
            {
                "primaryCategory":{
                    "categoryName":"Clothing, Shoes amp; Accessories >> Unisex Clothing, Shoes amp; Accs >> Unisex Adult Clothing >> T-Shirts",
                    "categoryId":155193
                },
                "listingInfo":{
                    "price":9.99,
                    "convertedBuyItNowPrice":9.99,
                    "bestOfferEnabled":"true",
                    "listingType":"FixedPrice",
                    "buyItNowPrice":9.99,
                    "startTime":"2009-10-31T00:09:01.000Z",
                    "lastChangeTime":"2009-10-31T00:09:01.000Z"
                },
                "viewItemURL":"http://www.bonanza.com/booths/tshirt_seller_dev/items/CHESS__THE_KING__LOGO_Royal_Blue_T_SHIRT",
                "location":"CA",
                "title":"CHESS \"THE KING\" LOGO Royal Blue T-SHIRT",
                "sellerInfo":{
                    "feedbackRatingStar":"Blue",
                    "membershipLevel":null,
                    "sellerUserName":"T-Shirt Sellin' Deven",
                    "availableForChat":"false",
                    "userPicture":"http://s3.amazonaws.com/bonanzaimages/user_profile_image/afu/user_profile_images/â?¦.jpg",
                    "positiveFeedbackPercent":"100"
                },
                "itemId":7410001,
                "storeInfo":{
                    "storeName":"Deven's T-Shirt Shoppe",
                    "storeDiscount":null,
                    "storeURL":"http://www.bonanza.com/booths/tshirt_seller_dev",
                    "storeHasBonanza":"false",
                    "storeItemCount":6
                },
                "shippingInfo":{
                    "shippingServiceCost":2.99,
                    "shippingType":"Flat",
                    "shipToLocations":"US"
                },
                "sellingStatus":{
                    "convertedCurrentPrice":9.99,
                    "sellingState":"Active",
                    "currentPrice":9.99
                },
                "postalCode":"94536",
                "paymentMethod":["Paypal"],
                "galleryURL":"http://s3.amazonaws.com/bonanzaimages/afu/images/2889/3800/shirt-chess-king.jpg",
                "globalId":"Bonanza",
                "descriptionBrief":"This shirt is only for KINGS!"
            },
            {
                "primaryCategory":{
                    "categoryName":"Home amp; Garden",
                    "categoryId":11700
                },
                "listingInfo":{
                    "price":10.0,
                    "convertedBuyItNowPrice":10.0,
                    "bestOfferEnabled":"true",
                    "listingType":"FixedPrice",
                    "buyItNowPrice":10.0,
                    "startTime":"2009-10-31T00:04:35.000Z",
                    "lastChangeTime":"2009-10-31T00:04:35.000Z"
                },
                "viewItemURL":"http://www.bonanza.com/booths/â?¦",
                "location":"Bolingbrook, IL",
                "title":"Elvisâ?¦",
                "sellerInfo":{
                    "feedbackRatingStar":"Yellow",
                    "membershipLevel":null,
                    "sellerUserName":"â?¦",
                    "availableForChat":"false",
                    "userPicture":"http://s3.amazonaws.com/bonanzaimages/user_profile_image/afu/user_profile_images/â?¦.jpg",
                    "positiveFeedbackPercent":"100"
                },
                "itemId":7920002,
                "storeInfo":{
                    "storeName":"â?¦",
                    "storeDiscount":null,
                    "storeURL":"http://www.bonanza.com/booths/â?¦",
                    "storeHasBonanza":"false",
                    "storeItemCount":1
                },
                "shippingInfo":{
                    "shippingServiceCost":0,
                    "shippingType":"Free",
                    "shipToLocations":"US"
                },
                "sellingStatus":{
                    "convertedCurrentPrice":10.0,
                    "sellingState":"Active",
                    "currentPrice":10.0
                },
                "postalCode":"60446",
                "paymentMethod":["MOCC","Paypal"],
                "galleryURL":"http://s3.amazonaws.com/bonanzaimages/afu/images/â?¦",
                "globalId":"Bonanza",
                "descriptionBrief":"â?¦"
            },
            â?¦
        ]
    },
    "ack":"Success"
}

C# Example for fetchToken

Sample: User Token Fetching

Code

C# code to fetch a token:

using System;
using System.Net;
using System.Net.Http;
using System.IO;
using System.Text;
using System.Threading.Tasks;
using System.Collections.Generic;
using System.Text.RegularExpressions;
using System.Globalization;

using Newtonsoft.Json;
using Newtonsoft.Json.Linq;

namespace c_sharp_examples
{
  public class FetchTokenExample
  {
    public static void Main (string[] args)
    {
      var dataObject = new { fetchTokenRequest = new { } };

      string dataJSON = JsonConvert.SerializeObject(dataObject);

      var url = "https://api.bonanza.com/api_requests/secure_request";
      var content = new StringContent (dataJSON, Encoding.UTF8, "application/json");

      string devId = "myDevId";
      string certId = "myCertId";

      using (var client = new HttpClient()) {
        client.DefaultRequestHeaders.Add("x-bonanzle-api-dev-name", devId);
        client.DefaultRequestHeaders.Add("x-bonanzle-api-cert-name", certId);

        var response = client.PostAsync(url, content).Result;
        string responseStr = response.Content.ReadAsStringAsync().Result;

        var responseJSON = JObject.Parse(responseStr);

        Console.WriteLine (responseJSON);

        var errorMessage = responseJSON["errorMessage"];
        if (errorMessage != null) {
          Console.WriteLine (errorMessage);
        }
      }
    }
  }
}

Data

jsonResponse's value (JSON [formatted for legibility]):

{
  "ack": "Success",
  "version": "1.0beta",
  "timestamp": "2015-08-28T09:34:16Z",
  "fetchTokenResponse": {
    "authToken": "rXaGR1tCDv",
    "hardExpirationTime": "2016-08-28T09:34:16Z",
    "authenticationURL":"https://www.bonanza.com/login?apitoken=rXaGR1tCDv"
  }
}

C# Example for getCategories

Sample: Getting Categories

Code

C# code to get information of all children categories of the provided categoryID:

using System;
using System.Net;
using System.Net.Http;
using System.IO;
using System.Text;
using System.Threading.Tasks;
using System.Collections.Generic;
using System.Text.RegularExpressions;
using System.Globalization;

using Newtonsoft.Json;
using Newtonsoft.Json.Linq;

namespace c_sharp_examples
{
  public class GetCategoriesExample
  {
    public static void Main (string[] args)
    {
      var dataObject = new
      {
        getCategories = new
        {
          categoryParent = 2984
        }
      };
      
      string dataJSON = JsonConvert.SerializeObject(dataObject);

      var url = "http://api.bonanza.com/api_requests/standard_request";
      var content = new StringContent (dataJSON, Encoding.UTF8, "application/json");

      string devId = "myDevId";
      string certId = "myCertId";

      using (var client = new HttpClient()) {
        client.DefaultRequestHeaders.Add("x-bonanzle-api-dev-name", devId);
        client.DefaultRequestHeaders.Add("x-bonanzle-api-cert-name", certId);

        var response = client.PostAsync(url, content).Result;
        string responseStr = response.Content.ReadAsStringAsync().Result;

        var responseJSON = JObject.Parse(responseStr);

        Console.WriteLine (responseJSON);

        var errorMessage = responseJSON["errorMessage"];
        if (errorMessage != null) {
          Console.WriteLine (errorMessage);
        }
      }
    }
  }
}


Data

response_json's value (JSON [formatted for legibility]):

{
  "ack":"Success",
  "version":"1.0beta",
  "timestamp":"2015-01-14T16:47:26.000Z",
  "getCategoriesResponse":{
    "categoryArray":[
      {
        "categoryId":1261,
        "categoryLevel":2,
        "categoryName":"Baby >> Other",
        "leafCategory":"true",
        "categoryBriefName":"Other",
        "traitCount":4
      },
      {
        "categoryId":19068,
        "categoryLevel":2,
        "categoryName":"Baby >> Toys for Baby",
        "leafCategory":"false",
        "categoryBriefName":"Toys for Baby",
        "traitCount":4
      },
      {
        "categoryId":20394,
        "categoryLevel":2,
        "categoryName":"Baby >> Bathing & Grooming",
        "leafCategory":"false",
        "categoryBriefName":"Bathing & Grooming",
        "traitCount":4
      }
    ]
  }
}

C# Example for getOrders

Sample: Getting Orders

Code

C# code to get order information for a seller in a specific time period

using System;
using System.Net;
using System.Net.Http;
using System.IO;
using System.Text;
using System.Threading.Tasks;
using System.Collections.Generic;
using System.Text.RegularExpressions;
using System.Globalization;

using Newtonsoft.Json;
using Newtonsoft.Json.Linq;

namespace c_sharp_examples
{
  public class GetOrdersExample
  {
    public static void Main (string[] args)
    {
      var dataObject = new {
        getOrdersRequest = new {
          requesterCredentials = new {
            bonanzleAuthToken = "anAuthToken"
          },
          orderRole = "Seller"
        }
      };

      string dataJSON = JsonConvert.SerializeObject(dataObject);

      var url = "http://api.bonanza.com/api_requests/secure_request";
      var content = new StringContent (dataJSON, Encoding.UTF8, "application/json");

      string devId = "myDevId";
      string certId = "myCertId";

      using (var client = new HttpClient()) {
        client.DefaultRequestHeaders.Add("x-bonanzle-api-dev-name", devId);
        client.DefaultRequestHeaders.Add("x-bonanzle-api-cert-name", certId);

        var response = client.PostAsync(url, content).Result;
        string responseStr = response.Content.ReadAsStringAsync().Result;

        var responseJSON = JObject.Parse(responseStr);

        Console.WriteLine (responseJSON);

        var errorMessage = responseJSON["errorMessage"];
        if (errorMessage != null) {
          Console.WriteLine (errorMessage);
        }
      }
    }
  }
}

Data

jsonResponse's value (JSON [formatted for legibility]):

{
  "ack":"Success",
  "version":"1.0beta",
  "timestamp":"2015-01-14T16:55:25.000Z",
  "getOrdersResponse":{
    "orderArray":[
      {
        "order":{
          "amountPaid":"104.32",
          "amountSaved":0.0,
          "buyerCheckoutMessage":"",
          "buyerUserID":6157,
          "buyerUserName":"JDoe",
          "checkoutStatus":{
            "status":"Complete"
          },
          "createdTime":"2013-04-25T16:54:25Z",
          "creatingUserRole":"Buyer",
          "itemArray":[
            {
              "item":{
                "itemID":205172,
                "sellerInventoryID":null,
                "sku":null,
                "title":"76 Blank DVD Cases",
                "price":"24.0",
                "quantity":1
              }
            }
          ],
          "orderID":1811,
          "orderStatus":"Shipped",
          "subtotal":24.0,
          "taxAmount":0.0,
          "total":"104.32",
          "transactionArray":{
            "transaction":{
              "buyer":{
                "email":"testy@bonanza.com"
              },
            "providerName":"Checkout by Amazon",
            "providerID":"104-1031316-4215451",
            "finalValueFee":"3.3"
            }
          },
          "paidTime":"2013-04-25T17:08:24Z",
          "shippedTime":"2014-04-28T23:19:08Z",
          "shippingAddress":{
            "addressID":6710,
            "cityName":"SEATTLE",
            "country":"US",
            "countryName":null,
            "name":"Test User",
            "postalCode":"98122-90210",
            "stateOrProvince":"WA",
            "street1":null,
            "street2":null
          },
          "shippingDetails":{
            "insuranceFee":0,
            "amount":"81.52",
            "servicesArray":[],
            "shippingService":"Standard shipping"
          }
        }
      }],
    "hasMoreOrders":"false",
    "paginationResult":{
      "totalNumberOfEntries":2,
      "totalNumberOfPages":1
    },
    "pageNumber":1
  }
}

C# Example for addFixedPriceItem

Sample: Adding an Item

Code

C# code to add an item


using System;
using System.Net;
using System.Net.Http;
using System.IO;
using System.Text;
using System.Threading.Tasks;
using System.Collections.Generic;
using System.Text.RegularExpressions;
using System.Globalization;

using Newtonsoft.Json;
using Newtonsoft.Json.Linq;

namespace c_sharp_examples
{
  public class AddFixedPriceItemExample
  {
    public static void Main (string[] args)
    {
      List<object> pictureURL = new List<object>();

      pictureURL.Add ("http://images.discountstarwarscostumes.com/products/9284/1-1/luke-skywalker-blue-lightsaber.jpg");
      pictureURL.Add ("http://www.rankopedia.com/CandidatePix/29862.gif");

      List<object> itemSpecifics = new List<object>();

      itemSpecifics.Add (new string[]{"condition", "used"});
      itemSpecifics.Add (new string[]{"danger", "extreme"});

      List<object> variationList1 = new List<object> {
        new { 
          name = "Colour",
          value = "Blue" 
        },
        new {
          name = "Style",
          value = "Single"
        }
      };

      List<object> variationList2 = new List<object> {
        new { 
          name = "Colour",
          value = "Red"
        },
        new { 
          name = "Style",
          value = "Double"
        }
      };

      List<object> variations = new List<object> {
        new {
          quantity = 4,
          nameValueList = variationList1
        },
        new {
          quantity = 7,
          nameValueList = variationList2
        }
      };

      var dataObject = new {
        addFixedPriceItemRequest = new {
          requesterCredentials = new {
            bonanzleAuthToken = "anAuthToken"
          },
          item = 
          (object)new {
            title = "Lightsaber",
            primaryCategory = new {
              categoryId = 163128
            },
            description = "An elegant weapon, for a more civilized age<br>* SELLER <strong>NOT LIABLE</strong> FOR DISMEMBERMENT *",
            itemSpecifics,
            price = 42,
            quantity = 3,
            shippingType = "Free",
            pictureDetails = new {
              pictureURL
            },
            variations
          }
        }
      };

      string dataJSON = JsonConvert.SerializeObject(dataObject);

      var url = "https://api.bonanza.com/api_requests/secure_request";
      var content = new StringContent (dataJSON, Encoding.UTF8, "application/json");

      string devId = "myDevId";
      string certId = "myCertId";

      using (var client = new HttpClient()) {
        client.DefaultRequestHeaders.Add("x-bonanzle-api-dev-name", devId);
        client.DefaultRequestHeaders.Add("x-bonanzle-api-cert-name", certId);

        var response = client.PostAsync(url, content).Result;
        string responseStr = response.Content.ReadAsStringAsync().Result;

        var responseJSON = JObject.Parse(responseStr);

        Console.WriteLine (responseJSON);

        var errorMessage = responseJSON["errorMessage"];
        if (errorMessage != null) {
          Console.WriteLine (errorMessage);
        }
      }
    }
  }
}

Data

jsonResponse's value (JSON [formatted for legibility] ):

{
        "ack":"Success",
        "version":"1.0beta",
        "timestamp":"2015-01-14T17:05:23.000Z",
        "addFixedPriceItemResponse":{
                "itemId":206013,
                "categoryId":163128,
                "sellingState":"Ready for sale",
                "message":null
        }
}