This guide provides complete C# .Net code examples for working with the Mintsoft API. You'll find modern HttpClient-based examples covering the most common API operations, including creating orders, managing products, and retrieving stock levels.
Important: You'll need your Mintsoft API key to use these examples. If you don't have an API key, contact your system administrator or Mintsoft support to obtain one.
Setup and authentication
The following example shows how to set up the base API client with authentication:
C#
using System;
using System.Net.Http;
using System.Net.Http.Headers;
using System.Text;
using System.Text.Json;
using System.Threading.Tasks;
using System.Collections.Generic;
namespace MintsoftApiExamples
{
public class MintsoftApiClient
{
private readonly HttpClient _httpClient;
private readonly string _baseUrl;
private readonly string _apiKey;
public MintsoftApiClient(string baseUrl, string apiKey)
{
_baseUrl = baseUrl.TrimEnd('/');
_apiKey = apiKey;
_httpClient = new HttpClient
{
BaseAddress = new Uri(_baseUrl),
Timeout = TimeSpan.FromSeconds(60)
};
// Set required headers for Mintsoft API
_httpClient.DefaultRequestHeaders.Add("Ms-Apikey", _apiKey);
_httpClient.DefaultRequestHeaders.Accept.Add(
new MediaTypeWithQualityHeaderValue("application/json"));
}
// Helper method for making API requests
private async Task<T> SendRequestAsync<T>(
HttpMethod method,
string endpoint,
object body = null)
{
try
{
var request = new HttpRequestMessage(method, endpoint);
if (body != null)
{
var json = JsonSerializer.Serialize(body, new JsonSerializerOptions
{
PropertyNamingPolicy = JsonNamingPolicy.CamelCase,
DefaultIgnoreCondition = System.Text.Json.Serialization.JsonIgnoreCondition.WhenWritingNull
});
request.Content = new StringContent(json, Encoding.UTF8, "application/json");
}
var response = await _httpClient.SendAsync(request);
var content = await response.Content.ReadAsStringAsync();
if (!response.IsSuccessStatusCode)
{
throw new HttpRequestException(
$"API request failed with status {response.StatusCode}: {content}");
}
return JsonSerializer.Deserialize<T>(content, new JsonSerializerOptions
{
PropertyNameCaseInsensitive = true
});
}
catch (Exception ex)
{
Console.WriteLine($"Error calling API: {ex.Message}");
throw;
}
}
}
}
Order operations
This section covers creating, retrieving, updating, and searching for orders through the Mintsoft API.
Create an order
You can create new orders in Mintsoft using the following code:
C#
public class CreateOrderRequest
{
public string OrderNumber { get; set; }
public string ExternalOrderReference { get; set; }
public string FirstName { get; set; }
public string LastName { get; set; }
public string CompanyName { get; set; }
public string Address1 { get; set; }
public string Address2 { get; set; }
public string Town { get; set; }
public string County { get; set; }
public string PostCode { get; set; }
public string Country { get; set; }
public int? CountryId { get; set; }
public string Email { get; set; }
public string Phone { get; set; }
public int? ChannelId { get; set; }
public int? WarehouseId { get; set; }
public int? CourierServiceId { get; set; }
public decimal? OrderValue { get; set; }
public int? ClientId { get; set; }
public List<OrderItem> OrderItems { get; set; }
}
public class OrderItem
{
public string SKU { get; set; }
public int? ProductId { get; set; }
public int Quantity { get; set; }
public decimal? UnitPrice { get; set; }
public decimal? UnitPriceVat { get; set; }
}
public class CreateOrderResponse
{
public int? OrderId { get; set; }
public string OrderNumber { get; set; }
public bool Success { get; set; }
public string Message { get; set; }
public int? OrderStatusId { get; set; }
public string OrderStatus { get; set; }
}
// In MintsoftApiClient class:
public async Task<List<CreateOrderResponse>> CreateOrderAsync(CreateOrderRequest order)
{
return await SendRequestAsync<List<CreateOrderResponse>>(
HttpMethod.Put,
"/Order",
order);
}
Get order details
You can retrieve complete order information using an order ID:
C#
public class Order
{
public int ID { get; set; }
public string OrderNumber { get; set; }
public string ExternalOrderReference { get; set; }
public string FirstName { get; set; }
public string LastName { get; set; }
public string Email { get; set; }
public string Address1 { get; set; }
public string Town { get; set; }
public string PostCode { get; set; }
public string Country { get; set; }
public decimal OrderValue { get; set; }
public string OrderStatus { get; set; }
public DateTime? OrderDate { get; set; }
public List<OrderItem> OrderItems { get; set; }
}
// In MintsoftApiClient class:
public async Task<Order> GetOrderAsync(int orderId)
{
return await SendRequestAsync<Order>(
HttpMethod.Get,
$"/Order/{orderId}");
}
Update order status
You can change the status of orders using these methods:
C#
// In MintsoftApiClient class:
public async Task<object> MarkOrderConfirmedAsync(int orderId)
{
return await SendRequestAsync<object>(
HttpMethod.Get,
$"/Order/{orderId}/MarkConfirmed");
}
public async Task<object> MarkOrderDespatchedAsync(int orderId)
{
return await SendRequestAsync<object>(
HttpMethod.Get,
$"/Order/{orderId}/MarkDespatched");
}
public async Task<object> CancelOrderAsync(int orderId)
{
return await SendRequestAsync<object>(
HttpMethod.Get,
$"/Order/{orderId}/Cancel");
}
Search orders
You can search for orders using various criteria:
C#
public class OrderSearchRequest
{
public string OrderNumber { get; set; }
public string CustomerName { get; set; }
public string Email { get; set; }
public DateTime? OrderDateFrom { get; set; }
public DateTime? OrderDateTo { get; set; }
public int? OrderStatusId { get; set; }
public int? ChannelId { get; set; }
}
public class OrderSearchResponse
{
public int ID { get; set; }
public string OrderNumber { get; set; }
public string CustomerName { get; set; }
public string OrderStatus { get; set; }
public DateTime OrderDate { get; set; }
public decimal OrderValue { get; set; }
}
// In MintsoftApiClient class:
public async Task<List<OrderSearchResponse>> SearchOrdersAsync(OrderSearchRequest searchCriteria)
{
return await SendRequestAsync<List<OrderSearchResponse>>(
HttpMethod.Post,
"/Order/Search",
searchCriteria);
}
Product operations
This section covers creating, retrieving, and searching for products in Mintsoft.
Create a product
You can add new products to your Mintsoft catalogue:
C#
public class CreateProductRequest
{
public string SKU { get; set; }
public string Name { get; set; }
public string Description { get; set; }
public string EAN { get; set; }
public decimal? Weight { get; set; }
public decimal? Height { get; set; }
public decimal? Width { get; set; }
public decimal? Depth { get; set; }
public decimal? Price { get; set; }
public decimal? CostPrice { get; set; }
public int ClientId { get; set; }
public bool HasExpiryDate { get; set; }
public bool HasBatchNumber { get; set; }
public bool HasSerialNumber { get; set; }
}
public class CreateProductResponse
{
public bool Success { get; set; }
public string Message { get; set; }
public int? ProductId { get; set; }
}
// In MintsoftApiClient class:
public async Task<CreateProductResponse> CreateProductAsync(CreateProductRequest product)
{
return await SendRequestAsync<CreateProductResponse>(
HttpMethod.Put,
"/Product",
product);
}
Get product details
You can retrieve complete product information using a product ID:
C#
public class Product
{
public int ID { get; set; }
public string SKU { get; set; }
public string Name { get; set; }
public string Description { get; set; }
public string EAN { get; set; }
public decimal? Weight { get; set; }
public decimal? Price { get; set; }
public decimal? CostPrice { get; set; }
public int? LowStockAlertLevel { get; set; }
}
// In MintsoftApiClient class:
public async Task<Product> GetProductAsync(int productId)
{
return await SendRequestAsync<Product>(
HttpMethod.Get,
$"/Product/{productId}");
}
Search products
You can search for products using SKU, name, or EAN:
C#
public class ProductSearchRequest
{
public string SKU { get; set; }
public string Name { get; set; }
public string EAN { get; set; }
}
public class ProductSearchResponse
{
public int ID { get; set; }
public string SKU { get; set; }
public string Name { get; set; }
public decimal? Price { get; set; }
public int? StockLevel { get; set; }
}
// In MintsoftApiClient class:
public async Task<List<ProductSearchResponse>> SearchProductsAsync(ProductSearchRequest searchCriteria)
{
return await SendRequestAsync<List<ProductSearchResponse>>(
HttpMethod.Post,
"/Product/Search",
searchCriteria);
}
Stock level operations
You can retrieve current stock levels for products across your warehouses.
Get stock levels
C#
public class StockLevelRequest
{
public string SKU { get; set; }
public int? WarehouseId { get; set; }
}
public class StockLevelResponse
{
public string SKU { get; set; }
public int ProductId { get; set; }
public int WarehouseId { get; set; }
public string WarehouseName { get; set; }
public int Available { get; set; }
public int OnHand { get; set; }
public int Allocated { get; set; }
}
// In MintsoftApiClient class:
public async Task<List<StockLevelResponse>> GetStockLevelsAsync(StockLevelRequest request)
{
return await SendRequestAsync<List<StockLevelResponse>>(
HttpMethod.Post,
"/Stock/StockLevels",
request);
}
Key points
When working with the Mintsoft API, keep these important details in mind:
Authentication: Use the Ms-Apikey header with your API key.
Base URL: https://api.mintsoft.co.uk/api
Content type: Always use application/json.
HTTP methods: Use PUT for creating resources, GET for retrieving data, POST for searches and some updates, and DELETE for removing resources.
Error handling: Always wrap API calls in try-catch blocks.
Async/await: Use asynchronous methods for better performance.
