Call Epicor Function via REST from C# code outside of Epicor

The REST calls in my WinForms app to an Epicor Function work great until I make the call for an Epicor company that is NOT the company where the Function was created. For example, the Epicor Function is created in CompanyA but I’m trying to get an order number that is in CompanyB.
When I debug the below code the RequestURI looks like this
{https://Server/Instance/api/V2/efx/staging/CompanyB/SalesOrderSvc/GetByID}
The ResponseStatus is NotFound, ResponseData is null and ResponseBody is “”.
Is there a way to get data from multiple companies when calling Functions outside of Epicor?
The function in CompanyA:


The REST call to the function:

        public static async Task<SalesOrderFunction> GetByID(int orderNumber, string company)
        {
            try
            {
                CallContextHeader callContext = new CallContextHeader();
                dynamic postData = new
                {
                    iOrderNum = orderNumber
                };
                var response = await EpicorRest.EfxPostAsync("SalesOrderSvc", "GetByID", postData, callContext, true);
                if (response.IsErrorResponse)
                {
                    TraceLog.Write(string.Format("Failed to GetByID: {0}", response.ResponseError));
                }
                return JsonConvert.DeserializeObject<SalesOrderFunction>(response.Response.Content.Trim().ToString());
            }
            catch (Exception ex)
            {
                TraceLog.Write(string.Format("Failed to GetByID: {0}", ex.ToString()));
                throw new Exception(ex.Message);
            }
        }

Any suggestions are appreciated.
Kelly

On the Security tab, make sure the other companies have access to call the function. I think by default it is limited to the company where it was first created.

2 Likes

Boy do I feel dumb. :woman_facepalming:
But I sure am glad it was an easy fix! :joy:
Thanks so much Andrew for your quick response!
Kelly

I’ve been bitten by this more than once, so I was familar with the problem :slight_smile:

1 Like