2

Here is my code for my PHP application to access the CI Rest Library by Phil sturgeon. When I disable the api key it seems fine. This is the json result as follows:

[{"groupID":"1","listID":"1","groupTitle":"GroupA","groupName":"Group Name 1"}]

And when I try enabling the api key in rest library. I receive this

{"status":false,"error":"Unknown method."}

Trying also on my terminal:

I got this

CURL

[2012-07-03 14:11.42]  ~
[User4001.me] → curl -X POST -H "X-API-KEY: 221b368d7f5f597867f525971f28ff75" http://localhost/mailapi/index.php/api/group/id/1
{"status":false,"error":"Unknown method."}   

ON PHP
test.php

$ch = curl_init();
curl_setopt_array($ch, array(
    CURLOPT_RETURNTRANSFER => true,
    CURLOPT_URL => 'http://localhost/mailapi/index.php/api/group/id/1',
    CURLOPT_POSTFIELDS => 'X-API-KEY=221b368d7f5f597867f525971f28ff75'
));
$response = curl_exec($ch);

echo"<pre>";
print_r($response);
echo"</pre>";

Am I missing something?

program taylor
  • 119
  • 1
  • 2
  • 8
  • Maybe it wants it as a GET parameter? Not entirely sure, but you should try it nevertheless. so like `localhost/X-API-KEY/` – Steven Lu Jul 03 '12 at 14:08
  • Sanity check: Did you add the `rest_keys_table` to your db with the `221b368d7f5f597867f525971f28ff75` key? Also do you have `rest_auth` enabled too? – sekati Jul 05 '12 at 04:09
  • See my response here: [a link]http://stackoverflow.com/questions/19517714/philsturgeons-rest-api-codeigniter-always-returning-status0-errorunknown-me/21401025#21401025 – onalbi Jan 28 '14 at 09:05

1 Answers1

2

Phils library by default looks for X-API-KEY as a header, not a post. The documentation clearly states you need to change the config file to accept post vars.

NDBoost
  • 10,184
  • 6
  • 53
  • 73