Notification texts go here Contact Us Buy Now!

Invalid Api key using RestServer

Invalid API Key: Troubleshooting with RestServer

Invalid API Key: Troubleshooting with RestServer

Encountering an "Invalid API Key" error while using RestServer in CodeIgniter? Here are comprehensive solutions to address this issue:

1. Correct URL Format

Ensure you are using the proper URL format for your API requests. RestServer automatically detects the request's nature based on the parameters passed. However, you must make the following change:

Incorrect URL:

http://localhost/projects/myapi/key/index_put.php

Corrected URL:

http://localhost/projects/myapi/key/index.php

2. API Key Creation and Configuration

  1. Create an API key using sha1 (max 40 characters) in the keys table (table structure is defined in config/rest.php).
  2. Set is_private_key to 1 and ip_address to ::1.
  3. Save the record and check again.

Additional Solutions:

Using x-www-form-urlencoded Header

When using the PUT method, the API key should be in the PUT header variables as x-www-form-urlencoded type. Use a tool like Google Chrome Postman to fill in the necessary details.

Adding 'auth_override_class_method' Configuration

  1. Open application/config/rest.php.
  2. Locate the auth_override_class_method section.
  3. Add the following line:
  4. $config['auth_override_class_method']['key']['*'] = 'basic';
    

Make sure to modify the configuration based on your specific API requirements.

Conclusion

These solutions should help you resolve the "Invalid API Key" error when using RestServer in CodeIgniter. If the issue persists, consider checking your API key permissions and ensuring that your API requests are properly formatted and authenticated.

Post a Comment

Cookie Consent
We serve cookies on this site to analyze traffic, remember your preferences, and optimize your experience.
Oops!
It seems there is something wrong with your internet connection. Please connect to the internet and start browsing again.
AdBlock Detected!
We have detected that you are using adblocking plugin in your browser.
The revenue we earn by the advertisements is used to manage this website, we request you to whitelist our website in your adblocking plugin.
Site is Blocked
Sorry! This site is not available in your country.