BarcodesDocs

V1 (Legacy)

This is documentation for V1 of the API, which is no longer maintained. Use the V2 documentation for new integrations.

Barcodes API Wrapper for C#

Amplify your C# projects by integrating the Barcodes.GG API. Our C# SDK is crafted to offer a smooth and efficient integration experience. Follow the steps below and dive into the world of barcodes.

Prerequisites

Your C# project should have the Newtonsoft.Json library. Install it via NuGet if you haven't already:

Install-Package Newtonsoft.Json

SDK Wrapper Code

using System.Net.Http;
using Newtonsoft.Json.Linq;

public class BarcodesAPI
{
    private readonly string apiKey;
    private const string BaseUrl = "https://barcodes.gg/api";
    private readonly HttpClient httpClient;

    public BarcodesAPI(string apiKey)
    {
        this.apiKey = apiKey;
        httpClient = new HttpClient();
        httpClient.DefaultRequestHeaders.Add("Authorization", $"Bearer {apiKey}");
    }

    private async Task<JObject> MakeRequest(string endpoint)
    {
        var response = await httpClient.GetAsync(BaseUrl + endpoint);
        var content = await response.Content.ReadAsStringAsync();
        return JObject.Parse(content);
    }

    public Task<JObject> SearchProducts(string query)
    {
        return MakeRequest($"/product/search?query={query}");
    }

    public Task<JObject> LookupBarcode(string ean, int showData = 1, string fields = "*")
    {
        return MakeRequest($"/barcode/lookup/{ean}?show_data={showData}&fields={fields}");
    }

    public Task<JObject> GetImage(string styleCode)
    {
        return MakeRequest($"/image/{styleCode}");
    }

    public Task<JObject> ReverseLookupBySKU(string sku, int isVerified = 1, int page = 1)
    {
        return MakeRequest($"/barcode/lookup/sku/{sku}?is_verified={isVerified}&page={page}");
    }
}

Integration Steps

  1. Initialization: Kickstart the process by initializing the BarcodesAPI class.
var api = new BarcodesAPI("YOUR_API_KEY");

Remember to replace "YOUR_API_KEY" with your genuine API key.

  1. Product Search: Explore the vast product database with a succinct query.
var result = api.searchProducts("dd1503-100").Result;
Console.WriteLine(result);
  1. Barcode Lookup: Delve into product specifics using its unique barcode.
var result = api.lookupBarcode("195245980597").Result;
Console.WriteLine(result);
  1. Image Retrieval: Acquire product images with ease using the style code.
var result = api.getImage("DH4756-100").Result;
Console.WriteLine(result);
  1. SKU-based Reverse Barcode Lookup: Navigate the barcode landscape using SKU as your compass.
var result = api.reverseLookupBySKU("DD1391-100").Result;
Console.WriteLine(result);

Each method returns a JObject, making it convenient to handle and process the response as you deem fit.

Step into the future of barcode integrations with C#.