Stores API Examples - Java

Overview

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

Requirements

The following examples demonstrate calls to the Stores API in Java. Java examples demonstrated here assume the use of a generated XML web service client. To generate such a client, a tool such as wsdl2java can be used. A detailed description on this tool can be found on the Apache Web Services website, but all you will need to do is point it at your site's WSDL description.

Retrieve a single Stores' details.

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

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

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

int storeID = 1;
// Retrieve the store
StoresApiResponse retrieveResponse = 
	service.GetStoreByID(authenticationResponse.getMessage(), storeID);

// Examine the StoresApiResponse for our store.
if (retrieveResponse.getData()[0] == null) {
	System.out.printf("Failed to retrieve store with ID: %s", storeID);
} else {
	// Extract the store from the response.
	Store store = retrieveResponse.getData()[0];
}
			

Retrieve a list of Stores based on a postcode location.

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

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

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

// Country to retrieve the stores from.
String storeCountry = "New Zealand";

// The postcode the stores are in.
String storePostcode = "8010";

// The radius from the postcode within which to retrieve the stores (in metres).
int radius = 2000;

// Retrieve the store
StoresApiResponse retrieveResponse = 
	service.ListStoresByPostcode(
				authenticationResponse.getMessage(), 
				storeCountry, 
				storePostcode, 
				radius
	);

// Examine the StoresApiResponse for our stores.
if (retrieveResponse.getData == null) {
	Console.WriteLine(
		"There were no stores present for the given parameters"
	);
} else {
	// Extract the store from the response.
	Store[] stores = retrieveResponse.getData();
}
			

Add or update a Store.

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

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

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

Store store = new Store();
store.setID(0);
store.setActive(true);
store.setBranchCode("Test branch");
store.setName("Test store");
store.setManager("Test manager");
store.setLatitude("0");
store.setLongitude("0");
store.setAddress("Test address");
store.setDetails("Test details");
store.setType("Test type");
store.setEmail("[email protected]");

Area area = new Area();
area.setName("Test name");
area.setCountry("Test country");
store.setArea(area);

// Invoke the UpdateStore web method.
service.UpdateStore(authenticationResponse.getMessage(), store);
			

Delete a Store from the database.

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

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

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

// Store to delete in the system.
int storeID = 1;

// Delete the store from the system.
service.Delete(authenticationResponse.getMessage(), storeID);