A comprehensive .NET client library for the PS in foodservice Web API. Licensed for use by authorized PS in foodservice customers only.
License
—
Deps
22
Install Size
—
Vulns
✓ 0
Published
Apr 7, 2025
$ dotnet add package PSinfoodserviceA comprehensive C# client library for the PS in foodservice Web API (v7). This package simplifies integration with PS in foodservice services by providing a clean, type-safe interface for all API endpoints.
Install the package via NuGet:
Install-Package PSinfoodservice
Or via the .NET CLI:
dotnet add package PSinfoodservice
using PSinfoodservice;
using System;
using System.Threading.Tasks;
namespace YourApplication
{
class Program
{
static async Task Main(string[] args)
{
// Initialize the client
var client = new PSinfoodserviceClient(PSinfoodservice.Domain.PSEnvironment.Test);
try {
// Authenticate
var loginResponse = await client.Authentication.Login("your-email@example.com", "your-password");
if (loginResponse.IsSuccess && loginResponse?.Data == true) {
Console.WriteLine("Authentication successful!");
// Get product information
var productSheetResponse = await client.WebApi.GetProductSheet(59, PSinfoodservice.Enum.OutputType.All);
if (productSheetResponse.IsSuccess) {
Console.WriteLine($"Product name: {productSheetResponse.Data.Summary.Name.FirstOrDefault(p => p.Language == PSinfoodservice.Dtos.Language.nl).Value}");
}
}
} catch (Exception ex) {
Console.WriteLine($"Error: {ex.Message}");
}
}
}
}
For complete API documentation, visit the PS in foodservice API Documentation.
The client is organized into multiple modules, each handling a specific part of the API:
var client = new PSinfoodserviceClient(PSinfoodservice.Domain.PSEnvironment.Test);
var loginResponse = await client.Authentication.Login("your-email@example.com", "your-password");
if (loginResponse.IsSuccess && loginResponse?.Data == true) {
Console.WriteLine("Successfully logged in!");
} else {
Console.WriteLine($"Login failed! Error: {loginResponse.ErrorMessage}");
}
// Get product sheet
var productSheetResponse = await client.WebApi.GetProductSheet(59, PSinfoodservice.Enum.OutputType.All);
if (productSheetResponse.IsSuccess) {
Console.WriteLine("Successfully retrieved product sheet!");
Console.WriteLine($"Summary name: {productSheetResponse.Data.Summary.Name.FirstOrDefault(p => p.Language == PSinfoodservice.Dtos.Language.nl).Value}");
}
// Get ingredients information
var ingredientsResponse = client.Helper.GetIngredientsPreview(productSheetResponse.Data, PSinfoodservice.Dtos.Language.nl);
if (ingredientsResponse != null && ingredientsResponse.IsSuccess) {
Console.WriteLine($"Ingredients declaration: {ingredientsResponse.Data.DeclarationPreview}");
}
// Get allergen information with bootstrap formatting
var allergenResponse = client.Helper.GetAllergensPreview(
productSheetResponse.Data,
false, // simplified information
PSinfoodservice.Dtos.Language.nl,
PSNetPackage.Domain.Outputstyle.Bootstrap
);
if (allergenResponse.IsSuccess) {
Console.WriteLine($"Allergens:");
Console.Write(allergenResponse.Data);
}
// Get allergen information with table formatting
var extendedAllergenResponse = client.Helper.GetAllergensPreview(
productSheetResponse.Data,
true, // extended information
PSinfoodservice.Dtos.Language.nl,
PSNetPackage.Domain.Outputstyle.Table
);
var nutrientsResponse = client.Helper.GetNutrientsPreview(
productSheetResponse.Data,
PSinfoodservice.Dtos.Language.nl,
PSNetPackage.Domain.Outputstyle.Table
);
if (nutrientsResponse.IsSuccess) {
Console.WriteLine($"Nutrients:");
Console.Write(nutrientsResponse.Data);
}
var preparationInformationResponse = client.Helper.GetPreparationInformationPreview(
productSheetResponse.Data,
PSinfoodservice.Dtos.Language.nl
);
if (preparationInformationResponse != null && preparationInformationResponse.IsSuccess) {
Console.WriteLine("Preparation Information:");
foreach (var item in preparationInformationResponse.Data) {
Console.WriteLine($"Type: {item.PreparationType}");
Console.WriteLine($"Description: {item.Description}");
}
}
// Get all impact scores
var impactScoreResponse = await client.ImpactScore.AllScores();
if (impactScoreResponse.IsSuccess) {
Console.WriteLine("Successfully retrieved impact scores!");
foreach (var impactScore in impactScoreResponse.Data.ImpactScore) {
Console.WriteLine($"Impact score (CradleToGate): {impactScore.CradleToGate}");
}
}
// Get specific product impact score
var productImpactScoreResponse = await client.ImpactScore.GetScore(59);
if (productImpactScoreResponse.IsSuccess) {
Console.WriteLine($"Product Impact Score: {productImpactScoreResponse.Data.Score}");
}
// Get all masters
var allMasterResponse = await client.Masters.GetAllMasters();
if (allMasterResponse.IsSuccess) {
Console.WriteLine("Successfully retrieved masters!");
// Access tax rates or other master data
foreach (var taxRate in allMasterResponse.Data.masters.TaxRates) {
var name = taxRate.Name.First(p => p.Language == PSinfoodservice.Dtos.Language.nl).Value;
Console.WriteLine($"Tax Rate: {name}");
}
}
// Get logistic masters
var logisticMasterResponse = await client.Masters.GetLogisticMasters();
if (logisticMasterResponse.IsSuccess) {
Console.WriteLine("Successfully retrieved logistic masters!");
foreach (var taxRate in logisticMasterResponse.Data.Masters.TaxRates) {
Console.WriteLine($"Tax Rate: {taxRate.Name.First(p => p.Language == PSinfoodservice.Dtos.Language.nl).Value}");
}
}
// Get my brands
var brandsResponse = await client.Brands.MyBrands();
if (brandsResponse.IsSuccess) {
Console.WriteLine("Successfully retrieved brands!");
foreach (var brand in brandsResponse.Data.Brands) {
Console.WriteLine($"Brand: {brand.Name}");
}
}
// Get updates based on EAN codes
var updateResponse = await client.Updates.Ean(new PSinfoodservice.Dtos.Incoming.RequestUpdateEANDto {
LastUpdatedAfter = DateTime.Now.AddDays(-30),
SearchCriteria = new[] { "1236547892138", "12365478921381", "1236547892139" },
TargetMarket = PSinfoodservice.Enum.TargetMarkets.All
});
if (updateResponse.IsSuccess) {
Console.WriteLine("Successfully retrieved updates!");
Console.WriteLine("Changed:");
foreach (var item in updateResponse.Data.Changed) {
Console.WriteLine($"- {item.GTIN}");
}
Console.WriteLine("Not Changed:");
foreach (var item in updateResponse.Data.NotChanged) {
Console.WriteLine($"- {item.GTIN}");
}
Console.WriteLine("Not Found:");
foreach (var ean in updateResponse.Data.NotFound) {
Console.WriteLine($"- {ean}");
}
Console.WriteLine("Deleted:");
foreach (var item in updateResponse.Data.Deleted) {
Console.WriteLine($"- {item.GTIN}");
}
}
// Get product image
var imageResponse = await client.Image.GetImage(1, Guid.Empty, 500, 500);
if (imageResponse != null && imageResponse.IsSuccess) {
Console.WriteLine($"Content Type: {imageResponse.Data.ContentType}");
Console.WriteLine($"Image Size: {imageResponse.Data.Content.Length} bytes");
// Save the image
if (imageResponse.Data.Content.Length > 0) {
string extension = GetExtensionFromContentType(imageResponse.Data.ContentType);
string filePath = Path.Combine(Path.GetTempPath(), $"image_{Guid.NewGuid()}{extension}");
await File.WriteAllBytesAsync(filePath, imageResponse.Data.Content);
Console.WriteLine($"Image saved to: {filePath}");
}
}
// Helper method to determine file extension
private static string GetExtensionFromContentType(string contentType) {
return contentType.ToLower() switch {
"image/jpeg" => ".jpg",
"image/png" => ".png",
"image/gif" => ".gif",
"image/bmp" => ".bmp",
"image/tiff" => ".tiff",
"image/webp" => ".webp",
_ => ".jpg"
};
}
The package includes comprehensive error handling with response objects:
try {
var loginResponse = await client.Authentication.Login("email@example.com", "password");
if (loginResponse.IsSuccess) {
// Use the API...
} else {
Console.WriteLine($"API Error: {loginResponse.ErrorMessage}");
Console.WriteLine($"Error Code: {loginResponse.ErrorCode}");
}
} catch (Exception ex) {
Console.WriteLine($"Unexpected Error: {ex.Message}");
Console.WriteLine($"Stack Trace: {ex.StackTrace}");
}
All API methods return a standardized response object with the following properties:
public class ApiResponse<T>
{
public bool IsSuccess { get; set; }
public T Data { get; set; }
public string ErrorMessage { get; set; }
public int? ErrorCode { get; set; }
}
You must have a PS in foodservice account to use this package. For more information, visit https://psinfoodservice.com
For questions or support requests, please contact us at info@psinfoodservice.com.