Notification texts go here Contact Us Buy Now!

Invalid Api key using RestServer

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:

  1. Step 1: Correct URL Format
  2. 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
  3. Step 2: Create a Valid API Key
  4. Create an API key using sha1 (max 40 characters) in the keys table. Follow these steps:

    1. Set is_private_key to 1.
    2. Set ip_address to ::1.
    3. Create the record and check it again.

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:

API Key in PUT Header Variables

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';

Override Authentication Method

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.

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.