I am attempting to add an AP Invoice Head to my Kinetic environment through the RESt-API and I keep getting this error:
Sorry! Something went wrong. Please contact your system administrator. Correlation Id: 9d940985-d629-482c-948f-cf5a004e598a
I contacted the sys admin and we looked for this error in our logs, but couldn’t find it. this happens when trying to hit the endpoint from Swagger as well as from our integration project.
Here’s the invoice head object that’s being sent in: json1.txt (16.7 KB)
Here’s my context to call the API:
internal async Task CreateInvoices(string groupId, string invoices)
{
BuildingRequest += buildServiceRequest;
var parameters = new BodyOperationParameter[]
{
new BodyOperationParameter("ds", invoices),
new BodyOperationParameter("cGroupId", groupId)
};
var request = getNewAPInvHedInvoice(parameters);
var response = request.Execute();
}
private DataServiceActionQuery getNewAPInvHedInvoice(params BodyOperationParameter[] parameters) => new(this, this.BaseUri.OriginalString.Trim('/') + "/GetNewAPInvHedInvoice", parameters);
Can anyone tell me what I’m doing wrong and how I can actually create an AP Invoice head using the REST-API?
I can provide more details if needed. Thanks in advance.
Hey Robert,
In general I steer people to utilizing the REST API but also using Epicor Functions (user defined RPC like endpoints) to do the actual work. The v1 API is more “let’s expose the services over rest” without much consideration for the calling client application. v2 allows the use of Functions, which will give you the opportunity to pass the function what is needed (the dynamic part of the data) and perform the orchestration of the transaction, i.e. create the API invoice head, inside the function.
Typically you’ll want to perform a trace of the transaction through the client first to show what it’s doing and what data is needed. Then, you can build out either your function or calling the appropriate services exactly with those calls. Sometimes weird stuff happens, as you saw, which is why I really recommend the function approach first and foremost.
I am using the API to call this endpoint. We’re not using a client per-se, it’s being done in an integration, I’m manually constructing the AP Invoice head prior to calling the endpoint, the json file I included is what I’m actually sending to the REST API.
Even more reason to take a look at what Aaron is suggesting. Why complicate your integration client with Kinetic-specific code? Pass a Json string that makes it easy on your client and then put the work of the Invoice creation in the Epicor Function. Bonus: you’ll cut down the number of calls over the wire and make your integration faster.
Doesn’t that kind of eliminate the purpose of an integration though? We have considered doing an Epicor Function that does all the work, but we decided against it. I see the benefit of doing it that way though.
Appologies, I didn’t fully grasp what you were telling me. I was half asleep and had been trying to figure out a solution on my own. We had looked at doing an Epicor Function before, but decided against it since we felt that it was eliminating the purpose of an integration. I like your recommendation much better than what we’re doing now, which is adding the invoice through DMT.
It’s just another tool in the chest, and a way to do abstractions. A very powerful one at that.
Nice place to keep your logic contained, and do it on the server.
I try and do anything I can on the server, instead of any type of client. Do just what you need
in the client, and pass the data up for processing.
The way it’s been requested is that we have a document management system that, when it sees that an invoice is ready to be created, it creates a JSON file in one of our network folders. The integration has a worker service that runs once, or multiple times daily(final decision hasn’t been made yet on how often), to sweep that folder to check for new files.
When it picks up a new file, it transforms that JSON file into a collection of APInvoiceHed objects. Creates the “ds” object for the body parameter for GetNewAPInvHedInvoice.
The end goal is to basically use this RPC method to insert these items into our Kinetic DB.