Interface with External API [SOLVED]
ty13r
14 May 2016, 22:04
Is it possible to interface with an external API within Quest?
I'd like to setup an AJAX call to a remote server that outputs a URL to the user if a particular string is sent through the API, otherwise returning a null response.
In my mind this would allow me to use a custom passphrase that could not be determined by looking at the game's source code.
The Pixie
15 May 2016, 18:08I do not know, but I would guess yes. Mess around with JS.eval, and see what happens. And let us know!
Could you use GetFileData to pull a file across the internet, and examine that?
Could you use GetFileData to pull a file across the internet, and examine that?
ty13r
21 May 2016, 20:50Ok so I've got an API setup to return a response if the correct parameter is passed and have verified it's working.
i've added a JS file and have this function inside it.
My intention is now to pass a phrase by the player and return the response from the server.
So far I've had no luck getting this work in Quest, any help would be much appreciated!
i've added a JS file and have this function inside it.
function winning (result) {
$.ajax(
{
url : "http://MYURL.com/api.php",
type: "POST",
data : result,
success: function(result)
{
msg ("Success!" + result.status)
}
,
error: function ()
{
msg ("Error!")
}
}
);
}
My intention is now to pass a phrase by the player and return the response from the server.
So far I've had no luck getting this work in Quest, any help would be much appreciated!
ty13r
21 May 2016, 21:13Currently seeing these errors in the console:
XMLHttpRequest cannot load http://MYURL.com/api.php. No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'res://' is therefore not allowed access.
fb.js:15 Uncaught ReferenceError: ALSEvent is not defined
and
Uncaught ReferenceError: ALSEvent is not defined
XMLHttpRequest cannot load http://MYURL.com/api.php. No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'res://' is therefore not allowed access.
fb.js:15 Uncaught ReferenceError: ALSEvent is not defined
and
Uncaught ReferenceError: ALSEvent is not defined
ty13r
21 May 2016, 21:34ty13r wrote:Currently seeing these errors in the console:
XMLHttpRequest cannot load http://MYURL.com/api.php. No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'res://' is therefore not allowed access.
fb.js:15 Uncaught ReferenceError: ALSEvent is not defined
and
Uncaught ReferenceError: ALSEvent is not defined
Ok looks like that's an issue on my server's end. Will update when I've verified if this works.
ty13r
21 May 2016, 23:50Ok everyone I was able to get everything working as expected! 
I added a JS file and invoked the function via abstract interaction with an object.
Here's a copy of my finalized js code.

I added a JS file and invoked the function via abstract interaction with an object.
Here's a copy of my finalized js code.
function apiCall () {
var input = prompt ("enter code");
var inputObj = {'query' : input};
if (input != null) {
$.ajax({
type: 'POST',
dataType: 'text',
url: 'http://MYURL.com/api.php',
data: inputObj,
success: function (responseData, textStatus, jqXHR) {
if (responseData != "incorrect") {
$('#divOutput').html('<div>' + responseData + '</div>');
} else {
alert(responseData);
}
},
error: function (responseData, textStatus, errorThrown) {
alert('POST failed.');
}
});
} else {
alert('FAILBOAT')
}
}
The Pixie
22 May 2016, 06:20Good effort!
Can the Quest game determine if the right code was put in? I can see how the game will display whether it was successful of not; I cannot see how anything in the game world will know that however.
Can the Quest game determine if the right code was put in? I can see how the game will display whether it was successful of not; I cannot see how anything in the game world will know that however.
ty13r
22 May 2016, 06:28The Pixie wrote:Good effort!
Can the Quest game determine if the right code was put in? I can see how the game will display whether it was successful of not; I cannot see how anything in the game world will know that however.
Thank you. No the quest game is not able to determine the correct code to pass, it's all contained on my server's side.
Basically unless the correct value is passed in my server will return "incorrect"
If the user passes in the correct response the the server will return something of value to the user.
Server side code looks something like:
<?php
header('Access-Control-Allow-Origin: *');
$KEY = 'RANDOM STRING';
$ANSWER= 'RANDOM STRING';
$result = 'incorrect';
if (isset($_POST['query'])) {
$query = $_POST['query'];
$query_hash = hash('sha256', $query);
if ($query_hash == $KEY) {
$result = openssl_decrypt($ANSWER, 'aes256', $KEY);
}
}
echo $result;
The Pixie
22 May 2016, 06:45Have you tried the ASLEvent function in your JavaScript? If you have a function in Quest called SetResult that takes a string parameter, you should be able to call it like this:
ASLEvent ("SetResult", "correct");
ASLEvent ("SetResult", "wrong");
ASLEvent ("SetResult", "correct");
ASLEvent ("SetResult", "wrong");
ty13r
22 May 2016, 12:44The Pixie wrote:Have you tried the ASLEvent function in your JavaScript? If you have a function in Quest called SetResult that takes a string parameter, you should be able to call it like this:
ASLEvent ("SetResult", "correct");
ASLEvent ("SetResult", "wrong");
I tried to mess with getting the ASLevent to work, but reverted to prompt and alert for troubleshooting purposes.
Thanks for the tip, if I have time I will try to update this
