How to accept JSON data?
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?
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 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).
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
@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.