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?

3
  • Maybe it wants it as a GET parameter? Not entirely sure, but you should try it nevertheless. so like localhost/X-API-KEY/<api_key> Commented Jul 3, 2012 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? Commented Jul 5, 2012 at 4:09
  • See my response here: [a link]stackoverflow.com/questions/19517714/… Commented Jan 28, 2014 at 9:05

1 Answer 1

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.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.