Invalid API Key using RESTServer
If you're encountering an "Invalid API key" error while using RESTServer, here's a comprehensive solution with step-by-step instructions:
- Step 1: Correct URL Format
- Step 2: Create a Valid API Key
- Set
is_private_key
to 1. - Set
ip_address
to::1
. - Create the record and check it again.
Ensure that your URL follows the correct format. Instead of:
http://localhost/projects/myapi/key/index_put.php
Use this:
http://localhost/projects/myapi/key/index.php
Create an API key using sha1
(max 40 characters) in the keys table. Follow these steps:
Alternative Solution: API Key in PUT Header Variables
For the CodeIgniter RESTServer library, when using the PUT method, the API key should be included in the PUT header variables as an x-www-form-urlencoded type. Use Google Chrome Postman and fill in the fields as shown in the image below:
Additional Solution: Override Authentication Method
You can also override the authentication method in the application/config/rest.php
file. Locate the auth_override_class_method
section and add the following line:
$config['auth_override_class_method']['key']['*'] = 'basic';
Conclusion
By following the steps outlined above, you should be able to resolve the "Invalid API key" error and successfully use RESTServer with a valid API key.