Does anyone have experience creating an API to insert records from SQL Server into Acumatica? I’m currently working on building an integration that transfers data from a SQL Server database into Acumatica using the SOAP API, specifically for the Receivables module (Invoices and Memos screen). Any guidance or examples would be appreciated!
Im stuck 😞
What i started
using System; using System.Collections.Generic; using System.Data.SqlClient; using System.Linq; using System.Web.Services; using AcumaticaClientLib.AcumaticaDefault24; using AcumaticaInvoiceClientLib.Models;
namespace AcumaticaInvoiceClientLib.Services { public class InvoiceUploader { private readonly Screen _client; private readonly string _connectionString;
private Dictionary<string, List<InvoiceLine>> LoadInvoices() { var map = new Dictionary<string, List<InvoiceLine>>(); using (var conn = new SqlConnection(_connectionString)) using (var cmd = conn.CreateCommand()) { conn.Open(); cmd.CommandText = @" SELECT ExtSerial, [Date], CustomerRefNbr, [Description], Customer, AQ_Branch, InventoryID, LineQuantity, LineUnitPrice, LineDescription, LineSubAccount, AQ_COA, Amount FROM AH_ODS_DB.dbo.KDI_Vigi_InvoiceDetails WHERE AQ_PostStatus IS NULL ORDER BY ExtSerial, LineNbr";
using (var rdr = cmd.ExecuteReader()) { while (rdr.Read()) { var id = rdr["ExtSerial"].ToString(); if (!map.ContainsKey(id)) map[id] = new List<InvoiceLine>();
var lineCmds = new List<Command> { Cmd("Transactions", "InventoryID", line.InventoryID), Cmd("Transactions", "Quantity", line.Quantity), Cmd("Transactions", "UnitPrice", line.UnitPrice), Cmd("Transactions", "TranDesc", line.LineDescription) };
if (!string.IsNullOrWhiteSpace(line.SubAccount)) lineCmds.Add(Cmd("Transactions", "SubID", line.SubAccount)); if (!string.IsNullOrWhiteSpace(line.AccountID)) lineCmds.Add(Cmd("Transactions", "AccountID", line.AccountID));
DebugCommands(lineCmds.ToArray(), "Line Import"); _client.AR301000Import(lineCmds.ToArray(), null, null, true, true, true); _client.AR301000Submit(new Command[0]); Console.WriteLine(" ✔ Line Saved"); } } catch (Exception ex) { throw new Exception($"❌ Failed on Transactions: {ex.GetBaseException().Message}"); }
The first thing is that you shouldn’t use the SOAP interface. It’s being depreciated. Use the REST Api. Then you don’t need to worry about models - just create a JSon payload and send it to the correct endpoint.
The other observation is around the dates of your transaction and that you’re supplying a RefNbr for the document. Are you able to enter this transaction manually in Acumatica without errors?