Access Prestashop webservice from JavaScript

2019-02-03 20:02发布

In the Prestashop backend I activated the webservice and I created an authentication key. Testing in browser works well but now I want to access the webservice via JavaScript in a Cordova application.

The response I am getting is 401 (Unauthorized). I'm performing this ajax call (using AngularJS):

$http.get('http://AUTHENTICATION_KEY@url.com/api/employees/2', {})

How do I have to send the authentication key?

I've been searching on the Internet but I did not found anything interesting that solves my problem.

2条回答
ゆ 、 Hurt°
2楼-- · 2019-02-03 20:23

Although i am not php guy and i haven not used prestashop ever, but may be you forgot provide access in your crodova application this might be the issue please add

<access origin="*"/>

this to your config.xml file hopefully it will work thanks, please do not forgot mark as an answer if it helps you..

查看更多
Viruses.
3楼-- · 2019-02-03 20:35

Finally, I figured out how to send the ws_key:

$http({
        method: 'get',
        url: ws_url + 'customers/?schema=blank',
        params: {
            ws_key: ws_key
        });

You have to pass the ws_key param with your key to access the PrestaShop webservice.

查看更多
登录 后发表回答