Skip to content
Advertisement

CodeIgniter Rest_Controller: Invalid API Key

I’m learning to use codeigniter and in general to create the API.

I have installed REST_Controller in my project, I have created in my db the table ‘logs’ and ‘keys’ using the query that I found in the Rest.php file.

Now If I do a get, the method works. But if I tried to do a post (from Postman) I receive this error:

"status": false,
"error": "Invalid API Key "

I have done a post to link: localhost/…./controllername/create (so without using create_post) and I pass values using body/form-data in Postman.

If I see the data inside the ‘logs’ table, i can see the post with the values that I have passed, but I have no values about the api_key parameter, while the ‘keys’ table is completely empty.

How can I do to resolve this error?

Advertisement

Answer

Go to config/rest.php and set the API KEY name you wil send, default is:

$config['rest_key_name'] = 'X-API-KEY';

You can change for any other like: token, authtoken, etc. If you are using tools like Postman try send in the headers: name: X-API-KEY value: your_token_value

User contributions licensed under: CC BY-SA
1 People found this is helpful
Advertisement