EpicorRESTApiCore - Error when running POST

I just switched over to using @josecgomez 's new package for .NET 6, and I’m getting the attached errors when trying to instantiate a new EpicorRestSession. Code is below:

            using (EpicorRestSession ses = new EpicorRestSession())
            {
                EpicorRest.AppPoolHost = "https://usaz1app008p.am.dir.grpleg.com";
                EpicorRest.AppPoolInstance = "EpicorERPPilot";
                EpicorRest.UserName = Properties.Settings.Default.BatchEntryPerson;
                EpicorRest.Password = Properties.Settings.Default.BatchEntryPass;
                EpicorRest.APIKey = Properties.Settings.Default.APIKey;
                EpicorRest.Company = Properties.Settings.Default.CompanyID;
                EpicorRest.APIVersion = EpicorRestVersion.V2;
                EpicorRest.License = EpicorLicenseType.Default;

                var smsSend = new
                {
                    GroupID = $@"{BatchGroupID}"
                };

                var rsp = EpicorRest.EfxPost(Properties.Settings.Default.RESTLibrary, Properties.Settings.Default.RESTFunction, smsSend);

                if (rsp.IsErrorResponse)
                    Console.WriteLine(rsp.ResponseError.ToString());
            }


Don’t use HTTP/ HTTPS we take care of that :wink: (on your host name)

1 Like

I apologize, the errors came up before adding https:// to the creation. Question: Should the AppPoolHost property have the entire endpoint, or just the server name? Thing actually fails in debug as soon as the EpicorRestSession call executes…

Jose, could this be happening due to the server using a self-signed certificate? I get the following if I go to the server address in Chrome:

There’s a bypass bad cert flag
No the Host should just be the TLD the AppPoolInstance would the your Epicor Instance name

It is wholy documented here

1 Like

You can’t start a session until you have the EpicorSettings in place.

Jose, below is the code I currently have in my program. It’s throwing an exception as soon as the EpicorRestSession object is created. What am I missing?

        private static void CallPostFunctionNew()
        {
            EpicorRest.AppPoolHost = "(server FQDN)";
            if (_ServerID == "")
                EpicorRest.AppPoolInstance = "EpicorERP";
            else
                EpicorRest.AppPoolInstance = _ServerID;
            EpicorRest.UserName = Properties.Settings.Default.BatchEntryPerson;
            EpicorRest.Password = Properties.Settings.Default.BatchEntryPass;
            EpicorRest.APIKey = Properties.Settings.Default.APIKey;
            EpicorRest.Company = Properties.Settings.Default.CompanyID;
            EpicorRest.APIVersion = EpicorRestVersion.V2;
            EpicorRest.License = EpicorLicenseType.Default;
            EpicorRest.IgnoreCertErrors = true;

            using (EpicorRestSession ses = new EpicorRestSession())
            {
                var smsSend = new
                {
                    GroupID = $@"{BatchGroupID}"
                };

                var rsp = EpicorRest.EfxPost(Properties.Settings.Default.RESTLibrary, Properties.Settings.Default.RESTFunction, smsSend);

                if (rsp.IsErrorResponse)
                    Console.WriteLine(rsp.ResponseError.ToString());
            }
        }

What is the error? What version of the Library are you using?

Jose, here’s the error:
System.MissingMethodException
HResult=0x80131513
Message=Method not found: 'Void RestSharp.RestClient…ctor(RestSharp.RestClientOptions, System.Action1<System.Net.Http.Headers.HttpRequestHeaders>)'. Source=EpicorRESTAPICore StackTrace: at EpicorRestAPI.EpicorRest.HttpJson(Method iMethodType, String iBaseMethodURl, String iFormattedParams, Object iJsonData, CallContextHeader iCallContext, Dictionary2 requestHeaders)
at System.Dynamic.UpdateDelegates.UpdateAndExecute6[T0,T1,T2,T3,T4,T5,TRet](CallSite site, T0 arg0, T1 arg1, T2 arg2, T3 arg3, T4 arg4, T5 arg5)
at EpicorRestAPI.EpicorRest.BoPost(String iBO, String iMethod, Object iData, CallContextHeader iCallContext)
at EpicorRestAPI.EpicorRestSession…ctor()
at APOCInvoiceLoad.Program.CallPostFunctionNew() in M:\IT_Volume\SourceCode\CSharp_102700\APOCInvoiceLoad\APOCInvoiceLoad\Program.cs:line 1427
at APOCInvoiceLoad.Program.CreateAPInvoiceBatch(String originalFile) in M:\IT_Volume\SourceCode\CSharp_102700\APOCInvoiceLoad\APOCInvoiceLoad\Program.cs:line 1084

This exception was originally thrown at this call stack:
[External Code]
APOCInvoiceLoad.Program.CallPostFunctionNew() in Program.cs
APOCInvoiceLoad.Program.CreateAPInvoiceBatch(string) in Program.cs

I’m using EpicorRESTAPICore 2.2.0.2

Jose, I’m still getting the error I posted back on 9/14, also posted the RESTAPICore version I’m using. Any ideas?

What version of NET Core are you running?

I have Microsoft .NET Core SDK 3.1.414 (x64) installed on my system

Right but what version of .NET is the Project you are trying to write?

The project is targeted at .NET 6.0, probably should be targeted at .Net Core 3.1, right? (duuh…)

Jose, I retargeted the project to .NET Core 3.1, however EpicorRESTAPICore now shows an error saying the type or namespace cannot be found. I have the NuGet package installed, what could I still be missing?

No .NET 6 is fine I just needed to understand what version you were working with so I can provide help. Stand by

If your project is targeting .NET 6 you should use version 2.2.0.2 of the library which should automatically install Newtonsoft 13.0.2 and RestSharp 108.0.3
image

I already have the versions you listed or higher…
image

That’s the wrong version of Rest Sharp.

1 Like

OK… Switched RestSharp versions to the correct one(108.0.3), I’ll try it and let you know

1 Like