Summary
Infigo publishes its REST API client for .NET on NuGet as Infigo.Api.Stub. It gives you one typed method for each API operation, grouped by area such as Order, Customer and CatalogV2, so you do not write HTTP calls or parse JSON yourself.
Problem
You are building an integration with your storefront's REST API from a .NET application and want to avoid hand-writing requests, authentication and response models.
Environment
Any project that supports .NET Standard 2.0, the web address of your storefront and an API token for it. Your API token is issued by Infigo Support (the same first step as in Embedding our editors in another site). The full list of endpoints and models is in the API documentation.
Configuration
Step 1: Add the package to your project
Install the Infigo.Api.Stub package from NuGet. From a command line in your project folder run:
dotnet add package Infigo.Api.Stub
In Visual Studio you can instead open Manage NuGet Packages for the project, search for Infigo.Api.Stub and click Install. Use this route if your project uses a packages.config file.
The package name is Infigo.Api.Stub, but the namespace in your code is Infigo.Api.Client, so add using Infigo.Api.Client; to the files that use it.
Step 2: Create the client
Create an InfigoApiClient with your storefront address and API token:
var api = new InfigoApiClient("https://your-storefront.infigo.net", token);
Use the https:// address of your storefront, or its full API address ending in /services/api; both work. The client sends the token with every request for you, so you do not build any authentication header.
The token gives access to your storefront's API, so keep it out of your source code: read it from configuration, an environment variable or a secret store, and use the client only from server-side code you control.
Create one client and reuse it for the life of your application rather than creating a new one for every call, and dispose it when your application shuts down. If you work with several storefronts, create one client for each.
Step 3: Make your first call
Each API area is a property on the client, with one method per operation. Type api. in your editor to see the areas, such as Order, Customer and CatalogV2. They match the sections of the API documentation, which lists every operation with its description. Every method comes in a synchronous and an Async form.
A good first call is a list of products, which needs no ids:
var products = api.CatalogV2.ListProducts(0, 20);
Console.WriteLine(products.Count);
The two numbers are the page index and the number of products per page. If the call returns without an exception, your address and token are correct, and products holds the first page of products.
Calls that act on one record take its id, and the async form is used inside an async method:
int orderId = 12345;
var order = api.Order.GetOrder(orderId);
var sameOrder = await api.Order.GetOrderAsync(orderId);
Method names follow one pattern across the API: GetX, ListX, CreateX, UpdateX and DeleteX, or a verb and a noun. Prices and amounts are typed as decimal. In web or desktop applications, prefer the Async forms so calls do not block the calling thread.
Step 4: Handle errors
When the API returns an error response, the client throws an InfigoApiException that carries the HTTP StatusCode and the Response body:
try
{
var quote = api.Quote.GetQuote(quoteId);
}
catch (InfigoApiException ex)
{
Console.Error.WriteLine($"{ex.StatusCode}: {ex.Response}");
}
A 401 or 403 means the token was not accepted: check the token and that it was issued for that storefront address. A 429 means you are sending requests too quickly: wait for the time in the Retry-After header before you retry. Network failures and timeouts are not wrapped: they are thrown as the usual HttpRequestException and TaskCanceledException.
Step 5: Update the package
When a newer version of the package is available, update it: run dotnet add package Infigo.Api.Stub again, or open the Updates tab in Manage NuGet Packages in Visual Studio. Rebuild your project afterwards.
Search Terms
infigo api client, infigo api nuget, Infigo.Api.Stub, infigo .net api client, infigo api c# example, infigo api sdk, call infigo api from .net, InfigoApiClient, infigo api typed client, infigo rest api library, nuget package infigo, infigo api token .net