问题
I am having this problem I enabled the webservice from prestashop and I can access it if I write the URL directly passing the parameter from post method http://underwearstudio.mx/pruebas/api?&ws_key="mykey".
But If I try to access without passing the ws_key as parameter it keeps asking me to authenticate.
From what I read when authentication is prompted you need to use the API key as username and leave the blank password, but it just keeps prompting the authentication.
What can I do?
I was trying to follow this tutorial.(http://doc.prestashop.com/display/PS15/Chapter+2+-+Discovery+-+Testing+access+to+the+web+service+with+the+browser)
Any help would be greatly appreciated
回答1:
For googlers such as myself:
as in the current version, 1.6.1.1, one need to add this code [?&ws_key=YourSecretKey
] at the end of the url and access the webservice with this method, as the passing as username (stated in the docs) does not work
http://[YourPrestaShopUrl]/api?&ws_key=YourSecretKey
eg: http://192.168.1.148/api/products?limit=5&ws_key=EUQ1J6NT1KVJ1S9SYGRCLGQE8IJU66DA
to accomplish this using the webservice library , you may add this line :
$url .= '&ws_key=' . $this->key;
at line 116 (in current version), which is in the
protected function executeRequest($url, $curl_params = array())
and right before the initializing the cURL :
$session = curl_init($url);
which I have proposed in this request
You may find the working Library in this gist for now
回答2:
Just create an .htaccess within webservice folder with:
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]
</IfModule>
回答3:
Hello I am also gone through same problem if You want to avoid that authentication of prestashop then you can add the consumer key for that prestashop store in api url such as follows
http://localhost:8080/prestashop/api/products/2/?ws_key=TCXXHYPCT8DHWW64QXU1KEQVF4PQ1SJ6
here while accessing products details you can add consume key to access the products details. It can be also useful when if you are using prestashop web service apis in other platform. Thanks
回答4:
From their documentation, it looks like you should be able to put your API key into the URL in place of where a username would go in a regular HTTP request, e.g:
http://[yourapikeyhere]@example.com/api/customers/
This quote from "Testing access to the web service with the browser":
The shop should prompt you for a username and a password to enter. The ID is the authentication key and there is no password.
... seems to match up with what you said about the username vs password. It looks like these guys are using the API key as the username in a regular HTTP basic authentication sense with no password (otherwise would be http://user:password@example.com
), which seems to match up with the RESTful URL example they provided above. If basic authentication via your browser isn't working, I'd suggest it's more likely either that your API key is wrong - keep in mind it's highly likely to be case sensitive.
回答5:
Since prestashop 1.7.4, they are providing an alternate method.
ie; to access http://yourstore.com/api/
it will prompt for username/password.
Enter the key you generated as username and leave password field empty.
This will give you an output like
<prestashop xmlns:xlink="http://www.w3.org/1999/xlink">
<api shopName="Tureds">
<products xlink:href="https://www.tureds.com/api/products" get="true" put="false" post="true" delete="false" head="false">
<description xlink:href="https://www.tureds.com/api/products" get="true" put="false" post="true" delete="false" head="false"> The products</description>
<schema xlink:href="https://www.tureds.com/api/products?schema=blank" type="blank"/>
<schema xlink:href="https://www.tureds.com/api/products?schema=synopsis" type="synopsis"/>
</products>
</api>
</prestashop>
Remember
- to enable webservice in the backend.
- No need to regenerate .htaccess file. Regeneration of .htaccess file is for older versions of prestashop.
来源:https://stackoverflow.com/questions/28749812/prestashop-web-service-api-keeps-asking-for-authentication