REST API on IIS 2019 – 405 method not allowed

Software Development and IT Support in Tameside

REST API on IIS 2019 – 405 method not allowed

Like many – we’ve had issues with a REST API running on IIS – this was a WordPress site.

We’re doing some development work for a customer who wants to add a shop to his WordPress site. This development included a product and price data feed from a 3rd Party.

We put together a test site – basic WordPress, basic WooCommerce on a clean Linux build on our internal development network to prepare a proof of concept environment – which worked really well.

Later in the development process we needed to demo this to the client, but needed their WordPress site framework around what we’d done. As we are a Microsoft Windows shop, our internet facing servers are Windows 2019 with IIS. We run WordPress sites on this server already – so know it works, but none of them use a REST API for anything.

So, we grab an image of their existing WordPress site, give it a few tweaks to not interfere with the existing site, and add a GoGetSSL 3-month SSL Certificate (REST API needs to run over SSL).

A couple of DNS entries later and we are able to load products, categories, images etc., via the REST API into the copy of their site. This process uses the API GET and POST commands.

We also needed to modify some products once they were uploaded, to add some Advanced Custom Fields data – some extended product data that is not part of the default WooCommerce product info.

This is where we hit our snag – although this method is tested and still works with our proof of concept, it didn’t work with the demo site.

The only difference (that I could see) was this is IIS on Windows, not Apache2 or Linux. So a trawl of the web for 405 – method not allowed on IIS showed loads of posts saying delete the references/disable WEBDAV.

The catch is, WEBDAV is not installed on this server, so all these “solutions” which say the cause is WEBDAV made no difference.

After some head scratching we looked at the IIS Handler Mappings for this site – specifically for PHP.

WordPress is exclusively PHP-based, this won’t work if your REST API is written in ASP.NET.

We added Handler Mappings for PHP to handle the Verbs “PUT” and “DELETE” which were not present.

Restart the site, and hey presto, the API now works the same as the Proof of Concept site!