First time here? Check out the FAQ!
0

Receiving 401 - Unauthorized: Access is denied due to invalid credentials

I am able to successfully get a RETS response when going to http://manhattan.rets.paragonrels.com... in a web browser, my user is SRram1, but when I try to use cURL to login, I get the access is denied due to invalid credentials error.

In other RETS implementations we are able to use cURL to login, send a search query, and get results back for our integration.

JamesPetree's avatar
JamesPetree
asked 2018-07-25 10:37:31 -0500
edit flag offensive 0 remove flag close merge delete

Comments

Are you using Digest authentication with cURL for your login?

bwolven's avatar bwolven (2018-07-25 14:09:20 -0500) edit

I am not currently. I tried connecting with and without it and still receive the error.

JamesPetree's avatar JamesPetree (2018-07-25 16:26:14 -0500) edit

With http we use digest. With https we use Basic.

bwolven's avatar bwolven (2018-07-25 16:38:17 -0500) edit

Ok I tried adding digest since I'm connecting to http. I'm still receiving the error.

JamesPetree's avatar JamesPetree (2018-07-25 16:51:35 -0500) edit

I'm working with a simplified cURL right now just trying to get a successful connect. I'll post my code in a few comments due to character limits.

$curlRets = curl_init(); $headers[] = "Accept: /"; $headers[] = "RETS-Version: RETS/1.7.2"; $headers[] = "User-Agent: RETSConnector/1.0"; curl_setopt($curlRets, CURLOPT_URL, $loginURL); curl_setopt($curlRets, CURLOPT_HTTPHEADER, $headers);

JamesPetree's avatar JamesPetree (2018-07-25 17:27:00 -0500) edit

curl_setopt($curlRets, CURLOPT_RETURNTRANSFER, 1); curl_setopt($curlRets, CURLOPT_HTTPAUTH, CURLAUTH_DIGEST); curl_setopt($curlRets, CURLOPT_USERPWD, $username.":".$password);

$output = curl_exec($curlRets); curl_close($curlRets);

JamesPetree's avatar JamesPetree (2018-07-25 17:27:12 -0500) edit

Looks like the line breaks were taken out. Hopefully that helps. Is there a sample cURL code that you have that I could try?

JamesPetree's avatar JamesPetree (2018-07-25 17:28:16 -0500) edit

Any assistance with cURL sample code would be greatly appreciated.

JamesPetree's avatar JamesPetree (2018-07-27 14:59:34 -0500) edit

You may be better off using PHRETS than trying to roll your own. It will make it much easier to work with RETS. https://github.com/troydavisson/PHRETS

bwolven's avatar bwolven (2018-07-27 15:02:23 -0500) edit

Were you able to get this working using PHRETS?

bwolven's avatar bwolven (2018-07-30 14:59:57 -0500) edit

I have downloaded it and have been trying to get it to work. I am unfamiliar with Composer, though, which it says to use to "install" PHRETS. I found instructions on installing locally with Composer then just copy up the files to the server, which I'll be working on next.

JamesPetree's avatar JamesPetree (2018-07-31 10:47:40 -0500) edit

Glad to hear you are making some progress. I'm not a PHP developer, but I was able to follow the instructions and use composer to install the needed components. Just running scripts from the command line I was able to login, search and download data and logout.

bwolven's avatar bwolven (2018-07-31 10:55:24 -0500) edit

I was able to install composer and get PHRETS unpacked. I've copied up to the server and tried running, but I'm getting syntax errors due to the splat operators. Trying to troubleshoot that issue now.

JamesPetree's avatar JamesPetree (2018-07-31 15:23:51 -0500) edit

Ok, the issue is the server is running php version 5.4.16 and PHRETS requires 5.6 minimum. I'll likely need another solution.

JamesPetree's avatar JamesPetree (2018-07-31 15:26:40 -0500) edit

Sorry to hear that. It's much better to use an existing tool than to try to roll your own from scratch.

bwolven's avatar bwolven (2018-07-31 15:32:39 -0500) edit

Any insight or ideas why that cURL would be returning an invalid credentials error?

JamesPetree's avatar JamesPetree (2018-07-31 15:37:36 -0500) edit

No. But you could maybe look at the PHRETS source on GitHub and get some idea of how the connection is being made using cURL.

bwolven's avatar bwolven (2018-07-31 15:42:31 -0500) edit
add a comment see more comments

1 Answer

0

I was able to login using cURL like this using your info.

$loginURL = 'http://manhattan.rets.paragonrels.com/rets/fnisrets.aspx/manhattan/login?rets-version=rets/1.7.2';

$username = 'SRram1';

$password = '**';

$curlRets = curl_init();

$headers[] = "Accept: /";

$headers[] = "RETS-Version: RETS/1.7.2";

$headers[] = "User-Agent: RETSConnector/1.0";

curl_setopt($curlRets, CURLOPT_URL, $loginURL);

curl_setopt($curlRets, CURLOPT_HTTPHEADER, $headers);

curl_setopt($curlRets, CURLOPT_RETURNTRANSFER, 1);

curl_setopt($curlRets, CURLOPT_HTTPAUTH, CURLAUTH_DIGEST);

curl_setopt($curlRets, CURLOPT_USERPWD, $username.":".$password);

$output = curl_exec($curlRets);

echo $output ;

curl_close($curlRets);

bwolven's avatar
bwolven
answered 2018-07-31 15:58:14 -0500, updated 2018-07-31 16:00:01 -0500
edit flag offensive 0 remove flag delete link

Comments

Yes! It works! Thank you very much. It is very similar to what I had before, but as we know, one little thing can keep it from working.

JamesPetree's avatar JamesPetree (2018-07-31 16:17:00 -0500) edit

All I did was copy what you had before and set the 3 variables at the top. One thing to keep in mind if you roll your own is you will need to handle cookies too. And make sure to call logout when finished using the session.

bwolven's avatar bwolven (2018-07-31 16:24:22 -0500) edit

Just an FYI, in my code, in the headers info, I had "Accept: /", I changed it to "Accept: /" with no asterisks, like your example, and it worked in my old code. I have the script writing a cookies file and logging out successfully as well. Thanks again!

JamesPetree's avatar JamesPetree (2018-07-31 17:05:20 -0500) edit

Ok. I had asterisks too but the group stripped them out. Probably should have them.

bwolven's avatar bwolven (2018-07-31 17:08:08 -0500) edit
add a comment see more comments

Your Answer

Login/Signup to Answer