Jump to content

REST API URL translation problem


Recommended Posts

Hello,

I need to use REST webservices to handle my eshop. I followed the tutorial "Using the REST webservice" and found a problem.

My URL translation is not working properly.

I've generated new .htaccess file, having inside

<IfModule mod_rewrite.c>
# URL rewriting module activation
RewriteEngine on
# URL rewriting rules
RewriteRule ^api/?(.*)$ /prestashop/webservice/dispatcher.php?url=$1 [QSA,L]
</IfModule>

 

Rewriting in prestashop is enabled via Back Office accordingly, I generated the key and set all needed permissions.

Rewriting in Apache is enabled too, module is loaded.

Apache is version 2.2, hosted on localhost.

 

If I access http://localhost/pre.../dispatcher.php it works, i get a tree of xlinks. But according translated URL http://localhost/prestashop/api results in error 404. Same error is returned while trying to access http://localhost/pre...p/api/customers etc..

 

Problem is, that I want to use created PHP scripts (0-CustomersList.php, 1-Retrieve.php) and in all those script, URL translation is used.

Snippet of 0-CustomersList.php:

// Here we define constants /!\ You need to replace this parameters
define('DEBUG', true);		   // Debug mode
define('PS_SHOP_PATH', 'http://localhost/');  // Root path of your PrestaShop store
define('PS_WS_AUTH_KEY', 'ZQ88PRJX5VWQHCWE4EE7SQ7HPNX00RAJ'); // Auth key (Get it in your Back Office)
require_once('./PSWebServiceLibrary.php');

 

Any ideas?

Link to comment
Share on other sites

Just as an example of nonworking address resolution, I uploaded correct CustomersList.php to the server and executed it, here is a reply.

 

URL is http://localhost/prestashop/webservice/CustomersList.php


HTTP REQUEST HEADER
GET //api/customers HTTP/1.1
Authorization: Basic V0FESDZTQkFZNkZUOTdDWU9BRElVVFlNWlJSSFlPMlk6
Host: localhost
Accept: */*


HTTP RESPONSE HEADER
HTTP/1.1 404 Not Found
Date: Thu, 03 May 2012 11:47:18 GMT
Server: Apache/2.2.22 (Fedora)
Content-Length: 286
Connection: close
Content-Type: text/html; charset=iso-8859-1

RETURN HTTP BODY
<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML 2.0//EN">
<html><head>
<title>404 Not Found</title>
</head><body>
<h1>Not Found</h1>
<p>The requested URL /api/customers was not found on this server.</p>
<hr>
<address>Apache/2.2.22 (Fedora) Server at localhost Port 80</address>
</body></html>


Bad ID

Customer's List

Link to comment
Share on other sites

  • 2 weeks later...
  • 3 years later...
  • 9 months later...

Hello,

I have made a new bit step, now I have the .htaccesss and if I test on my ubuntu 16 server it told me that the rewrite module is active, but keeps giving me error.

 

this is my .htaccess, have you any suggest to give me?

 

thanks in advance

Order deny,allow
Deny from all

RewriteEngine on

# ~~start~~ Do not remove this comment, Prestashop will keep automatically the code outside this comment when .htaccess will be generated again
# .htaccess automaticaly generated by PrestaShop e-commerce open-source solution
# http://www.prestashop.com - http://www.prestashop.com/forums

<IfModule mod_rewrite.c>
<IfModule mod_env.c>
SetEnv HTTP_MOD_REWRITE On
</IfModule>

RewriteEngine on


#Domain: www.cimminob2b.com
RewriteRule . - [E=REWRITEBASE:/]
RewriteRule ^api$ api/ [L]

RewriteRule ^api/(.*)$ %{ENV:REWRITEBASE}webservice/dispatcher.php?url=$1 [QSA,L]

# AlphaImageLoader for IE and fancybox
RewriteRule ^images_ie/?([^/]+)\.(jpe?g|png|gif)$ js/jquery/plugins/fancybox/images/$1.$2 [L]
</IfModule>

AddType application/vnd.ms-fontobject .eot
AddType font/ttf .ttf
AddType font/otf .otf
AddType application/x-font-woff .woff
<IfModule mod_headers.c>
    <FilesMatch "\.(ttf|ttc|otf|eot|woff|svg)$">
        Header add Access-Control-Allow-Origin "*"
    </FilesMatch>
</IfModule>

#If rewrite mod isn't enabled
ErrorDocument 404 /index.php?controller=404

# ~~end~~ Do not remove this comment, Prestashop will keep automatically the code outside this comment when .htaccess will be generated again
 

Link to comment
Share on other sites

if I try to access directly at http://www.cimminob2b.com/webservice/dispatcher.php?url=customers

 

this is the result

 

<prestashop><customers><customer id="1" xlink:href="http://www.cimminob2b.com/api/customers/1"/></customers></prestashop>

 

but If I try to access by http://www.cimminob2b.com/api

 

the result is ( I have tested that ini php.ini there was mod_rewrite and also I checked that on my ubuntu 16 that the rewrite module is active ) :

 

Any suggest?

Not Found

The requested URL /api was not found on this server.

Apache/2.4.18 (Ubuntu) Server at www.cimminob2b.com Port 80
Link to comment
Share on other sites

  • 3 months later...
×
×
  • Create New...