CSharpAmazonBusinessAPI 0.1.2
See the version list below for details.
dotnet add package CSharpAmazonBusinessAPI --version 0.1.2
NuGet\Install-Package CSharpAmazonBusinessAPI -Version 0.1.2
<PackageReference Include="CSharpAmazonBusinessAPI" Version="0.1.2" />
<PackageVersion Include="CSharpAmazonBusinessAPI" Version="0.1.2" />
<PackageReference Include="CSharpAmazonBusinessAPI" />
paket add CSharpAmazonBusinessAPI --version 0.1.2
#r "nuget: CSharpAmazonBusinessAPI, 0.1.2"
#:package CSharpAmazonBusinessAPI@0.1.2
#addin nuget:?package=CSharpAmazonBusinessAPI&version=0.1.2
#tool nuget:?package=CSharpAmazonBusinessAPI&version=0.1.2
βAmazon Business API C# π

.NET C# library for the Amazon Business API. Wraps all 9 REST APIs (Document, Cart, Ordering, Product Search, Reconciliation, Reporting v2025-06-09 + v2021-01-08, User Management, Package Tracking, Application Management) behind a single AmazonBusinessConnection. LWA token refresh, rate-limit retry, regional endpoint routing, sandbox toggle, and debug logging are handled for you.
The generated clients are produced by NSwag from Amazon's published OpenAPI specs (fetched verbatim from developer-docs.amazon.com); the wrapper layer hides the per-spec type duplication so callers see Country.US instead of NSwag-generated Region2/Region3/etc.
Contents β Quick start Β· Configuration Β· Service surface Β· Onboarding (OAuth consent) Β· Roles Β· Status
Installation 
Install-Package CSharpAmazonBusinessAPI
Quick start
using CSharpAmazonBusinessAPI;
using CSharpAmazonBusinessAPI.Utils;
var connection = new AmazonBusinessConnection(new AmazonBusinessCredential
{
ClientId = "amzn1.application-oa2-client.XXXX",
ClientSecret = "XXXX",
RefreshToken = "Atzr|XXXX",
MarketPlace = MarketPlace.UnitedStates,
});
// First call β token refresh, regional host, auth header are all handled.
var reports = await connection.Documents.GetReportsAsync(
createdSince: DateTime.UtcNow.AddDays(-7));
See Configuration for proxy / sandbox / debug-logging options, Onboard a customer for the OAuth consent flow used during one-time customer onboarding, and Source/CSharpAmazonBusinessAPI.SampleCode/ for a per-API sample for every wrapper.
Status & roadmap
The roadmap below covers the full Amazon Business developer surface (docs index) and mirrors the structure used in the sister Amazon-SP-API-CSharp project. Foundation work is required before the per-API service wrappers can be built.
Foundation / scaffolding
-
MarketPlace/Region/Countrylookup tables β 11 supported markets (register-as-a-developer) across 3 regional hosts (ab-api-endpoints):na.business-api.amazon.com,eu.business-api.amazon.com,jp.business-api.amazon.com. -
AmazonBusinessCredentialβ LWA-only (ClientId,ClientSecret,RefreshToken,MarketPlace/MarketPlaceID, optionalProxy,IsDebugMode,Environment). No AWS keys. - LWA token pipeline β
LwaClientPOSTs tohttps://api.amazon.com/auth/o2/token; per-credentialAccessTokenCache(thread-safe viaSemaphoreSlim, refreshes 60s before expiry);LwaAuthHandlerDelegatingHandlerinjectsx-amz-access-tokenand retries once on 401. - LWA client-secret rotation β
AmazonBusinessCredential.RotateClientSecret(newSecret)swaps the secret in place and invalidates the cache so the next call re-exchanges. -
AmazonBusinessConnectionfacade β validates credentials, resolvesMarketPlaceIDβMarketPlace, builds a configuredHttpClient, exposes one property per API surface (Documents,Cart,Ordering,ProductSearch,Reconciliation,Reporting,ReportingLegacy,PackageTracking,Users,Applications). - HTTP layer for NSwag-generated clients β chained handlers
RateLimit β Auth β Debug β HttpClientHandlerwrap a sharedHttpClientwhoseBaseAddresscomes fromMarketPlace.Region. Generated clients consume theHttpClientin their constructor. - Exception types β
AmazonBusinessExceptionbase +Unauthorized,InvalidInput,NotFound,QuotaExceeded,InternalErrorsubclasses. Each carriesStatusCode+ResponseBody. - Rate-limit handling β
RateLimitHandlerDelegatingHandlerhonorsRetry-After(delta or HTTP-date), exponential-backoff fallback, capped byMaxThrottledRetryCount; throwsAmazonBusinessQuotaExceededExceptionif exhausted. - Sandbox toggle β
AmazonBusinessCredential.Environment(Sandbox/Production) switchesBaseAddressbetweenRegion.HostUrlandRegion.SandboxHostUrl. - Debug logging β
DebugLogHandlerpretty-prints request/response (with masked sensitive headers) whenIsDebugMode == true. Routes throughILoggerifAmazonBusinessConnectionwas constructed with anILoggerFactory, else falls back toConsole.
API surfaces
Each API has: (1) OpenAPI spec under Source/CSharpAmazonBusinessAPI/OpenAPIs/ (fetched by scripts/fetch_spec.py), (2) an <OpenApiReference> entry in the csproj, (3) a hand-written *Service wrapper exposed off AmazonBusinessConnection, (4) a sample under Source/CSharpAmazonBusinessAPI.SampleCode/, (5) sandbox-mode tests under Source/Tests/.
- Application Management API v1 β wired as
connection.Applications. Single op (RotateApplicationClientSecretAsync) triggers Amazon to deliver a new LWA client secret to the developer's registered SQS queue. - Cart API v1 β wired as
connection.Cart. All 7 operations exposed (List/Get/AddItems/ModifyItems/DeleteItems/GetItems/EstimateCost). Overview Β· model Β· sandbox. - Document API v1 β wired as
connection.Documents. Invoice-report retrieval viaGetReports/CreateReport/GetReport/CancelReport/GetReportDocument. Region-specific guides: NA invoices, EU/JP invoices. Sandbox. - Ordering API v1 β wired as
connection.Ordering(PlaceOrderAsync,OrderDetailsAsync). Overview. Workflow guides: - Package Tracking API v1 β wired as
connection.PackageTracking(GetPackageTrackingDetailsAsync). Push notifications are out-of-band (SNS); this API covers pull-based detail retrieval. Overview Β· push notifications Β· sandbox. - Product Search API v1 β wired as
connection.ProductSearch. 5 ops with very wide parameter lists (search/get-product/get-offers/by-asin/by-offer-ids); use.Clientdirectly for full IntelliSense. Overview. Workflow guides: - Reconciliation API v1 β wired as
connection.Reconciliation(GetTransactions,GetBatchInvoicePaymentDetails,GetInvoiceDetailsByOrderLineItems). Overview. Workflow guides: - Reporting API β both versions wired side-by-side; new is default, legacy still callable.
- Reporting API v2025-06-09 (current) β wired as
connection.Reporting(5 ops: order reports, order line items, order reports by PO, shipment reports, shipment line items). Use.Clientdirectly. Model. - Reporting API v2021-01-08 (legacy) β wired as
connection.ReportingLegacy(GetOrdersByOrderDateAsync,GetOrdersByOrderIdAsync). Model.
- Reporting API v2025-06-09 (current) β wired as
- User Management API v1 β wired as
connection.Users(CreateBusinessUserAccountAsync). Overview Β· model.
Workflows & integrations
- REST cross-API sample β see
CartToOrderSample.csfor Product Search β Cart β Ordering. Note: Amazon's Integrated Quoting workflow is a separate cXML/cert-auth integration, not a REST workflow β it's out of scope for this SDK. - Third-party website authorization β
LwaConsentHelper.BuildAuthorizationUrl()+ExchangeCodeForTokensAsync(). Use during one-time onboarding to collect a customer's refresh token, then persist it forAmazonBusinessCredential. Runnable demo: seeSource/CSharpAmazonBusinessAPI.WebAuthSampleβ ASP.NET Core minimal-API project with the full consent flow. - App Center authorization workflow β same
LwaConsentHelper.ExchangeCodeForTokensAsync()covers the LWA token-exchange step. The Amazon-initiated callback dance (amazon_callback_uri,amazon_stateechoing, step-3 ack POST, step-6 return-to-App-Center redirect) is wired in the demo at/appcenter/login-uriand/appcenter/oauth/callbackβ seeSource/CSharpAmazonBusinessAPI.WebAuthSamplefor the working reference. -
Punch-inβ out of scope (server-side cXML/SOAP-style endpoint your e-procurement system hosts, with TLS certs / shared-secret auth β same situation as Integrated Quoting). See Punch-in integration guide if you need to integrate the e-procurement side. - Amazon Business Integrations MCP Server β Amazon-hosted MCP server for AI assistants. Out of scope for the SDK; mentioned here for discoverability.
Sample app & tests
-
SampleCode/Program.csloads credentials fromappsettings.json+ User Secrets and prints the resolved region/host/marketplace. Live calls per API are pre-wired and commented β uncomment after dropping in real credentials. -
Tests/CSharpAmazonBusinessAPI.Testsβ xUnit, 41 unit tests + 8 sandbox integration tests (read-only).- Unit:
MarketPlacelookup + regional routing,AmazonBusinessConnectionvalidation/marketplace resolution,AccessTokenCache(caching, invalidation, concurrent refresh, LWA failure),LwaAuthHandler(header injection, cache reuse, 401 retry-once with fresh token),RateLimitHandler(429 retry,Retry-Afterdelta + HTTP-date, exhaustion βAmazonBusinessQuotaExceededException),RotateClientSecretflow,ApiExceptionshape,LwaConsentHelperURL-builder + arg validation. - Integration:
SandboxIntegrationTests.cssmoke-tests Documents, Reconciliation, ReportingLegacy, Reporting (GetOrderReports / GetShipmentReports), ProductSearch, Cart, PackageTracking against the real sandbox. Skipped automatically whenAB_INTEGRATION_*env vars aren't set. Destructive ops (Ordering.PlaceOrder, Users.CreateBusinessUserAccount, Applications.RotateApplicationClientSecret) are intentionally not tested here β add a separate suite when you opt in. - Run with
dotnet test(ordotnet test --filter Category=Integrationfor just the sandbox tests).
- Unit:
- Amazon Business roles reference β see the Roles required per API table in the Usage section. Roles are requested via the Developer Registration Access Form (DRAF) at app creation; the API surface won't authorize without the matching role.
Keys
Amazon Business uses Login with Amazon (LWA) only β no AWS IAM, no STS, no role ARN. Onboarding flow:
- Register as a developer and request the roles your app needs (Developer Registration Access Form).
- Create an app client in the Solution Provider Portal β you'll receive a
ClientId+ClientSecret. - Authorize your app (or use the website-authorization workflow) to obtain a long-lived
RefreshTokenper Amazon Business customer.
| Field | Description |
|---|---|
MarketPlace / MarketPlaceID |
Target marketplace (list). Determines regional endpoint (NA/EU/FE). |
ClientId |
Your app's amzn1.application-oa2-client.β¦ ID. |
ClientSecret |
Your app's secret (rotatable β see LWA client-secret rotation). |
RefreshToken |
Long-lived token issued per customer after consent. Exchanged for a 1-hour access token automatically by the SDK. |
Usage
Configuration
See Program.cs for a runnable example that loads credentials from appsettings.json and User Secrets.
var connection = new AmazonBusinessConnection(new AmazonBusinessCredential
{
ClientId = "amzn1.application-oa2-client.XXXXXXXXXXXXXXXXXXXXXXXXXXXX",
ClientSecret = "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX",
RefreshToken = "Atzr|XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX",
MarketPlace = MarketPlace.UnitedStates, // or: MarketPlaceID = "ATVPDKIKX0DER"
Environment = AmazonBusinessCredential.Environments.Sandbox,
IsDebugMode = true,
});
AmazonBusinessConnection exposes one property per API surface:
| Property | API |
|---|---|
Documents |
Document API v1 (invoice reports) |
Cart |
Cart API v1 |
Applications |
Application Management API v1 |
Ordering |
Ordering API v1 |
PackageTracking |
Package Tracking API v1 |
ProductSearch |
Product Search API v1 |
Reconciliation |
Reconciliation API v1 |
Reporting |
Reporting API v2025-06-09 (current) |
ReportingLegacy |
Reporting API v2021-01-08 (legacy) |
Users |
User Management API v1 |
Each service exposes typed methods plus a .Client property for direct access to the NSwag-generated client when you need parameters not on the wrapper.
Configuration with a proxy
var connection = new AmazonBusinessConnection(new AmazonBusinessCredential
{
ClientId = "...", ClientSecret = "...", RefreshToken = "...",
MarketPlaceID = "ATVPDKIKX0DER",
Proxy = new System.Net.WebProxy("http://xxx.xxx.xxx.xxx:xxxx")
{
Credentials = new System.Net.NetworkCredential("username", "password"),
},
});
Onboard a customer (OAuth consent β refresh token)
For SaaS apps and App Center listings: send the customer to Amazon's consent page, then exchange the returned code for a long-lived refresh_token and persist it. A runnable end-to-end ASP.NET Core demo lives in Source/CSharpAmazonBusinessAPI.WebAuthSample β dotnet run from that folder, browse to https://localhost:7271, click Connect.
// 1. Generate a CSRF token, then redirect the customer's browser here:
var url = LwaConsentHelper.BuildAuthorizationUrl(
clientId: "amzn1.application-oa2-client.XXXX",
redirectUri: "https://my.app/oauth/callback",
state: Guid.NewGuid().ToString());
// 2. On callback, verify state matches, then exchange the code:
var tokens = await LwaConsentHelper.ExchangeCodeForTokensAsync(
code: queryParams["code"],
clientId: "amzn1.application-oa2-client.XXXX",
clientSecret: "...",
redirectUri: "https://my.app/oauth/callback");
// 3. Persist tokens.RefreshToken for this customer; pass it to AmazonBusinessCredential
// going forward. (The access_token expires in 1h β the SDK handles renewal automatically.)
LWA client-secret rotation
// 1. Trigger Amazon to send a new secret to your registered SQS queue.
await connection.Applications.RotateApplicationClientSecretAsync();
// 2. After picking up the new secret, swap it in place β the cached access
// token is invalidated automatically, so the next API call re-exchanges.
connection.Credentials.RotateClientSecret(newSecret);
Document API β list and download invoice reports
For more, see DocumentSample.cs.
// List recent invoice reports (marketplaceIds defaults to credential).
var reports = await connection.Documents.GetReportsAsync(
createdSince: DateTime.UtcNow.AddDays(-30));
// Create an invoice report, then poll for completion + download.
var reportId = (await connection.Documents.CreateReportAsync(new CreateReportSpecification
{
ReportType = "GET_FLAT_FILE_VAT_INVOICE_DATA_REPORT",
DataStartTime = DateTime.UtcNow.AddDays(-30),
DataEndTime = DateTime.UtcNow,
})).ReportId;
var report = await connection.Documents.GetReportAsync(reportId);
if (report.ProcessingStatus == ProcessingStatus.DONE)
{
var doc = await connection.Documents.GetReportDocumentAsync(report.ReportDocumentId);
// doc.Url is a 5-minute presigned URL; doc.CompressionAlgorithm == GZIP if compressed.
}
Cart API β list, get, add items
For more, see CartSample.cs. The country parameter defaults to the connection's marketplace β pass Country.X explicitly only to override per call.
// Country defaults from connection.Credentials.MarketPlace.Country.
var carts = await connection.Cart.ListCartsAsync(
customerEmail: "buyer@example.com",
pageSize: 25);
await connection.Cart.AddItemsAsync("cart-123", new AddItemsRequest
{
Items = new List<AddItemRequest>
{
new AddItemRequest { ProductIdentifier = "B07HMBFZCZ", Quantity = 2 },
},
});
Reporting API v2025-06-09
For more, see ReportingSample.cs. The 5 ops have wrapper methods (country defaults from connection); .Client is also there for the raw generated surface.
var orderReports = await connection.Reporting.GetOrderReportsAsync(
orderStartDate: DateTimeOffset.UtcNow.AddDays(-7),
orderEndDate: DateTimeOffset.UtcNow);
Reconciliation API β pull transactions
For more, see ReconciliationSample.cs.
var transactions = await connection.Reconciliation.GetTransactionsAsync(
feedStartDate: DateTimeOffset.UtcNow.AddDays(-30),
feedEndDate: DateTimeOffset.UtcNow);
Package Tracking
For more, see PackageTrackingSample.cs.
// Country defaults from the connection's marketplace.
var details = await connection.PackageTracking.GetPackageTrackingDetailsAsync(
orderId: "114-2589187-9801025",
shipmentId: "401971789238301",
packageId: "1");
Product Search
For more, see ProductSearchSample.cs. The two most common ops have wrappers; the other three (SearchOffersRequest, GetProductsByAsins, GetOffersByOfferIds) are reachable via .Client.
var results = await connection.ProductSearch.SearchProductsAsync(
keywords: "office chair",
customerEmail: "buyer@example.com",
pageSize: 24,
sortKey: SortKey.RELEVANCE);
var product = await connection.ProductSearch.GetProductByAsinAsync(
asin: "B07HMBFZCZ",
customerEmail: "buyer@example.com");
Other surfaces
- Ordering β
OrderingSample.cs - Reporting Legacy v2021-01-08 β
ReportingLegacySample.cs - User Management β
UserManagementSample.cs - Application Management β
ApplicationManagementSample.cs
Enable debug mode
Set IsDebugMode = true on the credential. Pretty-prints request and response (with sensitive headers masked) for every outbound call. Pass an ILoggerFactory to AmazonBusinessConnection to route through ILogger instead of Console.
Roles required per API
Each API call needs a specific Amazon Business role granted at app-creation time via the Developer Registration Access Form. Calling without the matching role returns 403. (Source.)
| Role | API surfaces (this SDK) |
|---|---|
| Business Product Catalog | connection.ProductSearch |
| Amazon Business Analytics | connection.Reporting, connection.ReportingLegacy |
| Business Purchase Reconciliation | connection.Reconciliation, connection.Documents |
| Amazon Business Order Placement | connection.Ordering, connection.Cart, connection.PackageTracking |
| User Management (offline approval required) | connection.Users |
| (no role required) | connection.Applications β uses standard LWA scope |
All roles are available across NA, EU, and FE marketplaces.
Out of scope: Integrated Quoting
Amazon's Integrated Quoting workflow is a separate cXML over HTTPS integration with digital-certificate auth, used by enterprise eProcurement sourcing modules β it does not use the REST APIs this SDK wraps. If you need that flow, integrate it via your cXML stack alongside this library.
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net5.0 was computed. net5.0-windows was computed. net6.0 was computed. net6.0-android was computed. net6.0-ios was computed. net6.0-maccatalyst was computed. net6.0-macos was computed. net6.0-tvos was computed. net6.0-windows was computed. net7.0 was computed. net7.0-android was computed. net7.0-ios was computed. net7.0-maccatalyst was computed. net7.0-macos was computed. net7.0-tvos was computed. net7.0-windows was computed. net8.0 was computed. net8.0-android was computed. net8.0-browser was computed. net8.0-ios was computed. net8.0-maccatalyst was computed. net8.0-macos was computed. net8.0-tvos was computed. net8.0-windows was computed. net9.0 was computed. net9.0-android was computed. net9.0-browser was computed. net9.0-ios was computed. net9.0-maccatalyst was computed. net9.0-macos was computed. net9.0-tvos was computed. net9.0-windows was computed. net10.0 was computed. net10.0-android was computed. net10.0-browser was computed. net10.0-ios was computed. net10.0-maccatalyst was computed. net10.0-macos was computed. net10.0-tvos was computed. net10.0-windows was computed. |
| .NET Core | netcoreapp2.0 was computed. netcoreapp2.1 was computed. netcoreapp2.2 was computed. netcoreapp3.0 was computed. netcoreapp3.1 was computed. |
| .NET Standard | netstandard2.0 is compatible. netstandard2.1 was computed. |
| .NET Framework | net461 was computed. net462 was computed. net463 was computed. net47 was computed. net471 was computed. net472 was computed. net48 was computed. net481 was computed. |
| MonoAndroid | monoandroid was computed. |
| MonoMac | monomac was computed. |
| MonoTouch | monotouch was computed. |
| Tizen | tizen40 was computed. tizen60 was computed. |
| Xamarin.iOS | xamarinios was computed. |
| Xamarin.Mac | xamarinmac was computed. |
| Xamarin.TVOS | xamarintvos was computed. |
| Xamarin.WatchOS | xamarinwatchos was computed. |
-
.NETStandard 2.0
- Microsoft.Extensions.Logging.Abstractions (>= 6.0.4)
- Newtonsoft.Json (>= 13.0.2)
- System.ComponentModel.Annotations (>= 5.0.0)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.
See CHANGELOG.md at https://github.com/abuzuhri/Amazon-Business-API-CSharp/blob/main/CHANGELOG.md