Method: Saving entity

POST api/publicapi/saveentity

When updating an entity, only the fields that should be updated need to be provided. Full list of entity fields can be sent, but it is not necessary. “EntityType” is always a required fields.

If “Id” is not provided, or has a value less than 1, the data will be inserted as new record.

Example creating a new ticket:

Some fields like GroupId and FormId will be set automatically if not included in inserted data. For missing group, the current user’s profile setting for default group will be used, and if this is not available, then the system default group will be used. If formId is not supplied, then default agent-form will be set. There are no mandatory ticket fields except “EntityType”, but it is recommended that “BaseHeader”, “BaseDescription”, “BaseEntityStatusId” are set.

POST api/publicapi/saveentity

{

    "EntityType": "Ticket",

    "BaseHeader": "Create new ticket",

    "PriorityId": 7,

    "CategoryId": 7,

    "BaseEntityStatusId": 1,

    "AgentGroupId": 1,

    "BaseEntitySource": 1,

    "FormId": 1,

    "BaseDescription": "New ticket via <strong>API</strong>"

}

 

If you have entity with dynamic properties you can send in request to save data;

POST api/publicapi/saveentity

{

    "EntityType": "Ticket",

    "BaseHeader": "Create new ticket",

    "PriorityId": 7,

    "CategoryId": 7,

    "BaseEntityStatusId": 1,

    "AgentGroupId": 1,

    "BaseEntitySource": 1,

    "FormId": 1,

    "BaseDescription": "New ticket via <strong>API</strong>",

    "DynamicProperties": {

                            "CustomField1": "Value for custom field"

                         }   

}

 

Example creating a new user:

Before inserting a user, check first if a user with identical email address already exists. There must be only one unique email per user in system, and trying to insert duplicate will cause an error response. This rule applies even to soft-deleted users. To avoid this issue, include the parameter “fetchDeleted”: true, in query to check if user exists. If a soft-deleted user exists, then it is possible to either update this record with a garbled email address, or restore and reuse the user object.

It is recommended that all below fields concerning user-name be filled in:

POST api/publicapi/saveentity

{

  "EntityType": "Person",

  "Id": "",

  "FirstName": "Test",

  "LastName": "User",

  "FullName": "Test User",

  "DisplayName": "Test User",

  "Email": "testuser1@nilex.se",

  "EMailAddress": "testuser1@nilex.se",

  "Phone": "+4642180050",

  "MobilePhone": null,

  "JobTitle": null,

  "Department": null,

  "IsActive": true,

  "u_MyCustomField": "Inserting test user."

}

 

Example updating existing user’s contact information:

{

    "Id": 1

    "EntityType": "Person",   

    "Phone": "+46 042 18 00 50",

    "Email": "sadmin@nilex.se"

}

Example adding a comment with attachment to a ticket:

{

  "Id": 192,

  "EntityType": "Ticket",

  "UpdatedDate": "2015-09-02T13:30:21Z",

  "Comments": [{

    "Id": null,

    "Body": "Adding new public comment with attachment",

    "IsPublic": true,

    "CommentTime": 1320,

    "Attachments": [{ 

      "Id": 0,

      "FileSize": 35,

      "ContentType": "image/gif",

      "FileName": "tinygif.gif",

      "Data": "R0lGODlhAQABAIAAAAUEBAAAACwAAAAAAQABAAACAkQBADs="

    }]

  }],

}

Binary data for attachments should be base64-encoded.

Example adding worklog to ticket:

{

  "Id": 192,  

  "EntityType": "Ticket", 

  "WorkLogs": [{

    "Id": null,

    "AgentId": 1,

    "TimeMinutes": 100,

    "Description": "Work done",

    "StartDate": "2018-04-01T02:34:10"

  }],

}