{Edited my code to include parent loop)
I'm having trouble with the Parse.Cloud.httpRequest function that runs in Parse cloud code and there's no documentation on this method.
Essentially I would like to be able to either
- access a global variable (channel_id) with in the success part of Parse.Cloud.httpRequest({}) so that it can be passed as parameter into a function (DoSomething()) or
- get the JSON response from of Parse.Cloud.httpRequest({}) and move the function that uses it (DoSomething()) outside of Parse.Cloud.httpRequest({}).
As of now, whatever variables I define inside of success have no scope outside of the function and when I try to access global variables inside success such as channel_id I have no access to them
var query = new Parse.Query("Channel");
query.equalTo("FrequentlyUpdated", false);
query.find ({
success: function (results) {
for (var i = 0; i < results.length; i++) {
channel_id = results[i].get("channel_id");
Parse.Cloud.httpRequest({
url: 'http://vimeo.com/api/v2/channel/' + channel_id + '/videos.json',
success: function (httpResponse) {
var response = httpResponse.text;
DoSomething(response, channel_id );
},
error: function (httpResponse) {
status.error("failed");
}
});
}
},
error: function() {
status.error("movie lookup failed");
}
});
Maybe there is a shorter version of the Parse.Cloud.httpRequest({}) function which simply takes the url and parameters etc. and returns the JSON or XML response?