REST API error via AJAX request
Posted: Wed Oct 16, 2019 12:07 pm
I have discovered a potential bug in the REST API.
When performing an AJAX request to any of the API GET endpoints from a separate website, a 403 Invalid Method response is returned.
It looks like the browser is making an OPTIONS request to the endpoint before making its GET request.
Looking through the source code for the API, it handles POST, GET, PUT, and DELETE requests, but not OPTIONS requests.
Since there is no way to handle the OPTIONS request, it defaults to a 403 error and prevents the GET request from executing.
I was able to resolve this issue by manually adding the following case to the switch statement in the __construct function for the utils.inc.php file for the API:
When performing an AJAX request to any of the API GET endpoints from a separate website, a 403 Invalid Method response is returned.
It looks like the browser is making an OPTIONS request to the endpoint before making its GET request.
Looking through the source code for the API, it handles POST, GET, PUT, and DELETE requests, but not OPTIONS requests.
Since there is no way to handle the OPTIONS request, it defaults to a 403 error and prevents the GET request from executing.
I was able to resolve this issue by manually adding the following case to the switch statement in the __construct function for the utils.inc.php file for the API:
Code: Select all
case 'OPTIONS':
$this->_response('Ok', 200);
break;