cancel
Showing results for 
Search instead for 
Did you mean: 

REST API issue : can not read api data in IIS 7.5, who could tell me how to set REWRITE in IIS?

REST API issue : can not read api data in IIS 7.5, who could tell me how to set REWRITE in IIS?

Hi there

 

I am trying to read Magent's data with rest api in Magento 1.9.2.1 on windows server & IIS 7.5. But I cannot get correct data and always get error msg "Invalid auth/bad request (got a 404, expected HTTP/1.1 20X or a redirect)". These are some details I did in my program:

 

1. I have succeeded in installing Magento and Oauth lib in PHP 5.6.9 

2. My address is a general web address "http://test.magento/magento-1.9.2.1" using port 80.

3. I created related role, user and tested successful authenticated connection to use the API. 

4. Following by the PHP examples on the magento official website "http://www.magentocommerce.com/api/rest/introduction.html" I wrote a test script for testing and it will occur the request "authorize application" in the first time.

 

The problem is that after I clicked on "Authorize" it will encounter the error message: "nvalid auth/bad request (got a 404, expected HTTP/1.1 20X or a redirect)"

 

I checked the script "\api.php" and assume the issue is caused by missing some correct REWRITE configuration in IIS7. Because I found that "api.php"cannot parse the url correctly.

 

I googled "magento REWRITE in IIS" but all documents is to Magento not for Magento Rest API. There are some REWRITE rules for apache and nginx but it's not suitable for IIS.Does anybody have rewrite configuration in IIS to let me study how to set ? Thank you very much.

1 REPLY

Re: REST API issue : can not read api data in IIS 7.5, who could tell me how to set REWRITE in IIS?

Hi there,

 

I have fixed it in IIS environment, add codes as below in the Web.config, please notice inserting <rule api.php> into the front of <rule index.php">

 

<?xml version="1.0" encoding="UTF-8"?> 
<configuration>
<system.webServer>
<rewrite>
<rules>
<rule name="Rewrite to api.php">
<match url="^api/rest(.+)" />
<action type="Rewrite" url="api.php?type=rest" />
</rule>
<rule name="Remove index.php rule" stopProcessing="true">
<match url=".*" ignoreCase="false"/>
<conditions>
<add input="{URL}" pattern="^/(media|skin|js)/" ignoreCase="false" negate="true" />
<add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" />
<add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" />
</conditions>
<action type="Rewrite" url="index.php" />
</rule>
</rules>
</rewrite>
</system.webServer>
<location allowOverride="true"/>
</configuration>
</configuration>