3

Just want to mention that I am really a newbie in API development (concepts, structure, best practices) I am not nearly familiar with it at all, so please excuse my pathetic stupid question if you find it to be, I'm using Phil Sturgeon's REST API server, Curl Library, and REST API client here's my code:

in my controller application/controllers/make_key

function index(){
      $this->load->library('rest');
      $this->load->library('curl');
      $this->rest->put('https://www.myapplication.com/apifolder/key/X-API-KEY/FOO');
    }

- no response at all

where apifolder/key is the location of my key.php (from Phil Sturgeon's default example):

and note that I've also tried this via address bar:

https://www.myapplication.com/apifolder/key/X-API-KEY/FOO - returns ({"status":false,"error":"Invalid API Key."})

https://www.myapplication.com/apifolder/key?X-API-KEY=FOO - returns ({"status":false,"error":"Unknown method."})

and tried quite a lot more queries but none seem to be working, my only question is...

How can make this key.php work? my apologies for such a simple minded question thank you in advance

Jerric Calosor
  • 95
  • 1
  • 1
  • 11
  • 1
    Supply a valid API key and use a valid method in your api call. This should be documented somewhere closeby where you got the libraries. – Robin Castlin Jul 24 '12 at 08:44
  • this isnt a simple minded question, several people have had this and honestly Phil probably needs to update his documentation a bit.. i provided an answer. – NDBoost Jul 24 '12 at 13:16
  • Thanks Robin yes FOO is a valid key placed within my key_table and tested against a get() method and seems to be working fine, except when I'm trying to do a post method it just returns an error, – Jerric Calosor Jul 24 '12 at 14:03

1 Answers1

4

see my self-accepted answer on my own qeuestion... Phils documentation does not provide this information. I had to dig into the library myself.

i ended up finding out the 403 forbidden was because i was not providing an api key to generate keys..
Kind of abiguous as Phil's documentation doesn't state that an existing api key is required before you can generate keys.. I simply created a bogus key in the table in the db and referenced that when calling /key/index?X-API-KEY=boguskey

CodeIgniter REST API Library Ajax PUT throwing 403 Forbidden

Community
  • 1
  • 1
NDBoost
  • 10,184
  • 6
  • 53
  • 73
  • updated: thank you Gorelative, I'm already using a bogus key I created to my key_table and had been using it with get method, the problem is when I'm trying to do a PUT/POST method it's always returning a ({"status":false,"error":"Invalid API Key."}) as a response, do you have an idea how can I do a post or put method to generate a key via CURL (Codeigniter Curl Library)? just like what you did using via $ajax, thanks a bunch – Jerric Calosor Jul 24 '12 at 14:10
  • 1
    you would need to pass the key as a http header. or a post var. Either that or pass the api key in the URL.. like i mentioned above using `?X-API-KEY=` – NDBoost Jul 24 '12 at 14:14
  • @gorelative in the api_keys database there is few field which im not sure what is the purpose. user_id, level, ignore_limits, is_private_key, ip_addresses. do you when i can uses these field ? – Bravo Net Mar 20 '16 at 09:48