Tuesday 16 May 2017

parse cloud code afterSave returns error 107 cannot POST

I have problems with afterSave implementing my signup logic. What I have to do is to add a transaction in Wallet class when user makes the registration, giving him some credits. So i have my cloud code function:

// Add welcome bonus on signup
Parse.Cloud.afterSave(Parse.User, (request) => {
// commit transaction only on signup completed with phone number
  if (request.object.get('username')) {
    const wallet = new Parse.Object('Wallet')

    wallet.set('value', 100)
    wallet.set('action', '+')

    wallet.save(null,{useMasterKey: true}).then(
      (result) => console.log('objectId',result.id),
      (error) => console.log('code:',error.code,'message:',error.message)
    )
  }
})

Since Parse.Cloud.useMasterKey() is deprecated I follwed the Parse doc on how to use the useMasterKey option on save method, but i still got this error:

info: afterSave triggered for _User for user undefined:
  Input: {...} className=_User, triggerType=afterSave, user=undefined
code: 107 message: Received an error with invalid JSON from Parse: Cannot POST /classes/Wallet

Any ideas on what's going on?



via Pietralberto Mazza

No comments:

Post a Comment