Start a new topic

Custom endpoint giving null values frequently

Last two days my app when make queries is returning null values frequently.

Our in house app testing team is not satisfied with this.

Can you please help me solve this issue.

We need more information about your issue to be able to properly debug.
Hi

Am trying to fetch from database using the code:

_dict = [[NSDictionary alloc] initWithObjectsAndKeys:_username,@"userName", nil];

NSString* string = @"userSelfiesPopular";



[KCSCustomEndpoints callEndpoint:string params:_dict completionBlock:^(id results, NSError *error) {

if(results){

NSLog("loading datas successful");

}else{

NSLog("loading datas not successful");

}

}];



The custom endpoint is as follows:



function onRequest(request, response, modules){



var collectionAccess = modules.collectionAccess;

var myCollection = collectionAccess.collection('selfieObjects');

var count, docCount=0;

var logger = modules.logger;



logger.info(request.body.userName);



//var selfieuser = request.body.user;

//find the current user in the user collection

myCollection.find({"username": request.body.userName},{sort:{"likes":-1}, skip:request.body.skip, limit:28}, function (err, docs) {



if (err) {



response.body = {error: error.message};

logger.info(response.body);

response.complete(434);



} else {



response.body = docs; //return the count of the collection

//logger.info(response.body);

response.complete(200);



}

});



}



The problem is that once in 5 call the datas are not loaded
This is happening only for last 2 days

Before that it was working well.

Please let me know if you need my app id or secret
Have you tried hitting the endpoint directly from the API console? That will isolate the endpoint and tell you if the issue is a bug with your code.


Hey Caroline

I tries the following in the api console

GET//rpc/kid_PTpOcIN_1f/custom/userSelfiesPopular/?q={"username":"joshuacleetus"}

can you please tell me if this is right
Cause its not giving any correct response
Can you please tell me how to use the custom endpoint in a api console

i dont know how to use it
Hey Caroline

Atlast i figured it out

This is the error it gives in every 3 requests

{

"error": "BLRuntimeError",

"description": "The Business Logic script has a runtime error. See debug message for details.",

"debug": "ReferenceError: error is not defined"

}
request

POST https://baas.kinvey.com/rpc/kid_PTpOcIN_1f/custom/userSelfiesPopular HTTP/1.1

Authorization: Basic a2lkX1BUcE9jSU5fMWY6NjlmYzcxODc1Y2FjNDk1ZWExMGZjMDI2YjViOWFjMzQ=

X-Kinvey-API-Version: 3



{

"userName": "joshuacleetus"

}

response

HTTP/1.1 400

Content-Type: application/json

X-Kinvey-API-Version: 3

X-Kinvey-Request-Id: 9fc294366053454dbc597be7b7d7f15d

X-Powered-By: Express



{

"error": "BLRuntimeError",

"description": "The Business Logic script has a runtime error. See debug message for details.",

"debug": "ReferenceError: error is not defined"

}
I am also having the same issue across all of my endpoints. Every 5-10 requests using collectionAccess.collection return without an error, but the results are null. This just started happening late last week.
To elaborate, I have been hitting the endpoint via the API console with the exact same parameters. Most of the time it works, but every 5-10 requests end up returning null.
For now i found a solution.

Show the activity indicator and call the api in a loop till it returns the value.

And this happens very fast.
Hi Joshua,



Can you post some sample code from your solution and flag it as the answer, so it can help others going forward?
Login or Signup to post a comment