{"id":79,"date":"2015-08-07T10:05:57","date_gmt":"2015-08-07T10:05:57","guid":{"rendered":"http:\/\/is.ieis.tue.nl\/research\/hc\/gamebus\/?page_id=79"},"modified":"2015-08-07T10:05:57","modified_gmt":"2015-08-07T10:05:57","slug":"api","status":"publish","type":"page","link":"https:\/\/blog.gamebus.eu\/index.php\/sample-page\/api\/","title":{"rendered":"GameBus API"},"content":{"rendered":"<h2>API Endpoint<\/h2>\n<p>http:islab1.ieis.tue.nl:8024\/api<\/p>\n<p>&nbsp;<\/p>\n<h2>Authentication<\/h2>\n<p>An access token is necessary to be used in each request.<\/p>\n<p>&nbsp;<\/p>\n<h2>Summary of resources<\/h2>\n<p>\/user<\/p>\n<p>\/player<\/p>\n<p>\/challenge<\/p>\n<p>\/gameDescriptor<\/p>\n<p>\/property<\/p>\n<p>\/propertyType<\/p>\n<p>\/propertyInstance<\/p>\n<p>\/gameSession<\/p>\n<p>\/tag<\/p>\n<p>\/dataProvider<\/p>\n<p>\/tokenForDataProvider<\/p>\n<p>\/rointMapping<\/p>\n<p>\/role<\/p>\n<p>\/support<\/p>\n<p>\/circle<\/p>\n<p>\/personalPoint<\/p>\n<p>\/participation<\/p>\n<p>\/reward<\/p>\n<p>\/sponsor<\/p>\n<p>\/rightToShowChallenge<\/p>\n<p>\/challengeRule<\/p>\n<p>\/condition<\/p>\n<p>\/operator<\/p>\n<p>To perform an operation on any of the above listed resources, you just need to append the resource as it is, with the API endpoint. Of course it varies from request to request, so for example in case of GET and DELETE you just append the resource to the endpoint but for POST or PUT you need to specify the parameters and their values accordingly. For details, see the relevant sections for those methods.<\/p>\n<h2><\/h2>\n<h2>Request pattern<\/h2>\n<p>curl -X $Method -H &#8220;Authorization: Bearer $token&#8221; <a href=\"http:\/\/islab1.ieis.tue.nl:8024\/api\/player\">http:\/\/islab1.ieis.tue.nl:8024\/api\/player<\/a><\/p>\n<p>In this request, the variable with $ sign needs to be replaced by its values. For example, in the example request below we have replaced $Method with GET and $token with the value of the access token.<\/p>\n<h2>Example request<\/h2>\n<p>curl -X GET -H &#8220;Authorization: Bearer 797d8861-1436-4bd5-97c2-2e7bd9884749&#8221; <a href=\"http:\/\/islab1.ieis.tue.nl:8024\/api\/player\">http:\/\/islab1.ieis.tue.nl:8024\/api\/player<\/a><\/p>\n<p>&nbsp;<\/p>\n<p>Sample response for the same request above, but when executed from a REST client.<\/p>\n<p>&nbsp;<\/p>\n<h2>Get a Token via Login service<\/h2>\n<p>&nbsp;<\/p>\n<p>Get the OAUTH token<\/p>\n<p>curl -X POST -H &#8220;Content-Type: application\/x-www-form-urlencoded&#8221; -d &#8220;grant_type=password&#8221; -d &#8220;username=testuser@example.com&#8221; -d &#8220;password=testpass&#8221; http:\/\/$gamebus:secret@localhost:8989\/oauth\/token | <span style=\"text-decoration: underline;\">jq<\/span> -r &#8216;.access_token&#8217;<\/p>\n<p>connection refused<\/p>\n<p>&nbsp;<\/p>\n<p>curl -X GET -H &#8220;Content-Type: application\/x-www-form-urlencoded&#8221; -d &#8220;grant_type=password&#8221; -d &#8220;username=testuser@example.com&#8221; -d &#8220;password=testpass&#8221; http:\/\/gamebus:secret@localhost:8989\/oauth\/token | <span style=\"text-decoration: underline;\">jq<\/span> -r &#8216;.access_token&#8217;<\/p>\n<p>connection refused<\/p>\n<p>&nbsp;<\/p>\n<p>Get token (out of script) returns null<\/p>\n<p>curl -X POST -H &#8220;Content-Type: application\/x-www-form-<span style=\"text-decoration: underline;\">urlencoded<\/span>&#8221; -d &#8220;grant_type=password&#8221; -d &#8220;username=testuser@example.com&#8221; -d &#8220;password=testpass&#8221; http:\/\/gamebus:@localhost:8989\/oauth\/token | <span style=\"text-decoration: underline;\">jq<\/span> -r &#8216;.access_token&#8217;<\/p>\n<p>Failed to connect to localhost port 8989: connection refused<\/p>\n<p>&nbsp;<\/p>\n<p>curl -X GET -H &#8220;Content-Type: application\/x-<span style=\"text-decoration: underline;\">www<\/span>-form-<span style=\"text-decoration: underline;\">urlencoded<\/span>&#8221; -d &#8220;grant_type=password&#8221; -d &#8220;username=testuser@example.com&#8221; -d &#8220;password=testpass&#8221; http:\/\/gamebus:@localhost:8989\/oauth\/token | <span style=\"text-decoration: underline;\">jq<\/span> -r &#8216;.access_token&#8217;<\/p>\n<p>Failed to connect to localhost port 8989: connection refused<\/p>\n<p>curl curl:testpass@localhost:8989\/oauth\/token\\?grant_type=client_credentials<\/p>\n<p>&nbsp;<\/p>\n<p>curl curl:testpass@localhost:8989\/oauth\/token\\?grant_type=password<\/p>\n<p>&nbsp;<\/p>\n<h2>Insert a GameDescriptor<\/h2>\n<p>curl -H &#8220;Authorization: Bearer 108cf321-06c1-4d30-bb2c-d7904b87cc6e&#8221; -X POST -H &#8220;Content-Type: application\/json&#8221; -d &#8220;{\\&#8221;name\\&#8221;: \\&#8221;Memory\\&#8221;, \\&#8221;tag\\&#8221;: \\&#8221;cognitive\\&#8221;}&#8221; <a href=\"http:\/\/localhost:8989\/api\/gameDescriptor\">http:\/\/localhost:8989\/api\/gameDescriptor<\/a><\/p>\n<p>#Retrieve all the gameDescriptors<\/p>\n<p>curl -X GET -H &#8220;Authorization: Bearer 108cf321-06c1-4d30-bb2c-d7904b87cc6e&#8221; <a href=\"http:\/\/localhost:8989\/api\/gameDescriptor\">http:\/\/localhost:8989\/api\/gameDescriptor<\/a><\/p>\n<p>#Based on Id of a (chosen) gameDescriptor, post a new GameSession<\/p>\n<p>curl -H &#8220;Authorization: Bearer 108cf321-06c1-4d30-bb2c-d7904b87cc6e&#8221; -X POST -H &#8220;Content-Type: application\/json&#8221; -d &#8220;{\\&#8221;createdAt\\&#8221;: \\&#8221;07-07-2015\\&#8221;, \\&#8221;isManual\\&#8221;: \\&#8221;true\\&#8221;}&#8221; <a href=\"http:\/\/localhost:8989\/api\/gameDescriptor\/1\/gameSession\">http:\/\/localhost:8989\/api\/gameDescriptor\/1\/gameSession<\/a><\/p>\n<h1>Retrieving resources:<\/h1>\n<p>curl -X GET -H &#8220;Authorization: Bearer 108cf321-06c1-4d30-bb2c-d7904b87cc6e&#8221; <a href=\"http:\/\/localhost:8989\/api\/player\">http:\/\/localhost:8989\/api\/player<\/a><\/p>\n<p>curl -X GET -H &#8220;Authorization: Bearer 108cf321-06c1-4d30-bb2c-d7904b87cc6e&#8221; <a href=\"http:\/\/localhost:8989\/api\/user\">http:\/\/localhost:8989\/api\/user<\/a><\/p>\n<p>curl -X GET -H &#8220;Authorization: Bearer 108cf321-06c1-4d30-bb2c-d7904b87cc6e&#8221; <a href=\"http:\/\/localhost:8989\/api\/gameDescriptor\">http:\/\/localhost:8989\/api\/gameDescriptor<\/a><\/p>\n<p>&nbsp;<\/p>\n<p>#Get a specific player with id (or entity likewise)<\/p>\n<p>curl -X GET -H &#8220;Authorization: Bearer 108cf321-06c1-4d30-bb2c-d7904b87cc6e&#8221; <a href=\"http:\/\/localhost:8989\/api\/player\/2\">http:\/\/localhost:8989\/api\/player\/2<\/a><\/p>\n<p>#Get circles for a player with id<\/p>\n<p>curl -X GET -H &#8220;Authorization: Bearer 108cf321-06c1-4d30-bb2c-d7904b87cc6e &#8221; <a href=\"http:\/\/localhost:8989\/api\/player\/2\/circles\">http:\/\/localhost:8989\/api\/player\/2\/circles<\/a><\/p>\n<p>curl -X GET -H &#8220;Authorization: Bearer 108cf321-06c1-4d30-bb2c-d7904b87cc6e&#8221; <a href=\"http:\/\/localhost:8989\/api\/player\/2\/supports\">http:\/\/localhost:8989\/api\/player\/2\/supports<\/a><\/p>\n<p>curl -X GET -H &#8220;Authorization: Bearer 108cf321-06c1-4d30-bb2c-d7904b87cc6e&#8221; <a href=\"http:\/\/localhost:8989\/api\/player\/2\/gameSessions\">http:\/\/localhost:8989\/api\/player\/2\/gameSessions<\/a><\/p>\n<p>&nbsp;<\/p>\n<p>curl -X GET -H &#8220;Authorization: Bearer 108cf321-06c1-4d30-bb2c-d7904b87cc6e&#8221; <a href=\"http:\/\/localhost:8989\/api\/player\/2\/tokensForDataProvider\">http:\/\/localhost:8989\/api\/player\/2\/tokensForDataProvider<\/a><\/p>\n<p>&nbsp;<\/p>\n<h1>Creation of resources<\/h1>\n<p>Create a user<\/p>\n<p>curl -H &#8220;Authorization: Bearer 108cf321-06c1-4d30-bb2c-d7904b87cc6e&#8221; -X POST -H &#8220;Content-Type: application\/json&#8221; -d &#8220;{\\&#8221;firstName\\&#8221;: \\&#8221;Carolina\\&#8221;, \\&#8221;lastName\\&#8221;: \\&#8221;Gomez\\&#8221;, \\&#8221;email\\&#8221;: \\&#8221;c.gomez@tue.nl\\&#8221;, \\&#8221;password\\&#8221;: \\&#8221;testpassword\\&#8221;}&#8221; <a href=\"http:\/\/localhost:8989\/api\/user\">http:\/\/localhost:8989\/api\/user<\/a><\/p>\n<p>&nbsp;<\/p>\n<p>curl -H &#8220;Authorization: Bearer 108cf321-06c1-4d30-bb2c-d7904b87cc6e&#8221; -X POST -H &#8220;Content-Type: application\/json&#8221; -d &#8220;{\\&#8221;age\\&#8221;: \\&#8221;25\\&#8221;, \\&#8221;sex\\&#8221;: \\&#8221;male\\&#8221;, \\&#8221;height\\&#8221;: \\&#8221;5\\&#8221;, \\&#8221;weight\\&#8221;: \\&#8221;80\\&#8221;, \\&#8221;gameDescriptor\\&#8221;: \\&#8221;valueForGameDescriptor\\&#8221;, \\&#8221;circle\\&#8221;: <a href=\"http:\/\/localhost:8080\/circle\/1\/\">http:\/\/localhost:8080\/circle\/1\\<\/a>, \\&#8221;gameSession\\&#8221; : \\&#8221;http:\/\/localhost:8080\/gameSession\/1\\&#8221;}&#8221; <a href=\"http:\/\/localhost:8989\/player\">http:\/\/localhost:8989\/player<\/a><\/p>\n<p>&nbsp;<\/p>\n<p>POST a PropertyInstance with a reference to Property<\/p>\n<p>curl -H &#8220;Authorization: Bearer 108cf321-06c1-4d30-bb2c-d7904b87cc6e&#8221; -X POST -H &#8220;Content-Type: application\/json&#8221; -d &#8220;{\\&#8221;value\\&#8221;: \\&#8221;51\\&#8221;, \\&#8221;property\\&#8221;: \\&#8221;http:\/\/localhost:8989\/api\/property\/5\\&#8221;}&#8221; <a href=\"http:\/\/localhost:8989\/api\/propertyInstance\">http:\/\/localhost:8989\/api\/propertyInstance<\/a><\/p>\n<p>Add the value 51 for property score (which is property 5) in propertyInstance<\/p>\n<p>Check (test after the execution)<\/p>\n<p>curl -X GET -H &#8220;Authorization: Bearer 108cf321-06c1-4d30-bb2c-d7904b87cc6e&#8221; <a href=\"http:\/\/localhost:8989\/api\/property\/5\/propertyInstances\">http:\/\/localhost:8989\/api\/property\/5\/propertyInstances<\/a><\/p>\n<p>Add another value to 32, to see if it really works (regression test)<\/p>\n<p>curl -H &#8220;Authorization: Bearer 108cf321-06c1-4d30-bb2c-d7904b87cc6e&#8221; -X POST -H &#8220;Content-Type: application\/json&#8221; -d &#8220;{\\&#8221;value\\&#8221;: \\&#8221;32\\&#8221;, \\&#8221;property\\&#8221;: \\&#8221;http:\/\/localhost:8989\/api\/property\/5\\&#8221;}&#8221; <a href=\"http:\/\/localhost:8989\/api\/propertyInstance\">http:\/\/localhost:8989\/api\/propertyInstance<\/a><\/p>\n<p>curl -X GET -H &#8220;Authorization: Bearer 108cf321-06c1-4d30-bb2c-d7904b87cc6e&#8221; <a href=\"http:\/\/localhost:8989\/api\/property\/5\/propertyInstances\">http:\/\/localhost:8989\/api\/property\/5\/propertyInstances<\/a><\/p>\n<p>&nbsp;<\/p>\n<p>This time it shows both previous values, 51, 51 and newly added (32)<\/p>\n<p>We have to try update to see, if the old value gets updated or not?<\/p>\n<p>Some other checks<\/p>\n<p>curl -X GET -H &#8220;Authorization: Bearer 108cf321-06c1-4d30-bb2c-d7904b87cc6e&#8221; <a href=\"http:\/\/localhost:8989\/api\/propertyInstance\/19\/property\">http:\/\/localhost:8989\/api\/propertyInstance\/19\/property<\/a>\u00a0\u00a0 (for value 32)<\/p>\n<p>This returns \u201cScore\u201d as a property.<\/p>\n<p>&nbsp;<\/p>\n<h1>Update a value<\/h1>\n<p>curl -H &#8220;Authorization: Bearer 108cf321-06c1-4d30-bb2c-d7904b87cc6e&#8221; -X PUT -H &#8220;Content-Type: application\/json&#8221; -d &#8220;{\\&#8221;value\\&#8221;: \\&#8221;53\\&#8221;, \\&#8221;property\\&#8221;: \\&#8221;http:\/\/localhost:8989\/api\/property\/5\\&#8221;}&#8221; <a href=\"http:\/\/localhost:8989\/api\/propertyInstance\/17\">http:\/\/localhost:8989\/api\/propertyInstance\/17<\/a><\/p>\n<p>Updates PropertyInstance (17)\u2019s value from 51 to 53.<\/p>\n<p>Verify: Issue this request<\/p>\n<p>curl -X GET -H &#8220;Authorization: Bearer 108cf321-06c1-4d30-bb2c-d7904b87cc6e&#8221; <a href=\"http:\/\/localhost:8989\/api\/property\/5\/propertyInstances\">http:\/\/localhost:8989\/api\/property\/5\/propertyInstances<\/a><\/p>\n<p>It returns all 3 property Instances with values as 51, 32, and 53 which were earlier 51,32, and 51.<\/p>\n<h1>Delete a value<\/h1>\n<ol>\n<li>First I\u2019m creating a new PropertyInstance, then I\u2019ll delete it, just to keep the older ones as they are.<\/li>\n<li>curl -H &#8220;Authorization: Bearer 108cf321-06c1-4d30-bb2c-d7904b87cc6e&#8221; -X POST -H &#8220;Content-Type: application\/json&#8221; -d &#8220;{\\&#8221;value\\&#8221;: \\&#8221;49\\&#8221;, \\&#8221;property\\&#8221;: \\&#8221;http:\/\/localhost:8989\/api\/property\/5\\&#8221;}&#8221; <a href=\"http:\/\/localhost:8989\/api\/propertyInstance\">http:\/\/localhost:8989\/api\/propertyInstance<\/a><\/li>\n<\/ol>\n<p>curl -H &#8220;Authorization: Bearer 108cf321-06c1-4d30-bb2c-d7904b87cc6e&#8221; -X POST -H &#8220;Content-Type: application\/json&#8221; -d &#8220;{\\&#8221;value\\&#8221;: \\&#8221;13\\&#8221;, \\&#8221;property\\&#8221;: \\&#8221;http:\/\/localhost:8989\/api\/property\/5\\&#8221;}&#8221; <a href=\"http:\/\/localhost:8989\/api\/propertyInstance\">http:\/\/localhost:8989\/api\/propertyInstance<\/a><\/p>\n<ol>\n<li>Check if it is added<\/li>\n<\/ol>\n<p>curl -X GET -H &#8220;Authorization: Bearer 108cf321-06c1-4d30-bb2c-d7904b87cc6e&#8221; <a href=\"http:\/\/localhost:8989\/api\/property\/5\/propertyInstances\">http:\/\/localhost:8989\/api\/property\/5\/propertyInstances<\/a><\/p>\n<p>yes it got added, new reference is 20<\/p>\n<ol>\n<li>Delete it<\/li>\n<\/ol>\n<p>curl -H &#8220;Authorization: Bearer 108cf321-06c1-4d30-bb2c-d7904b87cc6e&#8221; -X DELETE -H &#8220;Content-Type: application\/json&#8221; -d &#8220;{\\&#8221;property\\&#8221;: \\&#8221;http:\/\/localhost:8989\/api\/property\/5\\&#8221;}&#8221; <a href=\"http:\/\/localhost:8989\/api\/propertyInstance\/20\">http:\/\/localhost:8989\/api\/propertyInstance\/20<\/a><\/p>\n<p>The above is correct way to delete<\/p>\n<p>curl -H &#8220;Authorization: Bearer 108cf321-06c1-4d30-bb2c-d7904b87cc6e&#8221; -X DELETE -H &#8220;Content-Type: application\/json&#8221; -d <a href=\"http:\/\/localhost:8989\/api\/propertyInstance\/21\">http:\/\/localhost:8989\/api\/propertyInstance\/21<\/a><\/p>\n<p>This results in error: curl, no url specified<\/p>\n<ol>\n<li>Check if it got deleted or not<\/li>\n<\/ol>\n<p>curl -X GET -H &#8220;Authorization: Bearer 108cf321-06c1-4d30-bb2c-d7904b87cc6e&#8221; <a href=\"http:\/\/localhost:8989\/api\/property\/5\/propertyInstances\">http:\/\/localhost:8989\/api\/property\/5\/propertyInstances<\/a><\/p>\n<p>It is deleted.<\/p>\n<p>&nbsp;<\/p>\n<h2>Updates and Changes<\/h2>\n<p>See the history for details<\/p>\n<p>&nbsp;<\/p>\n<p>History<\/p>\n<p>Friday, Aug 07, 2015. Summary of resources, an example request.<\/p>\n<p>Monday, Aug 10, 2015. Insert a GameDescriptor<\/p>\n<p>Monday, Aug 10, 2015.<\/p>\n<p>Curl requests to get token directly failing. Currently it is achieved through running a script.<\/p>\n<p>Creation of resources<\/p>\n<p>Retrieving resources<\/p>\n<p>Updating resources<\/p>\n<p>Deleting resources<\/p>\n<p>Regression Tests<\/p>\n<p>&nbsp;<\/p>\n<p>&nbsp;<\/p>\n","protected":false},"excerpt":{"rendered":"<p>API Endpoint http:islab1.ieis.tue.nl:8024\/api &nbsp; Authentication An access token is necessary to be used in each request. &nbsp; Summary of resources \/user \/player \/challenge \/gameDescriptor \/property \/propertyType \/propertyInstance \/gameSession \/tag \/dataProvider \/tokenForDataProvider \/rointMapping \/role \/support \/circle \/personalPoint \/participation \/reward \/sponsor \/rightToShowChallenge \/challengeRule \/condition \/operator To perform an operation on any of the above listed resources, you &hellip; <\/p>\n<p class=\"link-more\"><a href=\"https:\/\/blog.gamebus.eu\/index.php\/sample-page\/api\/\" class=\"more-link\">Continue reading<span class=\"screen-reader-text\"> &#8220;GameBus API&#8221;<\/span><\/a><\/p>\n","protected":false},"author":3,"featured_media":0,"parent":1114,"menu_order":1,"comment_status":"closed","ping_status":"closed","template":"","meta":{"footnotes":""},"categories":[],"tags":[],"class_list":["post-79","page","type-page","status-publish","hentry"],"_links":{"self":[{"href":"https:\/\/blog.gamebus.eu\/index.php\/wp-json\/wp\/v2\/pages\/79","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/blog.gamebus.eu\/index.php\/wp-json\/wp\/v2\/pages"}],"about":[{"href":"https:\/\/blog.gamebus.eu\/index.php\/wp-json\/wp\/v2\/types\/page"}],"author":[{"embeddable":true,"href":"https:\/\/blog.gamebus.eu\/index.php\/wp-json\/wp\/v2\/users\/3"}],"replies":[{"embeddable":true,"href":"https:\/\/blog.gamebus.eu\/index.php\/wp-json\/wp\/v2\/comments?post=79"}],"version-history":[{"count":0,"href":"https:\/\/blog.gamebus.eu\/index.php\/wp-json\/wp\/v2\/pages\/79\/revisions"}],"up":[{"embeddable":true,"href":"https:\/\/blog.gamebus.eu\/index.php\/wp-json\/wp\/v2\/pages\/1114"}],"wp:attachment":[{"href":"https:\/\/blog.gamebus.eu\/index.php\/wp-json\/wp\/v2\/media?parent=79"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blog.gamebus.eu\/index.php\/wp-json\/wp\/v2\/categories?post=79"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blog.gamebus.eu\/index.php\/wp-json\/wp\/v2\/tags?post=79"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}