Epicor Rest Helper (Nuget) Updated V3

Hi,
Yes we will update this library as soon as we get a chance but, for what its worth, this vulnerability isn’t a risk to whatever you are working on on its own unless you are allowing your users to craft their own Web Requests in your app including adding their own headers.

The vulnerability in question is this one

And that is really only a problem if you yourself write bad code using this vulnerable header. It allows you to insert a header in a request containing a Line Break thus generating more than one (split) request.

1 Like

Thank you very much for share the Rest Helper. Im fullstack developer and it is very helpful. So I can create APIs for multi-platform applications

1 Like

Hey Jose,

I am working on a new Blazor web app in which I would like to use your package. However I have concerns that it’s not going to work properly in a multi-user application, because EpicorRest is a static class. Because of this I cannot use it with dependency injection, and basically the entire context is shared across all consumers, which means that I could not have two requests running concurrently on different companies or plants, different bearer tokens, etc…

Would it be possible to add a factory method that would give me a non-static class I could use with dependency injection? Or basically just make EpicorRest non-static and use a singleton internally to maintain current static functionality…

Or should I just fall back to using HttpClient and forget this package? It really would be a shame…

Thanks!

1 Like

Yeah we should be able to do that , we’ve been looking at moving away from static. Let me see what I can do.

3 Likes

Can someone post a simple example of i.e. GetByID plus changing some data and then Update?

In what flavor? Are you doing this externally in C# project?

If so, there are some examples posted in this thread above.

I did not find any simple full flow example with data modification. (like GetByID > change smth > Update).
Reason - trying to play with Rest and this Helper and wondering what would be the best approach to unpack results after GetByID so I will have access to data by column names and then how to pack it back to send it for update.

EDIT:
If I want to call REST from Efx, is it possible to use somehow an existing/current authorization data instead of providing a username and password?

V3 Release Major Update

This release V3 3.0.0.0 contains breaking changes from prior versions as outlined below

The biggest change in this version other than a few bug fixes is to pivot the library to be Instance friendly instead of static. The static approach while it simplified some things it made some other things quite difficult. In order to keep backwards compatibility we still have a static wrapper which should function the same as it always has, below is a breakdown of changes and how to Upgrade easily. This request came from @HLalumiere but also several other users and I have myself encountered issues with this limitation.

  1. EpicorRest and EpicorRestV1 are now instance classes and should be instanciated as follows
EpicorRest myEpicorRestInstance= new EpicorRest();
myEpicorRestInstance.AppPoolHost = "subdomain.domain.tld"; //TLD to your Epicor Server
myEpicorRestInstance.AppPoolInstance = "EpicorDemo700"; //Epicor AppServer Insdtance
myEpicorRestInstance.UserName = "epicor"; //Epicor Username
myEpicorRestInstance.Password = "epicor"; //Epicor Password
myEpicorRestInstance.APIKey = "XXXXXXXXXXXXXXXXXXXXXXXXXXXXX"; //API key required with V2
myEpicorRestInstance.Company = "EPIC03"; //Epicor Company (Current company) Required with V2
myEpicorRestInstance.APIVersion = EpicorRestVersion.V2; //Defaults to V2
myEpicorRestInstance.License = EpicorLicenseType.Default; // You can select the type of license you want to use for the call.

The above approach allows you to have multiple instances of EpicorRest without stepping on each other, it also allows you to maintain multiple Sessions.
2. When instantiating a Session you now need to pass in the instance you’d like to associate with the session as shown below

EpicorRest myEpicorRestInstance= new EpicorRest();
//snip....
using (EpicorRestSession ses = new EpicorRestSession(myEpicorRestInstance))
            {
                var smsSend = new
                {
                    ToPhone = "90445555555",
                    ToMsg = "Rest is so Cool!"
                };
                var rsp = EpicorRest.EfxPost("FacilityPaging", "SendSMS", smsSend);
            }

Again this allows you to have multiple instances and multiple sessions going at once.

  1. When instanciating CallContext you’ll also have to pass in the instance because the client contains information like username company etc.
EpicorRest myEpicorRestInstance= new EpicorRest();
//snip....
CallContextHeader callContext = new CallContextHeader(myEpicorRestInstance); 

The above change also hilights a new class that was added to the project called EpicorCommon which is inherited by both EpicorRestV1 and EpicorRestV2 so each of these instances is in fact an instance of EpicorCommon
4. EpicorRestStaticWrapper class was created as a static wedge instance for backwards compaitbility. To easily upgrade any project without making any changes simply replace EpicorRest.XX with EpicorRestStaticWrapper.EpicorRest.XX and it should be seemless.

 EpicorRestStaticWrapper.EpicorRest.AppPoolHost = TestContext.Properties["AppPoolHost"].ToString();
 EpicorRestStaticWrapper.EpicorRest.AppPoolInstance = TestContext.Properties["AppPoolInstance"].ToString();
 EpicorRestStaticWrapper.EpicorRest.UserName = TestContext.Properties["UserName"].ToString();
 EpicorRestStaticWrapper.EpicorRest.Password = TestContext.Properties["Password"].ToString();
 EpicorRestStaticWrapper.EpicorRest.Company = TestContext.Properties["Company"].ToString();
 EpicorRestStaticWrapper.EpicorRest.CallSettings = new CallSettings(EpicorRestStaticWrapper.EpicorRest.Company, TestContext.Properties["Plant"].ToString(), "", "");
 EpicorRestStaticWrapper.EpicorRest.APIKey = TestContext.Properties["APIKey"].ToString();
 EpicorRestStaticWrapper.EpicorRest.APIVersion = EpicorRestVersion.V2;
 EpicorRestStaticWrapper.EpicorRest.License = EpicorLicenseType.Default;

With this version we also added a full test suite which should help with regression testing.

  1. Updated GetEnvironment to work with both version <=2024.1 >=

.NET Framework: NuGet Gallery | EpicorRestAPI 3.0.0
.NET Core 6+ NuGet Gallery | EpicorRESTAPICore 3.0.0
.NET Standard 2.1 NuGet Gallery | EpicorRESTAPIStandard 3.0.0

13 Likes

Hi Jose,
This is a great addition. I had version 2.2.0.1 working using a single instance and I attempted to move to 3 with multiple instances. Thought I had it, but when I request a BO I get a null variable exception in the BoGet. Oddly enough, if I request the “List” from the Service, it works.

So, to make progress on my project, I used the Static Wrapper and left everything else the same. The problem I have is that the code uses the CallContextHeader which now requires an instance. What should be put in the constructor for CallContextHeader when using the Static Wrapper?

Thanks.
PS. Using the .NEt Framework version.

I’ll look at it in the morning usually you can pass the static “instance”

However can you show me the call you were getting an error with? We should look at that