Epicor Rest Helper (Nuget) Updated (1.1.11)

No HTTPS in the Host.

no change.

PM me your settings as they are
Also what version of Epicor ?

Had to remove http:// or https:// altogether from the AppPoolHost property, then it worked.

Thanks @josecgomez!

1 Like

@josecgomez
Is there any simpler way to do this with your nuget without having to add the parameters one by one?

Dictionary<string, string> laborDic = new Dictionary<string, string>();
laborDic.Add("whereClauseLaborHed", "EmployeeNum = '" + id +"' and ActiveTrans = yes BY PayrollDate");
laborDic.Add("whereClauseLaborDtl", "EmployeeNum = '" + id + "' and ActiveTrans = yes");
laborDic.Add("whereClauseLaborDtlAttch", "");
laborDic.Add("whereClauseLaborDtlComment", "");
laborDic.Add("whereClauseLaborEquip", "");
laborDic.Add("whereClauseLaborPart", "");
laborDic.Add("whereClauseLbrScrapSerialNumbers", "");
laborDic.Add("whereClauseLaborDtlGroup", "");
laborDic.Add("whereClauseSelectedSerialNumbers", "");
laborDic.Add("whereClauseSNFormat", "");
laborDic.Add("whereClauseTimeWeeklyView", "");
laborDic.Add("whereClauseTimeWorkHours", "");
laborDic.Add("pageSize", "0");
laborDic.Add("absolutePage", "0");

JObject laborDetails = EpicorRest.DynamicPost("Erp.BO.LaborSvc", "GetRows", laborDic);

If the where clause is empty maybe try not adding it to the dictionary and see if it works.

I tried doing that. they are required.

@jdewitt6029 because they are required no. We could possibly design it to pull the params and only overwrite the ones you specify in the dictionary (it just gets turned into json later), that might be neat, but as of right now it requires you to provide them just like in any other call. Something we’ll consider as we go to v2 support.

If they are required you need to add them. You would have to manually add these in any case.
However since you are doing a POST here in a GetRows the data it expects is a JSON Object, so you could use a dynamic object instead of a dictionary.
Something like this

var myPostdata = new {
  whereClauseLaborHed =  "Your Where Clause here",
  whereClauseLaborDtl =  "",
  whereClauseLaborDtlAttch =  "",
  whereClauseLaborDtlComment =  "",
  whereClauseLaborEquip =  "",
  whereClauseLaborPart =  "",
  whereClauseLbrScrapSerialNumbers =  "",
  whereClauseLaborDtlGroup =  "",
  whereClauseSelectedSerialNumbers =  "",
  whereClauseSNFormat =  "",
  whereClauseTimeWeeklyView =  "",
  whereClauseTimeWorkHours =  "",
  pageSize =  0,
  absolutePage =  0
};

EpicorRest.DynamicPost("Erp.BO.LaborSvc", "GetRows", myPostdata);
1 Like

ahhh… perfect.

The next hurdle I ran into is that EndActivity on LaborSvc wants a whole freaking LaborDataSet in json passed. The empty Json object in this case is 679 lines / properties long. Doing .Add was out of the question! Even reconstructing it as you last mentioned would take forever.

Instead I called GetRows on LaborSvc, kept that as dynamic, looped through the Json object changing EndActivity and RowMod on ds.LaborDtl for activities i wanted to end, and passed it back as the dynamic postdata in the DynamicPost method. Worked.

So glad you have the dynamically typed functionality added to this nuget!

Yeah Dynamic is the way to go, you do a Get, Update, and send back it works nicely

Hi Joe,
I’m getting ready to dive into doing something similar, do you think you could share your code? I know it’s a big ask but it would likely save me a bunch time.
Ed

@eandres, Sure. It may not be the cleanest code but i was experimenting with creating a page in a MVC (4.7.2) project that would list everyone clocked in and clock give the user the ability to clock them out. First i started out with RestSharp and called a baq. I deserialized the json to a class i had created.

var client = new RestClient("https:/myserver/EpicorTest10/api/v1");
client.Authenticator = new HttpBasicAuthenticator("EpicorUsername", "EpicorPassword");

var request = new RestRequest("/BaqSvc/JDW-WhoIsClockedIn(GRC)/", DataFormat.Json);
var response = client.Get(request);

var employees = JsonConvert.DeserializeObject<EpicorEmployees>(response.Content);

Then i handled an ajax call to clock out the employee, by Id, when they were clicked in the UI. I used @josecgomez’s nuget when i found out it existed.

EpicorRest.AppPoolHost = "myserver";
EpicorRest.AppPoolInstance = "EpicorTest10";
EpicorRest.UserName = "EpicorUsername";
EpicorRest.Password = "EpicorPassword";
EpicorRest.IgnoreCertErrors = true;
EpicorRest.License = EpicorLicenseType.Default; 
EpicorRest.CallSettings = new CallSettings("GRC", string.Empty, string.Empty, string.Empty);

using (EpicorSession sess = new EpicorSession())
{
	Dictionary<string, string> dic = new Dictionary<string, string>();
	dic.Add("$filter", $"EmployeeNum eq '" + id + "' and ActiveTrans eq true");

	dynamic newObj = EpicorRest.DynamicGet("Erp.BO.LaborSvc", "Labors", dic);

	if (newObj.value.Count > 0)
	{
		Dictionary<string, string> laborDic = new Dictionary<string, string>();
		laborDic.Add("whereClauseLaborHed", "EmployeeNum = '" + id + "' and ActiveTrans = yes BY PayrollDate");
		laborDic.Add("whereClauseLaborDtl", "EmployeeNum = '" + id + "' and ActiveTrans = yes");
		laborDic.Add("whereClauseLaborDtlAttch", "");
		laborDic.Add("whereClauseLaborDtlComment", "");
		laborDic.Add("whereClauseLaborEquip", "");
		laborDic.Add("whereClauseLaborPart", "");
		laborDic.Add("whereClauseLbrScrapSerialNumbers", "");
		laborDic.Add("whereClauseLaborDtlGroup", "");
		laborDic.Add("whereClauseSelectedSerialNumbers", "");
		laborDic.Add("whereClauseSNFormat", "");
		laborDic.Add("whereClauseTimeWeeklyView", "");
		laborDic.Add("whereClauseTimeWorkHours", "");
		laborDic.Add("pageSize", "0");
		laborDic.Add("absolutePage", "0");
		dynamic laborDetails = EpicorRest.DynamicPost("Erp.BO.LaborSvc", "GetRows", laborDic);
		foreach (var item in laborDetails.ds.LaborDtl)
		{
			item.EndActivity = true;
			item.RowMod = "U";
		}
		EpicorRest.DynamicPost("Erp.BO.Laborsvc", "EndActivity", laborDetails);
		EpicorRest.DynamicPost("Erp.BO.Laborsvc", "Update", laborDetails);
	}

	Dictionary<string, string> empClockout = new Dictionary<string, string>();
	empClockout.Add("employeeID", id);
	EpicorRest.DynamicPost("Erp.BO.EmpBasicSvc", "ClockOut", empClockout);
            }

I hope that helps! I also did this exact same thing using epicor business objects Interesting enough, when calling the BO objects, it takes slightly longer to get the list of employees.

3 Likes

Oh, that’s cool, I’ve been trying to understand how this stuff actually gets used as there’s not that much out there for a real beginner. Thanks for sharing that.

@jdewitt6029 Thank You! This will be very helpful to kick start my project.
This forum and it’s members are awesome!
Ed

@josecgomez

Hey Jose,

On the DynamicPost method, there is a parameter called ‘replaceReturn’ not mentioned above. Can you explain what that is?

thanks,

Yes some methods return a “returnObj” instead of a “ds” in JSON so if that flag is passed in as true I replace returnObj with ds in the JSON for you
Because most Post methods require a ds and not a returnObj

Which makes it easier to do a GetByID update the data and call Update without having to do a ton of Kung Fu

3 Likes

Thanks Jose!

1 Like

@josecgomez Is there a trick to being able to use LINQ on the results of a REST call? Just copy in into a standard collection first? Apparently Dynamic and LINQ do not get along…

1 Like

You can do linq with dynamic like this

((IEnumerable<dynamic>)ds.ds.ShipTo).Cast<dynamic>().Where(l => l.ShipToNum == shipTo.ShipTo.ToString()).Any();
1 Like