BricklinkSharp is a strongly-typed, easy-to-use C# client for the bricklink marketplace that gets you started with just a few lines of code. It features OAuth1 authentication, error handling and parsing of JSON data into typed instances. It supports all .NET platforms compatible with .NET standard 2.0.
- Covers all public API endpoints
- New Assembly versioning:
- Assembly Version: 1.0.0.0
- Assembly File Version: 1.0.0.<build ID>
- Assembly Informational File Version: 1.0.0-<build time>+<build date>
- New method on IBricklinkClient: GetMinifigImage. Builds and returns the image URL for a specific minifigure number.
- New method on IBricklinkClient: GetSetImage. Builds and returns the image URL for a specific set number.
- Fixed: OrderMessage.Subject can be Null. Thanks to aalex675 for his contribution.
- New method on IBricklinkClient: GetPartImageForColor. Builds and returns the image URL for a specific part number / color ID.
- New helper method on IBricklinkClient: EnsureImageUrlScheme. Adds (ensures) an URI scheme on image URLs returned by the Bricklink API.
- Coupons
- Nullable annotations
- Renamed UpdatedInventory container to UpdateInventory (breaking)
- Order
- IBricklinkClient implements IDisposable and manages one instance of HttpClient
- Feedback
- Member / Get member rating
- Push Notification
- Setting / Shipping methods
- Renamed IBricklinkClient.GetItemNumber to IBricklinkClient.GetItemNumberAsync (breaking)
- Renamed IBricklinkClient.GetElementId to IBricklinkClient.GetElementIdAsync (breaking)
- User Inventory
- Item Mapping
- OAuth1 handling
- Catalog Item
- Color
- Category
Check out the demo project for full-featured examples.
You need to be registered on bricklink as a seller. Then, use this link to add an access token. Add your client IP address (if applicable) or 0.0.0.0 for both IP address and mask to be able to make API requests from any IP.
Install-Package BricklinkSharp
nuget install BricklinkSharp
BricklinkClientConfiguration.Instance.TokenValue = "<Your Token>";
BricklinkClientConfiguration.Instance.TokenSecret = "<Your Token Secret>";
BricklinkClientConfiguration.Instance.ConsumerKey = "<Your Consumer Key>";
BricklinkClientConfiguration.Instance.ConsumerSecret = "<Your Consumer Secret>";
var client = BricklinkClientFactory.Build();
It's recommended to create and use one IBricklinkClient client throughout the lifetime of your application.
In applications using an IoC container you may register the IBricklinkClient as a service and inject it into consuming instances (e.g. controllers). See the below examples to register the IBricklinkClient as single instance (Singleton).
Autofac example
containerBuilder.Register(c => BricklinkClientFactory.Build())
.As<IBricklinkClient>()
.SingleInstance();
services.AddSingleton(typeof(IBricklinkClient), provider =>
{
return BricklinkClientFactory.Build();
});
var catalogItem = await client.GetItemAsync(ItemType.Part, "6089");
var catalogImage = await client.GetItemImageAsync(ItemType.OriginalBox, "1-12", 0);
var colorId = 34; //Lime.
var uri = client.GetPartImageForColor("43898pb006", 34);
var uri = client.GetMinifigImage("sw1093");
var uri = client.GetSetImage("6090-1");
var uri = client.EnsureImageUrlScheme("//img.bricklink.com/ItemImage/PN/34/43898pb006.png", "https");
Console.WriteLine(uri.ToString());
//Prints: https://img.bricklink.com/ItemImage/PN/34/43898pb006.png
var supersets = await client.GetSupersetsAsync(ItemType.Minifig, "aqu004", 0);
var subsets = await client.GetSubsetsAsync(ItemType.Set, "1095-1", breakMinifigs: false);
var priceGuide = await client.GetPriceGuideAsync(ItemType.Part, "3003", colorId: 1, priceGuideType: PriceGuideType.Sold, condition: Condition.Used);
var knownColors = await client.GetKnownColorsAsync(ItemType.Part, "3006");
var colors = await client.GetColorListAsync();
var color = await client.GetColorAsync(15);
var categories = await client.GetCategoryListAsync();
var category = await client.GetCategoryAsync(1);
//Include only parts and minifigs.
var includedTypes = new List<ItemType> { ItemType.Part, ItemType.Minifig };
//Exclude all inventories which are unavailable.
var excludedStatusFlags = new List<InventoryStatusType> { Unavailable };
var inventories = await client.GetInventoryListAsync(includedTypes, excludedStatusFlags: excludedStatusFlags);
var newInventory = new NewInventory
{
ColorId = 1,
Condition = Condition.Used,
Item = new ItemBase
{
Number = "3003",
Type = ItemType.Part
},
Quantity = 5,
UnitPrice = 0.01M,
Description = "Good used condition"
};
var inventory = await client.CreateInventoryAsync(newInventory);
var newInventories = new NewInventory[] { //fill with inventories... };
//Note that there will be no response data.
await client.CreateInventoriesAsync(newInventories);
var inventoryList = await client.GetInventoryListAsync();
var id = inventoryList.First().InventoryId;
var updateInventory = new UpdateInventory { ChangedQuantity = 21, Remarks = "Remarks added." };
var inventory = await client.UpdateInventoryAsync(id, updateInventory);
var inventoryList = await client.GetInventoryListAsync();
var id = inventoryList.First().InventoryId;
await client.DeleteInventoryAsync(id);
The method returns an array of ItemMapping objects. If a color ID is specified the array will contain just one element. Otherwise the array will contain mappings for every available color.
var itemMappings = await client.GetElementIdAsync("3003", 1);
var itemMapping = await client.GetItemNumberAsync("300301");
var notifications = await client.GetNotificationsAsync();
var shippingMethods = await client.GetShippingMethodListAsync();
var shippingMethod = await client.GetShippingMethodAsync(123);
var rating = await client.GetMemberRatingAsync("bluser");
var feedbackInList = await client.GetFeedbackListAsync(FeedbackDirection.In);
var feedbackOutList = await client.GetFeedbackListAsync(FeedbackDirection.Out);
var feedbackListAll = await client.GetFeedbackListAsync();
var feedbackListAll = await client.GetFeedbackListAsync()
var id = feedbackListAll.First().FeedbackId;
var feedback = await client.GetFeedbackAsync(id);
var orderId = 1234567; //Must be a valid order ID.
var feedback = await client.PostFeedbackAsync(orderId, RatingType.Praise, "Awesome transaction, praise!");
var feedbackId = 1234567; //Must be a valid feedback ID.
await client.ReplyFeedbackAsync(feedbackId, "Thank you for your kind comment.");
//Exclude all purged orders.
var orders = await client.GetOrdersAsync(OrderDirection.Out, excludedStatusFlags: new List<OrderStatus>
{
OrderStatus.Purged
});
//Only paid orders that must be shipped.
var orders = await client.GetOrdersAsync(OrderDirection.Out, excludedStatusFlags: new List<OrderStatus>
{
OrderStatus.Paid
});
var orderId = 123456789; //Must be a valid order ID.
var order = await client.GetOrderAsync(orderId);
var orderId = 1234566789; //Must be a valid order ID.
var itemsBatchList = await client.GetOrderItemsAsync(orderId);
foreach (var itemsBatch in itemsBatchList)
{
foreach (var item in itemsBatch)
{
//Process item...
}
}
var orderId = 123456789; //Must be a valid order ID.
var messages = await client.GetOrderMessagesAsync(orderId);
var orderId = 123456789; //Must be a valid order ID.
var feedbacks = await client.GetOrderFeedbackAsync(orderId);
var orderId = 123456789; //Must be a valid order ID.
//Note: you must only set properties which should be updated. Leave all others Null.
var updateOrder = new UpdateOrder();
updateOrder.Remarks = "Add remark";
updateOrder.IsFiled = true;
updateOrder.Cost.Insurance = 2.5m;
updateOrder.Cost.Etc1 = 1.0m;
updateOrder.Shipping.TrackingNo = "1234567892";
updateOrder.Shipping.TrackingLink = "www.foo.bar/123456789";
await client.UpdateOrder(orderId, updateOrder);
var orderId = 123456789; //Must be a valid order ID.
try
{
//Note that the order must be outgoing in order to be able to set it to 'Shipped'.
await client.UpdateOrderStatusAsync(orderId, OrderStatus.Shipped);
}
catch (Exception exception)
{
//Handle invalid operation.
}
var orderId = 123456789; //Must be a valid order ID.
try
{
//Note that the order must be outgoing in order to be able to set it to 'Received'.
await client.UpdatePaymentStatusAsync(orderId, PaymentStatus.Received);
}
catch (Exception exception)
{
//Handle invalid operation.
}
var orderId = 123456789; //Must be a valid order ID.
try
{
await client.SendDriveThruAsync(orderId, true);
}
catch (Exception exception)
{
//Handle invalid operation.
}
var includesStatusTypes = new List<CouponStatus>
{
CouponStatus.Open
}
var coupons = await client.GetCouponsAsync(Direction.Out, includedCouponStatusTypes: includesStatusTypes);
var couponId = 123456789; //Must be a valid coupon ID.
var coupon = await client.GetCouponAsync(couponId);
var newCoupon = new NewCoupon("bluser", "Special gift for you")
{
DiscountType = DiscountType.Percentage,
DiscountRate = 10
};
newCoupon.AppliesTo.ExceptOnSale = true;
newCoupon.AppliesTo.RestrictionType = CouponRestrictionType.ApplyToSpecifiedItemType;
newCoupon.AppliesTo.ItemType = ItemType.Part; //Only applies to parts.
var coupon = await client.CreateCouponAsync(newCoupon);
var updateCoupon = new UpdateCoupon
{
DiscountType = DiscountType.Percentage,
DiscountRate = 15 //Increase discount rate to 15 percent.
};
var couponId = 123456789; //Must be a valid coupon ID.
var coupon = await client.UpdateCouponAsync(couponId, updateCoupon);
var couponId = 123456789; //Must be a valid coupon ID.
await client.DeleteCouponAsync(couponId);