Page 1 of 1

Json request

Posted: Wed Jan 28, 2015 3:27 pm
by Joe Bohen

I would like to make a request to the Appery api using a $.getJSON request. I have attempted the following but get a:

{"code":"DBSQ002","description":"database id not specified"}

Although the database is specified in the request how is this acheived correctly using jquery?

code:

function restTest()
{

$.getJSON("https://api.appery.io/rest/1/db/colle...?",
{
'X-Appery-Database-Id': 'XXXXXXXe4b0747d4efdf493',
'type': 'get',
'dataType': 'json',
'contentType': 'application/json',
},
function(data) {
alert(data);
});

}


Json request

Posted: Wed Jan 28, 2015 5:41 pm
by Joe Bohen

Hi,

I have managed to get this working on the localhost with the help of stackoverflow. I would value your comments on this! Will I have problems with this after I publish the web site or will this continue to work even without authorisation. If it doe's then I hope others will benefit from this code if not doh!

function testRest() {

xhr = new XMLHttpRequest();

$.ajax({
url: 'https://api.appery.io/rest/1/db/colle...?',
type: 'GET',
datatype: 'jsonp',
success: function (data) {
alert(JSON.stringify(data));
},
error: function (data) {
alert(JSON.stringify(data));
},
beforeSend: setHeader
});
}
function setHeader(xhr) {
xhr.setRequestHeader('X-Appery-Database-Id', 'xxxxxxxxe4b0747d4efdf493');
}


Json request

Posted: Wed Jan 28, 2015 9:54 pm
by Ihor Didevych

Hi Joe,

you are not setting the header, you are setting simple parameter.
var as = $.ajax({
url: "https://api.appery.io/rest/1/db/colle...",
type: "GET",
headers: {
"X-Appery-Database-Id": " 548a9dd8XXXXXXX1aa8121f9"
}
}).done(function( data ) {
alert("Done");
});


Json request

Posted: Wed Jan 28, 2015 10:33 pm
by Joe Bohen

Hi, Ihor thanks for your reply, header or not I am happy that the call to the service is successful! Are you saying that this is not a legitimate method?


Json request

Posted: Thu Jan 29, 2015 4:39 pm
by Illya Stepanov

Hi Joe -

Possibly it may be working, but in different order, this needs to be debugged, hard to say at a first glance.


Json request

Posted: Thu Jan 29, 2015 5:18 pm
by Joe Bohen

Hi Illya, thank you for the reply I will let you know if I experience problems.


Json request

Posted: Thu Jan 29, 2015 5:45 pm
by Illya Stepanov

Ok Joe, feel free to let us know.