How to create users while registering with different roles via API?

@juniorconte not sure how this is working for you. You were right about role not being set properly during registration. This was a bug and I just fixed this on develop. With this bug fixed your script should work properly now. Also I would suggest not to use “type” in payload. This can be easily altered by any app. Instead use your API KEY to detect which app (customer or vendor) the request is coming from. DF2 already translates the API KEY to app id and stores it in the session. You can get it in ‘platform.session.app.id’. Here is the modified version of your script. I tried this with the bug fixed and it works.

var lodash = require("lodash.min.js");

var role1Id = 2;
var role2Id = 3;

var appVendorId = 66;
var appCustomerId = 65;

var originAppId = platform.session.app.id;

if (platform.session.user) {
      var userObject = platform.api.get('system/user/'+platform.session.user.id+'?related=user_to_app_to_role_by_user_id');

      lodash._.each(userObject.content.user_to_app_to_role_by_user_id, function(userApp) {
       switch (originAppId) {
          case appCustomerId:
          if (userApp.app_id === appCustomerId) {
              userApp.role_id = role1Id;
          }
          break;
          case appVendorId:
          if (userApp.app_id === appVendorId) {
              userApp.role_id = role2Id;
          }
          break;
      }
     });

    platform.api.patch('system/user/'+platform.session.user.id+'?related=user_to_app_to_role_by_user_id', userObject.content);
}