Coming soon: Your brand new Help Center & Community! Get a sneak-peek here

Create Person with username via REST

Hi all, I did a simple search in the community with no luck.

How can I create a Person via REST API, giving to it a username on SuperOffice Service?

I mean the person.(user_candidate->person_id).secret_key.

I used this body:

 

{
  "Firstname": "Bud",
  "MiddleName": "",
  "Lastname": "Spencer",
  "Mrmrs": "ad",
  "Title": "voluptatum",
  "BirthDate": "1998-06-13T100:00:00",
  "UserInfo": {
    "Deleted": false,
 "UserName": "bspencer",
    "Rank": 0,
    "Tooltip": "",
    "UserType": "InternalAssociate",
    "GrantedLicenses": null,
    "CanLogon": true,
    "RoleName": "role1",
    "RoleTooltip": "text0001",
    "UserGroupName": "aa\\bb",
    "UserGroupTooltip": ""
  },
}

 

But, after a 200 OK, I obtain:

 

"UserInfo": null,

Any idea?

Thanks in advance

RE: Create Person with username via REST

Hi!

Any update here yet?

We are in a similar situation with "username" in CS, namely the ability to manipulate this field via REST.

This is how we get the username on a person:

ticket.cust_id.(user_candidate->person_id).secret_key

 
Thanks!
 
Af: Markus Moripen 30. aug 2019

RE: Create Person with username via REST

Hi.

Any update on this? The username is key for everything in our system. We really need to be able to set this!

Is there anyway I can set the person.(user_candidate->person_id).secret_key?

Espen

Af: Espen Fosshaug 31. jul 2020

RE: Create Person with username via REST

Hi!

Our Person API should support this. Unfortunately the only want to programmatically accomplish this today is via a CRMScript.

If you think this going to be a common enough task, then I suggest performing the one-time creation of a CRMScript to perform the task for you. You can do this via the API.

Now, there a couple ways you could do this.... you can create the whole person and dependencies in CRMScript, or you can create the Person using the /person endpoint, and rely on the CRM script solely for creating the user-candidate. My example below will assume the latter.

Fundamentally you know you need a person id to create a user-candidate... so assuming you have a person ID, here is how you create a CRMScript that will load the person (Customer), and then save it... That's all you need to do to create a U-C record.

The "HierarchyId": 14, value in the script below represents the script folder. The folder ID's can be obtained by submitting a GET request for all Scripts and identifying the desired folder by name.

Create CRMScript request:

POST https://sod.superoffice.com/Cust12345/api/v1/CRMScript
Authorization: Bearer 8A:Cust12345.AUUr...47zne
Content-Type: application/json
Accept: application/json

{
  "Name": "Create User-Candidate via API",
  "Description": "Testing Person User-Candidate creation.",
  "IncludeId": "myIncludeId",
  "HierarchyId": 14,
  "Source": "#setLanguageLevel 3;
if(getVariable(\"personId\").toInteger() > 0)
{
  Integer personId = getVariable(\"personId\").toInteger();
  Customer c;
  c.load(personId);
  c.save();
  log(\"Person loaded and saved\");
  print(\"Person saved!\");
}
else
{
  log(\"No customer found: id=\" + getVariable(\"personId\"));
  print(\"No person found!\");
}"
}

RESPONSE: Makes sure to remember the ejScriptId... You will need this to invoke the script.

HTTP/1.1 200 OK
Cache-Control: no-cache
...
Connection: close

{
  "TableRight": {
    "Mask": "FULL",
    "Reason": ""
  },
  "FieldProperties": {},
  "EjscriptId": 196,
  "UniqueIdentifier": "0c62cf2050ed4ee0be68481db6c941b8",
  "Name": "Create User-Candidate via API 2",
  "Description": "Testing Person User-Candidate creation.",
  "IncludeId": "myIncludeId",
  "HierarchyId": 14,
  "Source": "#setLanguageLevel 3;\r\nif(getVariable(\"personId\").toInteger() > 0)\r\n{\r\n  Integer personId = getVariable(\"personId\").toInteger();\r\n  Customer c;\r\n  c.load(personId);\r\n  c.save();\r\n  log(\"Person loaded and saved\");\r\n  print(\"Person saved!\");\r\n}\r\nelse\r\n{\r\n  log(\"No customer found: id=\" + getVariable(\"personId\"));\r\n}",
  "Registered": "2020-08-03T13:22:43",
  "RegisteredAssociateId": 5,
  "Updated": "0001-01-01T00:00:00",
  "UpdatedAssociateId": 0,
  "_Links": {
    "Self": "https://sod.superoffice.com:443/Cust26759/api/v1/CRMScript/196/",
    "Archive": "https://sod.superoffice.com:443/Cust26759/api/v1/CRMScript/"
  }
}

 

When you want to invoke it, pass in the person ID parameter:

POST https://sod.superoffice.com/Cust12345/api/v1/CRMScript/196/Execute
Authorization: Bearer 8A:Cust12345.AUU...47zne
Content-Type: application/json

{
        "personId": "27"
}

Although you will be able to see scripts created this way, you will not be able to save any edits in the service client until you specify a unique Key property. Alternatively, when the script needs to be updated, use a PATCH request.

PATCH https://sod.superoffice.com/Cust12345/api/v1/CRMScript/196
Authorization: Bearer 8A:Cust12345.AUUr...47zne
Content-Type: application/json
Accept: application/json

{
  "Source": "#setLanguageLevel 3;
if(getVariable(\"personId\").toInteger() > 0)
{
  Integer personId = getVariable(\"personId\").toInteger();
  Customer c;
  c.load(personId);
  c.save();
  log(\"Person loaded and saved\");
  print(\"Person saved!\");
}
else
{
  log(\"No person found: id=\" + getVariable(\"personId\"));
}",
}

When the script is no longer needed, simply delete it:

DELETE https://sod.superoffice.com/Cust12345/api/v1/CRMScript/196
Authorization: Bearer 8A:Cust12345.AUU...47zne
Content-Type: application/json

We'll add a task to update our Person API, but until that can get done, I hope this helps!

 

 

Af: Tony Yates 3. aug 2020

RE: Create Person with username via REST

Hi.

Has there been any changes in this? We really need to set username using rest api.

The described way is way to difficult!

With SOAP it is username = "xxaa"

Espen

Af: Espen Fosshaug 30. sep 2021