Rest API authentication

Hi All,
I’m getting authentication error with the correct user credentials:

Client error response [url] https://servername/EpicorERPTest/api/v1/Erp.BO.JobStatusSvc/List [status code] 401 [reason phrase] Forbidden

I’m using GuzzleHttp Client on Laravel:

$client = new Client();

$res = $client->get(‘https://servername/EpicorERPTest/api/v1/Erp.BO.JobStatusSvc/List’, [‘verify’ => false], [‘auth’ => [‘user’,‘password’]]);

What am I missing? Thanks.

Are you passing the authorization header key with a base64 encoded username: password?

I don’t know what it would look like as I’m unfamiliar with that http client but for basic auth you would want to add that authorization header


I think there is some documentation in the REST services developer guide

Thanks Aaron. I am not sure how to add the authorization header but will look for the documentation.

I made the following change but still getting the same 401 Forbidden error:

$credentials = base64_encode(‘user:password’);

$res = $client->get(‘https://servername/EpicorERPTest/api/v1/Erp.BO.JobStatusSvc/List’, [‘verify’ => false], [‘Authorization’ => 'Basic '.$credentials]);

Can you get it to work with a different http client like postman?
I don’t like diagnosing plumbing issues with code. Get it worked out in something straightforward (like postman), then adjust your code after you connect with the other client

https://docs.guzzlephp.org/en/stable/request-options.html#auth

1 Like

I got it worked with the following:

$client = new Client([‘defaults’ => [‘verify’ => false]]);
$credentials = "Basic " . base64_encode(‘user:password’);
$request = $client->createRequest(‘GET’, ‘https://servername/EpicorERPTest/api/v1/Erp.BO.JobStatusSvc/List’, [‘headers’ => [‘Authorization’ => $credentials]]);
$result = $client->send($request);

2 Likes