Epicor Rest Helper (Nuget) Updated V2

is the username and password from domain or Epicor login?

It’s Epicor Login

Is there a callback you can do to check if it was executed properly?

It returns and obejct with errors and such see examples above

I had to recreate the function CreateBearerToken because of the certificate:

public static bool CreateBearerToken()
        {
            HttpClient httpClient = new HttpClient();
            if (EpicorRest.IgnoreCertErrors)
            {
                // Create an HttpClientHandler object and set to use default credentials
                HttpClientHandler handler = new HttpClientHandler();
                // Set custom server validation callback
                handler.ServerCertificateCustomValidationCallback += (sender, cert, chain, sslPolicyErrors) => true;

                httpClient = new HttpClient(handler);
            }
            httpClient.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
            string requestUri = "https://" + EpicorRest.AppPoolHost + "/" + EpicorRest.AppPoolInstance + "/TokenResource.svc/";
            HttpRequestMessage httpRequestMessage = new HttpRequestMessage(HttpMethod.Post, requestUri);
            httpRequestMessage.Headers.Add("username", EpicorRest.UserName);
            httpRequestMessage.Headers.Add("password", EpicorRest.Password);
            HttpResponseMessage result = httpClient.SendAsync(httpRequestMessage).Result;
            if (result.IsSuccessStatusCode)
            {
                dynamic val = JsonConvert.DeserializeObject<object>(result.Content.ReadAsStringAsync().Result);
                EpicorRest.BearerToken = val.AccessToken;
                return true;
            }
            throw new Exception($"{(int)result.StatusCode} ({result.ReasonPhrase})");
        }
1 Like

nice Catch I’ll make a fix for it
Thanks!!

1 Like

Done, Updated Lilbrary to 2.0.3

3 Likes

Hello, I was looking for the github repo; is the source available please?
Thank you,
-J

3 Likes

@josecgomez - this is absolutely brilliant. Thank you so much for sharing this.
Works a treat!!

Thank you @josecgomez and all those involved for all your work on this.

I’ve finally started dipping my toe into REST and your work has saved me a ton of time coming up to speed. I am using Epicor 10.2.300.5, EpicorRestAPI 2.0.4, Newtonsoft.Json 12.0.3 and RestSharp 106.11.7.

I have working examples of BoGet, BoPost and BoDelete so I feel I understand how this works, but I cannot get the PoPatch to work. I am able to do so successfully using the Epicor REST Swagger UI so that should eliminate any REST bugs with my older Epicor version.

Even if I use your exact example code from above (of course I have done a BoPost first to get the ABCCode = “Z” created), it fails with a BadRequest.

EpicorRest.AppPoolHost = restHost;
EpicorRest.AppPoolInstance = restPool;
EpicorRest.UserName = restUser;
EpicorRest.Password = restPass;
EpicorRest.APIVersion = EpicorRestVersion.V1;
EpicorRest.Company = restCompany;
EpicorRest.License = EpicorLicenseType.Default; 

var patchData = new {
                Company = EpicorRest.Company,
                ABCCode1 = "Z",
                CountFreq = 1
};
CallContextHeader callContext = new CallContextHeader();
var response = EpicorRest.BoPatch("Erp.BO.ABCCodeSvc", "ABCCodes", patchData, callContext);

I continue to get an HttpStatus 400 BadRequest, Request is not supported. Method: PATCH. The Response body value looks like this:

“{“Company”:“FCII01”,“ABCCode1”:“Z”,“CountFreq”:1}”

Any help in directing me where to look to solve this would be greatly appreciated.

Tim

1 Like

Epicor/Kinetic is not totally REST-compliant at this point. I use the Swagger/Open-API page to see which requests are valid.

image

When you are patching I believe your endpoint needs to have the Primary Key

Notice the Patch call has the Company and ABCCode in the URL as params.

So you need to do

var response = EpicorRest.BoPatch("Erp.BO.ABCCodeSvc", "ABCCodes('MyCompany','A')", patchData, callContext);
3 Likes

Why does your Swagger Page have Delete and Patch and mine does not? :thinking:

Because the new helper page is a bit annoying by default it shows you the method available to the “FIRST” endpoint but if you click on the second endpoint ABCCodes()… (Square in my picture) then you’ll get additional options available for that EndPoint

2 Likes

Here’s a better way of knowing what you are selected on.

1 Like

Got it! I have it working now. Thank you @josecgomez.

@Mark_Wonsil had me lost since my Swagger page showed the Patch and I was able to make the call successfully using Swagger. Good to know ahead of time the newer Swagger page plays differently than mine.

1 Like

Terribly sorry for the redirection. I certainly learned something!

2 Likes

@Mark_Wonsil no need to apologize. You have helped me so much, I’m always so grateful to see a response from you!

1 Like

Tim, nice work!

1 Like

First I want to say thank you because this is exactly the tool I was looking for and going to build for myself if I couldn’t find it.

I’m just getting started and I can’t find any Async methods on this library. I see that it’s built upon RestSharp which does have Async methods.

Is there an ongoing effort to add async methods? Is there a GitHub repo where I could help build them?