Examples


On this page you will find simple examples of how to interact with this service. A more comprehensive solution can also be found by downloading one of the sample projects from the Libraries Page.

To test any of these examples in your own development environment you will need to replace the string constants for "baseUri" and "credentials". The baseUri in the examples will default to the correct URI for this installation. In the individual examples other constants may be changed to affect the outcomes.

For more information on authentication you can visit the Authentication page.

Adding an email address to a constituent record


This specific example is for adding an email address, but the concepts will apply to POST calls on any resource. When posting or putting objects it is important to consult the help page for that resource. The help page will have information about what values are required and links to specific information about each resource contained. For example, the help page for the call we are using is here.

Also notice that now we need to set the content type on the request. Since this example is using json we set it to "application/json".

To make this call successfully in your environment you will likely need to update the values for the constituent id and the Reference data types (ElectronicAddressType, AltSalutationType...).


using System;
using System.Net.Http;
using System.Text;
using System.Threading.Tasks;
using Newtonsoft.Json;
using Tessitura.Service.Client.Common;
using Tessitura.Service.Client.CRM;
using Tessitura.Service.Client.ReferenceData;

namespace AddElectronicAddress
{
    class Program
    {
        static void Main(string[] args)
        {
            var t = MainAsync();
            t.Wait();
        }
        private static async Task MainAsync()
        {
            const string credentials = "yourUser:yourUserGroup:yourMachineName:yourPassword";
            const string baseUri = "https://ts-stg-appgw.calacademy.org/TessituraService/";
            const string addEmailAddressUri = baseUri + "CRM/ElectronicAddresses";

            var authHeaderString = "Basic " + Convert.ToBase64String(Encoding.Default.GetBytes(credentials));
            var httpClient = new HttpClient {Timeout = new TimeSpan(0, 0, 5000)};
            httpClient.DefaultRequestHeaders.Add("Accept", "text/json");
            httpClient.DefaultRequestHeaders.Add("Authorization", authHeaderString);

            var emailAddressToAdd = new ElectronicAddress()
            {
                Address = "test@domain.com",
                AffiliatedConstituent = null,
                AltSalutationType = new SalutationTypeSummary
                {
                    Description = "Default",
                    Id = 0,
                    Inactive = false
                },
                Constituent = new Entity
                {
                    Id = 1007
                },
                ElectronicAddressType = new ElectronicAddressTypeSummary
                {
                    Description = "Primary Email Address",
                    Id = 1,
                    Inactive = false,
                    IsEmail = true
                },
                EndDate = null,
                AllowHtmlFormat = true,
                Inactive = false,
                AllowMarketing = false,
                Months = "YYYYYYYYYYYY",
                PrimaryIndicator = false,
                StartDate = null,
                IsFromAffiliation = false,
                IsEmail = true
            };

            try
            {
                var content = new StringContent(JsonConvert.SerializeObject(emailAddressToAdd), Encoding.UTF8, "application/json");
                var response = await httpClient.PostAsync(addEmailAddressUri, content);
                var responseString = await response.Content.ReadAsStringAsync();
                if (((int) response.StatusCode >= 200 && (int) response.StatusCode < 300))
                {
                    var electronicAddress = JsonConvert.DeserializeObject<electronicaddress>(responseString);
                    Console.WriteLine("Created :" + electronicAddress.Address);
                }
                else
                {
                    Console.WriteLine(responseString);
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
            }
        }
    }
}

    

CRUD a price type


CRUD is an acronym for Create, Read, Update, Delete. For the last example we will show all four operations on a pricetype.

You will need to update the Reference Data objects on the created pricetype for this example to work with your system.

To compare to any active pricetypes in your system you can call this resource.


using System;
using System.Net.Http;
using System.Text;
using System.Threading.Tasks;
using Newtonsoft.Json;
using Tessitura.Service.Client.ReferenceData;
using Tessitura.Service.Client.Txn;

namespace CRUDpriceType
{
    class Program
    {
        static void Main(string[] args)
        {
            var t = MainAsync();
            t.Wait();
        }
        private static async Task MainAsync()
        {
            const string credentials = "yourUser:yourUserGroup:yourMachineName:yourPassword";
            const string baseUri = "https://ts-stg-appgw.calacademy.org/TessituraService/";
            const string priceTypeUri = baseUri + "TXN/PriceTypes";
            var authHeaderString = "Basic " + Convert.ToBase64String(Encoding.Default.GetBytes(credentials));
            var httpClient = new HttpClient {Timeout = new TimeSpan(0, 0, 5000)};
            httpClient.DefaultRequestHeaders.Add("Accept", "text/json");
            httpClient.DefaultRequestHeaders.Add("Authorization", authHeaderString);

            var priceTypeToCreate = new PriceType
            {
                DefaultTicketDesign = new TicketDesign
                {
                    Description = "Standard Ticket",
                    Id = 2011
                },
                Description = "My Test PriceType",
                EditableIndicator = false,
                Inactive = false,
                PriceTypeCategory = new PriceTypeCategorySummary
                {
                    Description = "Standard",
                    Id = 2
                },
                PriceTypeGroup = new PriceTypeGroupSummary
                {
                    Description = "Default Price Type Group",
                    Id = -1
                },
                ReasonIndicator = false
            };

            try
            {
                int? createdPriceTypeId;
                PriceType priceType;
                var content = new StringContent(JsonConvert.SerializeObject(priceTypeToCreate), Encoding.UTF8, "application/json");
                var createResponse = await httpClient.PostAsync(priceTypeUri, content);
                var createResponseString = await createResponse.Content.ReadAsStringAsync();
                if (((int)createResponse.StatusCode >= 200 && (int)createResponse.StatusCode < 300))
                {
                    priceType = JsonConvert.DeserializeObject<pricetype>(createResponseString);
                    if (priceType == null || priceType.Id == null)
                    {
                        throw new Exception("No priceTypeId was found for the created pricetype.");
                    }
                    Console.WriteLine("Successfully saved pricetype id " + priceType.Id);
                    createdPriceTypeId = priceType.Id;
                }
                else
                {
                    throw new Exception(createResponseString);
                }
                
                var getResponse = await httpClient.GetAsync(priceTypeUri + "/" + createdPriceTypeId);
                var getResponseString = await getResponse.Content.ReadAsStringAsync();
                if (((int)getResponse.StatusCode >= 200 && (int)getResponse.StatusCode < 300))
                {
                    priceType = JsonConvert.DeserializeObject<pricetype>(getResponseString);
                    Console.WriteLine("Successfully retrieved pricetype: " + priceType.Description);
                }
                else
                {
                    throw new Exception(getResponseString);
                }

                priceType.Description = "Updated PriceType Description.";
                content = new StringContent(JsonConvert.SerializeObject(priceType), Encoding.UTF8, "application/json");
                var updateResponse = await httpClient.PutAsync(priceTypeUri + "/" + createdPriceTypeId, content);
                var updateResponseString = await updateResponse.Content.ReadAsStringAsync();
                if (((int)updateResponse.StatusCode >= 200 && (int)updateResponse.StatusCode < 300))
                {
                    priceType = JsonConvert.DeserializeObject<pricetype>(updateResponseString);
                    Console.WriteLine("Successfully updated pricetype name to: " + priceType.Description);
                }
                else
                {
                    throw new Exception(updateResponseString);
                }

                var deleteResponse = await httpClient.DeleteAsync(priceTypeUri + "/" + createdPriceTypeId);
                var deleteResponseString = await deleteResponse.Content.ReadAsStringAsync();
                if (((int)deleteResponse.StatusCode >= 200 && (int)deleteResponse.StatusCode < 300))
                {
                    Console.WriteLine("Successfully deleted pricetype id: " + createdPriceTypeId);
                }
                else
                {
                    throw new Exception(deleteResponseString);
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
            }
        }
    }
}