mwandulu Posted May 25, 2016 Share Posted May 25, 2016 (edited) Hello all, I am new in the PrestaShop Devs Forum, and i have been here for like 3-4 days. I have a small problem trying to acc PrestaShop web service and I am unable to do so. I keep on getting the error: "NetworkError: 401 Unauthorized - https://maglet.pswebshop.com/api/?customer_messages/1" I am trying to call the rest service api using JavaScript JQuery. $ .ajax({ url : 'https://maglet.pswebshop.com/api/&ws_key=DRYZ21C3HNZJA1264GQER3DZU2ZAVV3L9/products?schema=blank', type : 'GET', async : false, data : '{}', success : function(response) { alert("Status " + response.status + " msg status" + response.statusText); }, error : function(response) { alert("Status " + response.status + " msg status" + response.statusText); } }); Now, i have never worked on JavaScript and JQuery before, but is there anything i am doing wrong over here? If yes, what is it? I have tried looking for "How to call web service using JS in PrestShop" and I have not found suitable answers. Please advice, the closest i came across where:in stackoverflow using AngularJS in prestashop which had correct? way of calling web service pragramatically, but was not what i was seeking. I have several ways such as below without success. username : 'DRYZ21C3HNZJA1264GQER3DZU2ZAVV3L9', or headers : { 'Authorization' : "Basic DRYZ21C3HNZJA1264GQER3DZU2ZAVV3L9" }, or headers : { 'Authorization' : "Basic"+btoa('DRYZ21C3HNZJA1264GQER3DZU2ZAVV3L9') }, I have tried doing things but i keep on getting the same error. "NetworkError: 401 Unauthorized - Or I get the error: NS_ERROR_IN_PROGRESS: Component returned failure code: 0x804b000f (NS_ERROR_IN_PROGRESS) [nsICacheEntry.dataSize] When i use Chrome PostMan, everything works fine and I just need to set Authentication to Basic, then provide key onto Username as described over here in Presto Devs Doc. The result calls I get from Postman are like below: * * * * *Access-Time →1464177748Connection →Keep-AliveContent-Encoding →gzipContent-Sha1 →87c9219k2f0ef6d3445fq65c963978ccf261e64aContent-Type →text/xml;charset=utf-8Date →Wed, 25 May 2016 12:02:28 GMTExecution-Time →0.016Keep-Alive →timeout=5, max=100PSWS-Version →1.6.1.3Server →ApacheTransfer-Encoding →chunkedVary →Authorization,Accept-EncodingX-Powered-By →PrestaShop Webservice * * * * * Please advice how to access PrestoShop web service using JavaScript ( preferably JQuery since I trying to develop a mobile app which will consume service in Cordova) Is there anything I am missing?? I appreciate your assistance in advance. Regards, Noel Edited May 25, 2016 by mwandulu (see edit history) Link to comment Share on other sites More sharing options...
derenyi Posted May 31, 2016 Share Posted May 31, 2016 Hi, a know nothing about JavaScript, but regarding the url, instead of this: https://maglet.pswebshop.com/api/&ws_key=DRYZ21C3HNZJA1264GQER3DZU2ZAVV3L9/products?schema=blank use this: (http, not https) http://maglet.pswebshop.com/api/products?schema=blank&ws_key=DRYZ21C3HNZJA1264GQER3DZU2ZAVV3L9 Also, if you use multishop, several times it is necessary to narrow it to a certain shop: http://maglet.pswebshop.com/api/products?id_shop=1&schema=blank&ws_key=DRYZ21C3HNZJA1264GQER3DZU2ZAVV3L9 All shops: http://maglet.pswebshop.com/api/products?id_group_shop=0&schema=blank&ws_key=DRYZ21C3HNZJA1264GQER3DZU2ZAVV3L9 bye, Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now