Epicor Web API

Anyone know, how to install and call Epicor Web API in Console application using c#?

1 Like

I have created one Console Application and wrote the below-mentioned code

HttpWebRequest webrequest = (HttpWebRequest)WebRequest.Create(“https://APPServer/E10Testing/api/v1/Erp.BO.SalesOrderSvc/SalesOrder(EPIC04,1)”);
webrequest.Method = “Get”;
webrequest.ContentType = “application/json”;
webrequest.ContentLength = 0;
webrequest.Headers.Add(“Username”, “manager”);
webrequest.Headers.Add(“Password”, “manager”);
HttpWebResponse webresponse = (HttpWebResponse)webrequest.GetResponse();
Encoding enc = System.Text.Encoding.GetEncoding(“utf-8”);
StreamReader responseStream = new StreamReader(webresponse.GetResponseStream(), enc);
string result = string.Empty;
result = responseStream.ReadToEnd();

System.ServiceModel.Security.SecurityNegotiationException: Could not establish trust relationship for the SSL/TLS secure channel with authority ‘servernamehere’. —> System.Net.WebException: The underlying connection was closed: Could not establish trust relationship for the SSL/TLS secure channel. —> System.Security.Authentication.AuthenticationException: The remote certificate is invalid according to the validation procedure.

Please anyone can suggest.

It’s a certificate error. You’ll need to disable the certificate validation.

I am new to this, could you please let me know from where we can disable the certificate?

The other option is to add a self-signed certificate (if it’s not already) and then import that certificate into your system. Disabling SLL will pass all transactions, including passwords, in the clear.

When working with REST, first make sure you can communicate with the service using abrowser using the OpenAPI/Swagger page and then a utility like Postman. This eliminates all the plumbing issues. Now start coding.

If you’re at 10.2.500 or higher, I prefer to do all the BO logic in a function and expose that interface to REST. It makes upgrading your clients far easier and it can reduce the traffic on the wire. If you can do Method Directives then you can do Epicor Functions.

1 Like

This is interesting, can you please explain this point? I can’t get my head around this.

Sure. Let’s say you want to add a sales order via REST. If you use the Sales Order REST service, you have to mimic all of the calls that the .Net Client makes: New Header, New Line, etc. The logic of doing this is embedded in your client and each call is another round trip over the network.

In an Epicor Function, you do all these calls at the server instead of embedding this logic in the client. Instead you expose a function via REST that takes in a JSON string. That function parses the string and does some data validation, and if all is good, it calls the same BOs the client would but without all the network traffic. The function would then return information back to your client - basically all of the input but with the addition of the OrderNum.

The nice part of this architecture is that you’ve encapsulated the details away from the client making it less likely to break during upgrades since the only changes would have to be done at the server. It is also easy to do automated testing via a tool like Postman instead of the web interface.

Hope that makes sense.

Mark W.


I have called the BO method for new record insertion of Receipt Entry. Below mentioned code is not working fine. Anyone can suggest.

ReceiptDataSet ds = new ReceiptDataSet();
var wcfBinding = NetTcp.UsernameWindowsChannel();
var appServer = new Uri(“net.tcp://localhost/Testing/Erp/BO/Receipt.svc”);
using (var receiptClient = new Erp.Proxy.BO.ReceiptImpl(wcfBinding, appServer))
receiptClient.ClientCredentials.UserName.UserName = “manager”;
receiptClient.ClientCredentials.UserName.Password = “manager”;
receiptClient.GetNewRcvHeadWithPONum(ds, 3, “”, 29);
ds.RcvHead[0].Company = “EPIC04”;
ds.RcvHead[0].VendorNum = 3;
ds.RcvHead[0].PurPoint = “”;
ds.RcvHead[0].PONum = 29;
ds.RcvHead[0].PackSlip = “PO-29”;

After modifying the code getting below mentioned error “Could not load file or assembly ‘Erp.Common.ContractInterfaces, Version=, Culture=neutral, PublicKeyToken=5d3fa3c7105d7992’ or one of its dependencies. The located assembly’s manifest definition does not match the assembly reference. (Exception from HRESULT: 0x80131040)”

var wcfBinding = NetTcp.UsernameWindowsChannel();
var appServer = new Uri(“net.tcp://Server Name/Instance Name/Erp/BO/Receipt.svc”);
using (var receiptClient = new Erp.Proxy.BO.ReceiptImpl(wcfBinding, appServer))
receiptClient.ClientCredentials.UserName.UserName = “manager”;
receiptClient.ClientCredentials.UserName.Password = “Login@123”;
ReceiptDataSet objds = new ReceiptDataSet();
ReceiptDataSet.RcvHeadRow objRow = objds.RcvHead.NewRcvHeadRow();
objRow[“Company”] = “KSA”;
objRow[“VendorNum”] = 203;
objRow[“PurPoint”] = “”;
objRow[“PONum”] = 27;
objRow[“PackSlip”] = “PO-27”;
objRow[“EntryPerson”] = “manager”;
objRow[“RowMod”] = “A”;

As a little sample of how this stuff can work, the following function accepts a case number and performs a simple GetRows() to retrieve the task list of a given case and return the results:

I’ve started using Epicor Functions like that one to build custom Siri Shortcuts that let me perform tasks with Siri :smiley:

Once you promote a library to production via the actions menu, it becomes available to call directly with a request. You will need to generate an API key in API Key Maintenance to be able to call the function. You can view and test your function in the browser via either https:/server/Environment/Apps/resthelp/#/home and then click on the Epicor Functions button on the left, or you can go to https://server/Environment/api/v2/efx/{Company}/{Library}/{Function}, or you could use a tool like Postman