Start a new topic
Answered

Active user unable to update his own record via endpoint?

I am following this tutorial: http://emadibrahim.com/2013/10/30/kinvey-stripe/


Everything works fine except the user record will not update.  This will fail:


collectionAccess.collection('user')

                    .update({"username": request.username},

                        { $set: { "stripeCustomer": JSON.parse(body) } }); 


Obviously the user calling the custom end point is logged in, obviously. 


But if I test the endpoint in the console logged in with master key and hardcode the username then the user will be updated so the update function is not failing per se. 


I have also tried somehow debug the update function but it returns only what looks like my request, not the response so I don't know what is wrong.  


Best Answer

Hi,


I was able to execute this: 

modules.collectionAccess.collection('user').update({"username": request.username}, {$set: { "stripeCustomer": request.body }}, function (err, res) { 
//    modules.logger.info(err);
//    modules.logger.info(res);
    response.complete(200);
});

 

Possible issues with your code:

  1. The request.body is already a JSON object. No need to use JSON.parse() on it.
  2. No callback in the statement you gave. I have included that.

Also, your code needs to be able to handle error conditions.

Do let me know if this is helpful.


Regards,
Wani
Kinvey Support

It helped, thanks!



Answer

Hi,


I was able to execute this: 

modules.collectionAccess.collection('user').update({"username": request.username}, {$set: { "stripeCustomer": request.body }}, function (err, res) { 
//    modules.logger.info(err);
//    modules.logger.info(res);
    response.complete(200);
});

 

Possible issues with your code:

  1. The request.body is already a JSON object. No need to use JSON.parse() on it.
  2. No callback in the statement you gave. I have included that.

Also, your code needs to be able to handle error conditions.

Do let me know if this is helpful.


Regards,
Wani
Kinvey Support
Login or Signup to post a comment