Sales and Returns API Examples - C#

Overview

This document reflects over the aforementioned use cases of the Sales and Returns API. All examples defined within demonstrate calls to the SOAP interface and are provided as is.

Requirements

The following examples demonstrate calls to the Sales and Returns API in C#. .NET examples demonstrated here assume the use of a generated XML web service client. To generate such a client, a tool such as WSDL.exe can be used. A detailed description on this tool can be found on MSDN, but all you will need to do is point it at your site's WSDL description.

.NET examples utilise the Microsoft .NET Framework component LINQ

Retrieve a single sale.

// Instantiate the web service proxy.
iSAMSSaleReturnAPI service = new iSAMSSaleReturnAPI();

// User to authenticate with.
String username = "Testing";
// Corresponding password to authenticate with.
String password = "Sup94zex";

// Authenticate
ApiResponse authenticationResponse = service.Authenticate(username, password);

// Order ID for the Sale to search the Database for.
int saleID = 10501;

// Retrieve the Sale
SaleReturnApiResponse retrieveResponse = 
	service.RetrieveSale(authenticationResponse.Message, saleID);

// Examine the SaleReturnApiResponse for our Sale.
if (retrieveResponse.Data.Count() == 0) {
	Console.WriteLine("Failed to retrieve sale: {0}", sale);
} else {
	// Extract the sale from the response.
	Sale sale = retrieveResponse.Data.First();
}
			

List all order IDs for sales/returns.

// Instantiate the web service proxy.
iSAMSSaleReturnAPI service = new iSAMSSaleReturnAPI();

// User to authenticate with.
String username = "Testing";
// Corresponding password to authenticate with.
String password = "Sup94zex";

// Authenticate
ApiResponse authenticationResponse = service.Authenticate(username, password);

// List the order IDs for all sales and returns within the system.
IntegerArrayApiResponse listResponse = 
	service.ListAll(authenticationResponse.Message);
listResponse.Data.AsParallel().ForAll(x => Console.WriteLine(x));
			

List order IDs for sales/returns based on a filter.

// Instantiate the web service proxy.
iSAMSSaleReturnAPI service = new iSAMSSaleReturnAPI();

// User to authenticate with.
String username = "Testing";
// Corresponding password to authenticate with.
String password = "Sup94zex";

// Authenticate
ApiResponse authenticationResponse = service.Authenticate(username, password);

// List the order IDs for all sales and returns in the given export ID.
IntegerArrayApiResponse listResponse = 
	service.ListFiltered(
		authenticationResponse.Message,
		2, null, null, null, 0
	);
listResponse.Data.AsParallel().ForAll(x => Console.WriteLine(x));