REST call gives 403 error - basic authorization

We are trying some external rest calls and it was going really well.

I tested it with a little javascript function that required the user to enter their Epicor credentials. This works.

So our developer prototypes an application using this and its all good.
But now its time to do this for real and they want a general login that we access securely and fill in so that users do not have to enter their epicor login credentials.

I create a user, verify that it can log into Epicor and try it on my little JS page before I hand the credentials over to the developer and I get a 403 invalid login even when I paste the credentials that are working to log into Epicor itself.

I give the user web access, several security groups, even security manager temporarily and no dice.

I tried an API key with a scope of just a BAQ that the prototype application will call and nada. Is there something that I need to set up for a user to be able to remotely connect?

The below HTML page will return data to the consoles and I can extract what I need with JS code.

It just seems odd that the generic user can’t use Rest
(That user can be logged into Epicor with the credentials and it can run that BAQ)

Am I missing something really basic in the user setup?

I included the JS - it was a fun way to access a BAQ

 <!DOCTYPE html>
    <html>
    <head>
        <title>Peak Processing - Epicor REST Javascript Test</title>
	<IMG SRC= "PeakLogo.jpg"><BR><BR>
    </head>
    <body>
 		 <input type="text" id="myUserID" placeholder="UserID">
		<input type="password" id="myPassword" placeholder="Password" type="password">


 

	
               <button onclick="getEpicorData()">Submit</button>

        <script>



	async function getEpicorData(baqID, companyID = 'YourCompanyID') {


const url = "https://**ourserver**.epicorsaas.com/SaaS508/api/v1/BaqSvc/VendorListReactPOProject?Company='**ourcompanynumber'"


const myUserID = document.getElementById("myUserID").value;
const myPassword = document.getElementById("myPassword").value;
const loginString = myUserID + ":" + myPassword;



  try {
    const response = await fetch(url, {
      method: 'GET',
      headers: {
        'Accept': 'application/json',
        'Content-Type': 'application/json',
        'Authorization': 'Basic ' + btoa(loginString)
      }
    });

    if (!response.ok) {

	var errorline = `HTTP error! status: ${response.status}   `;
	if (response.status = '401')
	{
		errorline += ' - Invalid Login';
	}
	alert(errorline);
      throw new Error(`HTTP error! status: ${response.status}`);
    }


 return data;
  } catch (error) {
    console.error('Error fetching Epicor data:', error);
    throw error;
  }
}

** Adding a API key to the mix just gave a login error, even if I used my credentials as the basic authorization part of the string

The BAQ itself just returns a list of our vendors

Where is your api key?

You need both user/pass and the api key.

See below.

1 Like

Oh I see, that’s an API v1 call.

You will need to open the Kinetic version of User Maintenance, and chose to allow that user access to API v1.

Or switch to API v2 and do what I said before.

3 Likes

:upwards_button: This is the way

2 Likes

Thank you. Both worked!

I tried it in V1 with basic and then pulled in the APIkey and have it working with V2.

I use the classic screen for when I have to manually tweak a user so missed that.

I have a function that I wrote that sets up users , employees and resources when I onboard =)

The JS is working now and our developer is happy to be moving along.

2 Likes

I know a little something on occasion. Makes up for all my mistakes.

2 Likes

I copied the JS that had the working call with API key and tried to call a function with the following syntax

https://[KineticServer]/[KineticInstance]/api/v2/efx/[Company]/[Library]/[Function]/

And received an error stating that I needed a valid API key - strange.

Function is published, can be called externally and the company has the permissions to call the function.

Its a very basic function that sends an email to myself.

Forbidden

REST API Exception

Access denied: REST calls must pass a valid API key

Ice.Api.Exceptions.ApiException