bigcommerce / bigcommerce-api-php

Connect PHP applications with the Bigcommerce Platform
https://developer.bigcommerce.com
MIT License
144 stars 185 forks source link

"No credentials were supplied in the request." #160

Open joetwostep opened 9 years ago

joetwostep commented 9 years ago

I wrote a program for a client to automatically update inventory levels for his store using the BigCommerce Legacy API and PHP. This same code has been working fine for months. Suddenly my client tells me it's no longer working and indeed it now gives the error "401: No credentials were supplied in the request." Here is my code:

        Bigcommerce::configure(array(
           'store_url' => BC_STORE_URL,
           'username'  => BC_USERNAME,
           'api_key'   => BC_API_KEY
           ));

        //test to see if we are connected
        $ping = Bigcommerce::getTime();
        if (!$ping) 
           var_dump(Bigcommerce::getLastError());      

It fails on getTime(). I have been using the same url, username, and api key successfully all this time, and even now when I go directly to the store url in my browser I can enter the username and api key into the prompt and view my data that way, so it still works but just not through my program. I'm not sure what could have changed for this to no longer work, any ideas or help? Thanks!

joetwostep commented 9 years ago

OK I happened to find out what the problem is, I thought I'd post an update here in case anyone else ever gets the same problem, for some reason the store URL I was using in the form https://www.storename.com no longer worked, just by chance I tried removing the www part, changing it to https://storename.com and it now works!

beardpapa commented 8 years ago

That is odd. Did the store update their www redirect on the front end where the www path now returns a 301 to the non-www path? If so maybe the credentials are lost as it tries to follow the redirect.

I would probably start with some manual CURL commands to see what is returned and troubleshoot from there.

If you don't want to post the domain here can you open a support ticket with the information so we can look at it internally?

bc-jz commented 8 years ago

This sounds like exactly the problem. The PHP API Library definitely does not carry the headers over on a 301 redirect.

joetwostep commented 8 years ago

Thanks guys for your input, yes it looks like now when I go to their site using www.... it gets redirected and strips off the www. Not sure who added this redirect or why, but they neglected to tell me about it. The program is fixed now that I dropped the www from the login credentials, it just took me 3 hours to figure out the problem so that's what I'm billing them for. Thanks again for your responses!

luongs3 commented 8 years ago

i got the same error when i got image data from image url. i used curl function in php, and get this error: [0] => Array ( [status] => 401 [message] => No credentials were supplied in the request. ) of course, not have www