This document contains examples of typical use cases for the Gift Registry API. These examples demonstrate calls to the SOAP interface and are provided as is.
Full API documentation is available here.
The following examples demonstrate calls to the Gift Registry API in C#.
These examples 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 - you will need to point this program at your site's Gift Registry API endpoint. A detailed description of how to generate a web service client is beyond the scope of this document.
Note that these examples include minimal or no error handling. Any API callers are expected to handle errors appropriately.
// Instantiate the web service proxy
iSAMSGiftRegistryAPI service = new iSAMSGiftRegistryAPI();
// User to authenticate with.
string username = "Testing";
// Corresponding password to authenticate with.
string password = "Sup94zex";
// Authenticate.
ApiResponse authResponse = service.Authenticate(username, password);
string token = authResponse.Message;
// ID of the required gift registry.
int registryID = 1027;
// Retrieve the gift registry.
GiftRegistryApiResponse apiResponse = service.Retrieve(token, registryID);
// Examine the GiftRegistryApiResponse for our gift registry.
if (!apiResponse.Success || apiResponse.Data.Count() == 0) {
Console.WriteLine("Failed to retrieve gift registry {0}", registryID);
} else {
// Extract the gift registry from the response.
Registry registry = apiResponse.Data.First();
Console.WriteLine(registry.LastName + ", " + registry.FirstName);
}
// Instantiate the web service proxy.
iSAMSGiftRegistryAPI service = new iSAMSGiftRegistryAPI();
// User to authenticate with.
string username = "Testing";
// Corresponding password to authenticate with.
string password = "Sup94zex";
// Authenticate and retrieve authentication token.
ApiResponse authResponse = service.Authenticate(username, password);
string token = authResponse.Message;
// List the IDs of all gift registries that have a registrant
// or a co-registrant with the name "Bourne".
IntegerArrayApiResponse searchByName =
service.Search(token, "Bourne", null, null, null);
searchByName.Data.ToList().ForEach(id => Console.WriteLine(id));
// List the IDs of all gift registries that have a registrant or
// a co-registrant with a CIA email address.
IntegerArrayApiResponse searchByEmail =
service.Search(token, null, "cia.govt", null, null);
searchByEmail.Data.ToList().ForEach(id => Console.WriteLine(id));
// List the IDs of all gift registries that have an event on April 1, 2017
// and have a registrant or co-registrant with the name 'Jason'.
DateTime eventDate = new DateTime(2017, 4, 1);
IntegerArrayApiResponse searchByNameAndEventDate =
service.Search(token, "Jason", null, null, eventDate);
searchByNameAndEventDate.Data.ToList().ForEach(id => Console.WriteLine(id));
// Instantiate the web service proxy.
iSAMSGiftRegistryAPI service = new iSAMSGiftRegistryAPI();
// User to authenticate with.
string username = "Testing";
// Corresponding password to authenticate with.
string password = "Sup94zex";
// Authenticate and retrieve authentication token.
ApiResponse authResponse = service.Authenticate(username, password);
string token = authResponse.Message;
// Gift registry ID of the registry to record the sale against.
int registryID = 1027;
// Barcode of item to record against gift registry.
string barcode = "314159";
// Retrieve gift registry and extract the registry's items.
GiftRegistryApiResponse apiResponse = service.Retrieve(token, registryID);
RegistryItem[] items = apiResponse.Data.First().RegistryItems;
// Find the item ID of the gift registry item with the correct barcode.
int itemID = items.Where(i => i.Barcode == barcode).First().ID;
// Create a new sale object for submission to the Gift Registry API.
RegistrySale[] sales = new RegistrySale[1];
sales[0] = new RegistrySale {
ID = itemID,
UnitNet = 10m,
Quantity = 1,
Comment = "Instore sale",
Reference = "TXN-REF-14142"
};
// Call API to submit the sale.
ApiResponse response = service.RecordSale(token, registryID, sales);
// Check that the request succeeded.
if (response.Success) {
Console.WriteLine("Successfully recorded sale");
} else {
Console.WriteLine(
"Error {0} encountered while recording sale for gift registry {1}",
response.Code, registryID
);
}