codeigniter-restserver icon indicating copy to clipboard operation
codeigniter-restserver copied to clipboard

How to accept JSON data?

Open harrykrupp opened this issue 10 years ago • 4 comments

I have a unique key that I send as MY-APPS-KEY=XXXXXXXXX (the database is already setup as suggested in documentation).

It doesn’t seem to accept JSON data as request (otherwise works perfectly – if we send data as key=value pairs).

It gives this error with JSON request: {"status":false,"error":"Invalid API key "}

Am I missing something?

harrykrupp avatar Feb 15 '16 14:02 harrykrupp

The key can be found in rest.php file inside the config folder and look for the $config['rest_key_name']. You can also disable the keys if you want to.

claide avatar Feb 19 '16 01:02 claide

@claide Thanks for the reply. I enabled keys and I want them in my code. My question is, how do I enable system to accept data in JSON format.

If I send key as MY-APPS-KEY=XXXXXXX&country=India it works. But, if I send it in JSON format as {MY-APPS-KEY:XXXXXXX,country:India} it doesn't work (I tried all variations - JSON data with double quotes, envelope brackets, etc - nothing works).

harrykrupp avatar Feb 19 '16 06:02 harrykrupp

You should send your API-Key in the Header of the request, not in the body.

curl -X POST -H "X-API-KEY: some_key_here" http://example.com/books

fabianblum avatar Feb 24 '16 16:02 fabianblum

@Hanisch-IT thanks a lot! :+1:

This works for me to some extent, it doesn't give me invalid api key error anymore - all I need to do is make the JSON data work.

harrykrupp avatar Feb 25 '16 07:02 harrykrupp