Prestashop Web Service API keeps asking for authentication

倖福魔咒の 提交于 2019-12-03 22:17:31

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

Just create an .htaccess within webservice folder with:

<IfModule mod_rewrite.c>
    RewriteEngine on
    RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]
</IfModule>

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

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.

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

  1. to enable webservice in the backend.
  2. No need to regenerate .htaccess file. Regeneration of .htaccess file is for older versions of prestashop.
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!