Search code examples
restsalesforcehttpurlconnectionsalesforce-lightning

how to create a custom profile in salesforce using rest api


Am experimenting with salesforce apis by creating and patching with its api services.I dont know how to create a custom profile with the help of its apis and also i dont know what are all the required body parameters to create a profile. i tried sending a post request with the following body

{
"Name" : "testprofile"
}

to the url /services/data/v54.0/sobjects/Profile i got this message as response

{
        "message": "insufficient access rights on cross-reference id",
        "errorCode": "INSUFFICIENT_ACCESS_ON_CROSS_REFERENCE_ENTITY",
        "fields": []
    }

i reffered https://developer.salesforce.com/docs/atlas.en-us.234.0.object_reference.meta/object_reference/sforce_api_objects_profile.htm

havent got any eloborate writings on what should be in the body while using post request.. but it says create() methods are allowed


Solution

  • It seems that i have to add user license with the body along with the name for the post to scceeded once added it should look like this

    {
     "Name":"profilename",
     "UserLicenseId": "license id"
    }
    

    and thus made the request work