Create Community User through REST API

I am using the nForce library with node.js.
Everything seems to be right and we perform CRUD on the Case object.

However when we try to create a User using an external account with “Delegated External User Administrator” permission, the API returns the following message:

{errorCode: “INVALID_FIELD”, messageBody: “No such column ‘profileid’
on sobject of type User”, statusCode: 400, $get: function, $save:
function…}

This is the data we sent to https://<org domain>/services/data/v30.0/sobjects/user using HTTP POST:

{
   "Username": "testapi@test.com",
   "LastName": "API",
   "Email": "testapi@test.com",
   "Alias": "testapi",
   "TimeZoneSidKey" : "America/Los_Angeles",
   "LocaleSidKey" : "en_US",
   "EmailEncodingKey" : "ISO-8859-1",
   "ProfileId" : "00e90000001a88W",
   "LanguageLocaleKey" : "en_US",
   "ContactId": "00390000013gwDS"
 }

How come there is no ‘profileid’ column? I can create a user using an internal admin account with the same set of data on the REST API.

Can a user with “Delegated External User Administrator” permission create a new external user through the REST API?

Answer

If it’s an issue, why don’t you create a custom REST apex class?

here’s a sample class and method:

@RestResource(urlMapping='/UserOperation/*')
global without sharing class RESTUserController {

    @HttpPost   
    global static String CreateNewUser(String Username,String LastName,String Email,String Alias,String TimeZoneSidKey,String LocaleSidKey,String EmailEncodingKey,String ProfileId,String LanguageLocaleKey,String ContactId) {
        User newUser = new User();
        newUser.Username = Username;
        newUser.LastName = LastName;
        newUser.Email = Email;
        newUser.Alias = Alias;
        newUser.TimeZoneSidKey = TimeZoneSidKey;
        newUser.LocaleSidKey = LocaleSidKey;
        newUser.EmailEncodingKey = EmailEncodingKey;
        newUser.ProfileId = ProfileId;
        newUser.LanguageLocaleKey = LanguageLocaleKey;
        newUser.ContactId = ContactId;
        insert newUser;
        return 'User Created! Id Is: ' + newUser.Id ;
    }
}

Attribution
Source : Link , Question Author : Oscar Tang , Answer Author : Haytham

Leave a Comment