Hello,
I would like to fetch some data from another API in a Parse.Cloud function, I initially tried using Parse.Cloud.httpRequest inside my function like this:
Parse.Cloud.define(
"cloudTestFunction",
async (request) => {
const query = new Parse.Query("MyParseClass");
// skipping the lines where I build the query
const results = await query.find();
const firstResult = results[0];
if (firstResult == null) {
// here I want to get data from another API
Parse.Cloud.httpRequest({
url: "otherAPIURL"
}).then(function(httpResponse) {
return 'yeah';
},function(httpResponse) {
return 'oops';
});
} else {
return 'result found';
// return firstResult;
}
}
);
When doing this, I get this error:
āæ ParseError code=141 error=Parse.Cloud.httpRequest is not a function
- code : ParseSwift.ParseError.Code.scriptFailed
- message : āParse.Cloud.httpRequest is not a functionā
- otherCode : nil
- error : nil
Then, I tried using another library to do it, and especially Got.
I ran npm install got, then added const got = require('got');
to the top of my file containing the parse cloud function, and replaced the Parse.Cloud.httpRequest
part with this:
const text = await got("otherAPIURL").text();
return text;
But now I get a very similar error:
āæ ParseError code=141 error=got(...).text is not a function
code : ParseSwift.ParseError.Code.scriptFailed
message : "got(...).text is not a function"
otherCode : nil
error : nil
Could you please help me trying to find a solution for this problem.
Thank you for your help