public async Task <IIntacctSession> InitiateApiSession(IntacctUserCredential cred, CancellationToken token) { var operation = new GetApiSessionOperation(cred); // construct and execute request var operations = new[] { operation }; var response = await ExecuteOperations(operations, token); // expecting a single operation result (more or less is a problem) var result = response.OperationResults.OfType <IntacctOperationResult <IntacctSession> >().SingleOrDefault(); if (result != null) { return(result.Value); } // let's see what the result is var badResult = response.OperationResults.FirstOrDefault(); if (badResult == null) { throw new Exception("Unable to initiate API session, and no results were captured."); } var authError = badResult as IntacctOperationAuthFailedResult; if (authError != null) { throw new Exception($"Unable to initiate API session, authentication failed. Service error: {authError.Errors.Select(e => e.ToString()).Aggregate((curr, next) => curr + " " + next)}"); } throw new Exception($"Unable to initiate API session, unexpected result type {badResult.GetType().Name}."); }
public async Task<IIntacctSession> InitiateApiSession(IntacctUserCredential cred, CancellationToken token) { var operation = new GetApiSessionOperation(cred); // construct and execute request var operations = new[] { operation }; var response = await ExecuteOperations(operations, token); // expecting a single operation result (more or less is a problem) var result = response.OperationResults.OfType<IntacctOperationResult<IntacctSession>>().SingleOrDefault(); if (result != null) return result.Value; // let's see what the result is var badResult = response.OperationResults.FirstOrDefault(); if (badResult == null) throw new Exception("Unable to initiate API session, and no results were captured."); var authError = badResult as IntacctOperationAuthFailedResult; if (authError != null) throw new Exception($"Unable to initiate API session, authentication failed. Service error: {authError.Errors.Select(e => e.ToString()).Aggregate((curr, next) => curr + " " + next)}"); throw new Exception($"Unable to initiate API session, unexpected result type {badResult.GetType().Name}."); }
private static void Main() { var settings = LoadSettings(); var serverUri = new Uri(settings.ServerUri); var serverCredential = new NetworkCredential(settings.AccountUsername, settings.AccountPassword); var userCredential = new IntacctUserCredential(settings.CompanyName, settings.Username, settings.Password); var client = new IntacctClient(serverUri, serverCredential); var session = client.InitiateApiSession(userCredential).Result; Console.WriteLine($"Session created, ID: {session.SessionId}, Endpoint: {session.EndpointUri}"); // create customer var customer = new IntacctCustomer("C0021", "MT Test " + Guid.NewGuid()) { ExternalId = "1337", PrimaryContact = new IntacctContact(Guid.NewGuid().ToString(), "Random") }; var response = client.ExecuteOperations(new[] { new CreateCustomerOperation(session, customer) }, CancellationToken.None).Result; Console.WriteLine($"Customer created: {response.Success}"); if (!response.Success) return; // retrieve customer response = client.ExecuteOperations(new[] { new GetEntityOperation<IntacctCustomer>(session, customer.Id) }, CancellationToken.None).Result; Console.WriteLine($"Customer retrieved: {response.Success}"); if (!response.Success) return; // create invoice var invoice = new IntacctInvoice(customer.Id, new IntacctDate(1, 1, 2015), new IntacctDate(1, 1, 2015)); var lineItem = IntacctLineItem.CreateWithAccountNumber("2000", 15); lineItem.Memo = "Services rendered"; invoice.Items.Add(lineItem); response = client.ExecuteOperations(new[] { new CreateInvoiceOperation(session, invoice) }, CancellationToken.None).Result; Console.WriteLine($"Invoice created: {response.Success}"); }
public async Task<IIntacctSession> InitiateApiSession(IntacctUserCredential cred) { return await InitiateApiSession(cred, CancellationToken.None); }
public async Task <IIntacctSession> InitiateApiSession(IntacctUserCredential cred) { return(await InitiateApiSession(cred, CancellationToken.None)); }