Epicor REST V2 Question (Chicken and Egg Problem)

As far as I can tell for all the REST calls in V2 you must pass in the company in the URL (even for things like Login)

https://<URL>/<Instance>/api/v2/odata/<Company>/Ice.LIB.SessionModSvc/Login

Now it seems I have an chicken / egg problem. I can’t pass in a company ID in the URL because I don’t know the company ID… and I can’t get a list of companies cause all the rest calls require a company be passed in.

Am I missing something obvious? How would I login or make any calls for the first time in an App if I don’t know the Company ID before hand. There should be a way to get a list of Companies out of the system without having a pre-existing company ID… no?

CC: @Olga @Patrick.Ferrington @Edge

Think App that doesn’t know anything about your system before hand (app store app)

I suppose I could prompt the user to type it, but I will eat my hat if you can find regular users who on average know their company ID… or what a company ID is…

3 Likes

That’s because you haven’t filled in your clear-text, hard-coded DB call to retrieve the companies…

Oh, wait…

I don’t know a lot about v2. It is more for @SAD or @JeffLeBert

I would think this would be by design, I don’t think you want a list of companies to be known to entities that aren’t authorized to view them.

there is global_services.json but how it is used you probably can find in documentation

@Doug.C you would have to have a Username and password and API key to Epicor
And I would hope it would return a list of companies which the current is user is authorized to see only.

But currently there is (as far as I can tell) zero way to “Login” or do anything in Rest V2 without knowing the Company ID before hand.

Epicor’s own EMWW prompts you for username / password then it gives you a dropdown of companies to select from (though it uses V1)

Yeah, I don’t think this is possible with V2 unless there is a method outside of the /{Company}/ scope, but I haven’t seen it.

I like Chicken better than eggs anyway :slight_smile:

But the Swagger screen does it…right? :thinking:

Or does it v1?

It does it in V1 Mark, in V2 it asks you to provide a company ID.

However @Olga just gave us the answer. It is the global services, it requires configuration on the server side. Set an AppSetting flag in the web.config but you can list specific services that can be “pinged” without a company.

I knew there had to be a way!

Documentation REST Services V2 Page 41

Thank you @Olga!

3 Likes

what is appsetting flag?

You have to add a key to the appSetting section of the web config

<add key="GlobalServices" value="global_erp_services.json" />

Then modify the global_erp_serivces.json file to contain the list of services you want to allow

{
 "ignoreDefaults": false;
 "globalServices": ["Erp.BO.CompanySvc"]
}

Thanks again @Olga I should have RTFM’d (Read that Fantastic Manual)

4 Likes

why spend 5 minutes reading the documentation when you could spend 5 days attempting it on your own??

2 Likes

I mean… yeah

In my defense I didn’t think that such a thing existed in the documentation. It is pretty obscure… However Epicor has come a HUGE way in their documentation and I should remember that. hat tip

4 Likes

In the first place. Don’t use global services hack for the company bound services (e.g. for the CompanySvc). This feature is for infrastructure services (e.g. helthcheking).

To get list of companies (AFAIR available for the current user) try to call
https://<URL>/<Instance>/api/v2/environment

1 Like

Hey look more stuff in the… FM… I didn’t tread :grin: thanks @SAD

1 Like

You are welcome, Jose

1 Like