Specifying site via REST API

Hello, I am trying to start/stop shop floor activity via the REST API and the LaborSvc endpoints.

When attempting to start an activity I am receiving “invalid Job Number”, so I manually started an activity in MES and am trying to use the API to end it. However, when I post the dataset from the Erp.BO.LaborSvc/EndActivity endpoint to the Erp.BO.LaborSvc/CheckWarnings endpoint, I receive the following:

{
  "HttpStatus": 400,
  "ReasonPhrase": "REST API Exception",
  "ErrorMessage": "Resource Group not valid for the Site.",
  "ErrorType": "Ice.BLException",
  "ErrorDetails": 
    {
      "Message": "Resource Group not valid for the Site.",
      "Type": "Error",
      "Table": "LaborDtl",
      "Field": "ResourceGrpID",
      "Program": "Erp.Services.BO.Labor.dll",
      "Method": "validateWcCode"
    }
}

The Access Scope has the “All Companies” box checked, and the user associated with the access token has access to all sites, so I am guessing there is something I’m missing about how to properly start/stop activity on an instance with multiple sites.

I also found this thread but didn’t find any relevant information about my error: REST API Start and Stop Production Activity

Thanks in advance for any guidance about this, or documentation about replicating MES behavior via REST.

Welcome Ben!

Have you run a trace of the transaction that you’re trying to automate?

There is also a better practice to do the Epicor work (also from the trace) into an Epicor Function and then call the function using the REST endpoint. There are several posts about the benefits of this approach.

Oh, have you looked at the REST Guides for your version on EpicWeb? You’ll find that site is passed in through the “Call Settings” header values.

Thank you, that resolved the issue and I can now end labor. However when starting labor I now encounter: “Labor cannot be reported to a non-location resource.”

Do you know what Erp.BO.LaborSvc/StartActivity expects to start an OP on a Job? I am passing the Laborhed from the current clock, modifying the response’s LaborDtl property with the Job, Op. Seq., Op. Code, and Resource Group ID, and then passing this modified dataset to Erp.BO.LaborSvc/Update but perhaps this is the wrong approach?

Perhaps I am going about this wrong, do I need to POST a new item to /{currentCompany}/Erp.BO.LaborSvc/LaborDtls and then use that resulting record for the StartActivity endpoint?

The API documentation is scant on usage details, the input bodies for virtually all of the RPCs in this namespace are identical.

This is the pain of REST calls. There will never be documentation that’s up to date, which is why tracing is the true North. The other pain is guessing which fields are required. This is why I prefer using Epicor Functions. You reduce the calls on the wire, reduce coupling, and make testing easier. Everyone starts where you are, but eventually many move to functions. There are several posts if you search the forum.

1 Like

Unfortunately this extension only seems to work for the ERP web app, no request data is gathered when running the MES web app.

Edit: Actually, the XHR requests are fairly self-explanatory in the Network tab, hopefully this will be enough to get me up and running.

Thanks again for pointing me in the right direction, @Mark_Wonsil

1 Like