{"id":797,"date":"2022-08-30T15:07:20","date_gmt":"2022-08-30T15:07:20","guid":{"rendered":"https:\/\/unknownerror.org\/index.php\/2013\/11\/09\/how-can-i-generate-an-api-key-in-my-own-controller-in-codeigniter-collection-of-common-programming-errors\/"},"modified":"2022-08-30T15:07:20","modified_gmt":"2022-08-30T15:07:20","slug":"how-can-i-generate-an-api-key-in-my-own-controller-in-codeigniter-collection-of-common-programming-errors","status":"publish","type":"post","link":"https:\/\/unknownerror.org\/index.php\/2022\/08\/30\/how-can-i-generate-an-api-key-in-my-own-controller-in-codeigniter-collection-of-common-programming-errors\/","title":{"rendered":"How can I generate an API Key in My own Controller in Codeigniter-Collection of common programming errors"},"content":{"rendered":"<p>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&#8217;m using Phil Sturgeon&#8217;s REST API server, Curl Library, and REST API client here&#8217;s my code:<\/p>\n<p>in my controller application\/controllers\/make_key<\/p>\n<pre><code>function index(){\n      $this-&gt;load-&gt;library('rest');\n      $this-&gt;load-&gt;library('curl');\n      $this-&gt;rest-&gt;put('https:\/\/www.myapplication.com\/apifolder\/key\/X-API-KEY\/FOO');\n    }\n<\/code><\/pre>\n<p>&#8211; no response at all<\/p>\n<p>where apifolder\/key is the location of my key.php (from Phil Sturgeon&#8217;s default example):<\/p>\n<p>and note that I&#8217;ve also tried this via address bar:<\/p>\n<p>https:\/\/www.myapplication.com\/apifolder\/key\/X-API-KEY\/FOO &#8211; returns ({&#8220;status&#8221;:false,&#8221;error&#8221;:&#8221;Invalid API Key.&#8221;})<\/p>\n<p>https:\/\/www.myapplication.com\/apifolder\/key?X-API-KEY=FOO &#8211; returns ({&#8220;status&#8221;:false,&#8221;error&#8221;:&#8221;Unknown method.&#8221;})<\/p>\n<p>and tried quite a lot more queries but none seem to be working, my only question is&#8230;<\/p>\n<p>How can make this key.php work? my apologies for such a simple minded question thank you in advance<\/p>\n<ol>\n<li>\n<p>see my self-accepted answer on my own qeuestion&#8230; Phils documentation does not provide this information. I had to dig into the library myself.<\/p>\n<blockquote>\n<p>i ended up finding out the 403 forbidden was because i was not providing an api key to generate keys..<br \/>\nKind of abiguous as Phil&#8217;s documentation doesn&#8217;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 <code>\/key\/index?X-API-KEY=boguskey<\/code><\/p>\n<\/blockquote>\n<p>CodeIgniter REST API Library Ajax PUT throwing 403 Forbidden<\/p>\n<\/li>\n<\/ol>\n<p id=\"rop\"><small>Originally posted 2013-11-09 22:46:02. <\/small><\/p>","protected":false},"excerpt":{"rendered":"<p>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&#8217;m using Phil Sturgeon&#8217;s REST API server, Curl Library, and REST API client here&#8217;s my code: [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-797","post","type-post","status-publish","format-standard","hentry","category-uncategorized"],"_links":{"self":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts\/797","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/comments?post=797"}],"version-history":[{"count":0,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts\/797\/revisions"}],"wp:attachment":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/media?parent=797"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/categories?post=797"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/tags?post=797"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}