Search code examples
javascriptpasswordsnetsuitesuitescript

Set/Change user password through netsuite RESTlet script


I'm integrating a WordPress site with a client's NetSuite using RESTlet scripts in SuiteScript. It's been going pretty well until I got to the reset password part. When a user change's their password in WordPress I'd like to update their password for NetSuite as well.

I figured I could use the nlapiSubmitRecord and update the record with a new pass but I don't see anywhere that talks about a password field. I'm assuming there's some functionality I don't know about or maybe it's just not possible to do through a RESTlet script?


Solution

  • I took a quick glance through the docs, and I see this is available in 2.0. Check out the (N/auth Module) and the auth.changePassword Method.

    They also included some demo code that show how to change the current user's email and password:

    /**
     *@NApiVersion 2.x
     */
    require(['N/auth'],function(auth){
      function changeEmailAndPassword() {
        var password='myCurrentPassword';
        auth.changeEmail({
          password:password,
          newEmail:'[email protected]'
        });
        auth.changePassword({
          currentPassword:password,
          newPassword:'myNewPa55Word'
        });
      }
      changeEmailAndPassword();
    });