Freshworks customers have real-world data modelling requirements, all of which cannot be met by a product’s native objects. The products offer custom fields to extend the existing native objects. At times, customers need entities that are related to native objects but do not exist within the product. Custom objects help meet this requirement. Through the use of an app, custom objects, and their relationships to native objects (associations) customers can create and use entities that act as part of the product itself, to meet specific functional requirements.
Apps that consume the default native objects or custom fields that the Freshworks products offer, can use the developer platform’s data storage feature. For a long time, the developer platform supported only key-value storage. This poses certain limitations in terms of key size, value field size, reverse look-ups, and capabilities to query, aggregate, report, and relate data. As part of the custom objects functionality, the developer platform offers entity storage in addition to the existing key-value storage. Entity storage helps provide capabilities such as reporting and aggregation of stored data, look up, retrieval and usage of relational information, querying on stored data, and so on.
To leverage the entity storage - custom objects feature, when you build an app, ensure to use FDK 8.5.0 or a later version.
To create and use custom objects,
- Define entities.
- As part of the app code, use the custom objects interface to create entity records.
- As part of the app code, define the necessary actions or operations on the entity records.
Sample use case - KYC record creation and updation for all contacts in the Freshsales Suite system. On initialization, the app leverages the custom objects feature to create KYC records for contacts in the Freshsales system, if such a record does not exist for a contact. On record creation the KYC status is Pending. The app is deployed as a full page app and also as a Contact Details page app. The app displays all KYC records in the Pending status. Also, through entity-storage retrievals, the app provides a provision to view the KYC documents. Based on the submitted approval documents, an agent can approve or reject the KYC document. The app updates the entity-storage records and displays the updated status on the app interface.
For a demonstration of this use case, see Freshsales Suite Contact-KYC App.
Currently, Custom Objects does not support defining associations between custom and native objects.
You can build apps that use custom objects and submit the apps as a Freshworks app or Custom app. After review and approval, the Freshworks app is published to the marketplace. The published app or the custom app is available for installation. If you are unable to install a published app or publish a custom app, please contact us.
Define Entities
In Freshworks products, business data is modelled as objects. The objects are created out of specific object types. An entity is an object type. Entity definition is the schema definition of the object type. Schema definition includes the definition of all the object.attributes. Contacts, Agents, Products, Deals, Sales Accounts, Tasks and so on are some default native objects. tasks.description, tasks.status and tasks.due_date are some of the attributes of the task entity.
You can use the custom objects feature to define new entities (object types). An object belonging to an entity (object type) is a record. Entity records (objects) of the defined object types can be created and an app can process these records to provide meaningful results.
To define and use entities:
- Define the custom object schema - Entity definition specification. The schema includes all object.attribute definitions.
- Initiate entity storage.
- Obtain a reference to the entity to facilitate schema and record operations.
Entity definition specification
- From the app’s root directory, navigate to the config folder and create an entities.json file.
- In the entities.json file, use the following syntax to configure all custom objects that the app uses, as JSON objects.
- You can define a maximum of five entities for each business account.
- You can define a maximum of 20 fields (attributes) for each entity.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 | { "<entity-name>": { "fields": [{ "name": "<attribute-name1>", "label": "<display-text>", "type": "<data type>", ... }, { "name": "<attribute-name2>", "label": "<display-text>", "type": "<data type>", "filterable": <true/false> }, ... ]}, "<entity-name1>": { "fields": [{ "name": "<attribute-name1>", "label": "<display-text>", "type": "<data type>" }, { "name": "<attribute-name2>", "label": "<display-text>", "type": "<data type>", "filterable": <true/false> }, ... ]} } |
File attribute | Data type | Description |
---|---|---|
<entity-name> | object | Schema definition of the custom object. An app can create records of type <entity-name> and process the records. For example, for an app to create a custom object kyc_status, <entity-name> in entities.json is kyc_status. The app and its users can create multiple records or objects of type kyc_status. Each record is a collection of attributes. In entities.json, specify the attributes’ definition through the fields array. |
fieldsMANDATORYChild attribute of <entity-name> | array of field objects | All attributes of the custom object, specified as an array. Each array element contains a list of child-attributes that define the custom object.attribute. |
Attribute name | Data type | Definition | ||
---|---|---|---|---|
name MANDATORY This is an alphanumeric field and can contain underscores. Must start with an alphabetic character. |
string | Identifier of the attribute. When creating, programmatically storing objects, and querying data belonging to a specific entity (object type), ensure to use the exact fields.name that is specified in the schema. | ||
label MANDATORY | string | Default display name for the attribute when it is exposed through a front-end component. In the app files that render the app’s front-end components, if a different value is specified as the label for the input field, the values in the front-end files take precedence. | ||
type MANDATORY | string | Data type of the attribute.
Possible values:
|
||
choices Mandatory and valid for an attribute of type enum Should not be an empty array | array of objects | Options that populate the drop-down list of an attribute of type enum. Attributes of the object: id (integer): Numeric identifier of the option. value (string): Actual option displayed in the drop-down list, when the attribute is exposed through a front-end component. | ||
fields Mandatory and valid for an attribute of type section | array of field objects | Schema definition of all the fields grouped under a section or sub-section. | ||
filterable | boolean | Specifies whether a subset of the stored records can be retrieved by specifying filter conditions for the attribute.
Notes:
Default value: false
|
||
required | boolean | Specifies whether the attribute is a mandatory attribute of the custom object.
When creating and updating records, ensure that the calls to the custom objects interface contain valid values for the attributes whose required value is true.
Note: An attribute of type section cannot be a mandatory attribute.
Default value: false |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 | { "kyc_status": { "fields": [ { "name": "customer_email", "label": "Email", "type": "text", "required": true, "filterable": true }, { "name": "status", "label": "KYC Status", "type": "enum", "choices": [ { "id": 1, "value": "Pending" }, { "id": 2, "value": "Approved" }, { "id": 3, "value": "Rejected" } ], "required": true, "filterable": true }, { "name": "applied_on", "label": "Date of KYC application", "type": "date", "required": true }, { "name": "processed_on", "label": "KYC application processed at", "type": "datetime", "required": false }, { "name": "document", "label": "Document", "type": "section", "fields": [ { "name": "document_details", "label": "Document details", "type": "section", "fields": [ { "name": "document_type", "label": "Document Type", "type": "enum", "choices": [ { "id": 1, "value": "Passport" }, { "id": 2, "value": "Voter ID" } ], "required": true }, { "name": "document_id", "type": "text", "label": "Document ID/number", "required": true } ] }, { "name": "document_url", "type": "paragraph", "label": "Document URL" } ] } ] } } |
Initiate entity storage
The developer platform’s data storage feature offers a client.db or $db interface to store and retrieve data. For custom objects, the interface is enhanced beyond its lightweight key-value storage capabilities to support entity storage. This facilitates custom object schema creation and deletion and CRUD operations on the records. Currently, the entity storage is accessible through a versioned interface that specifies that the app uses the v1 version of the entity storage feature. To initiate entity storage and start using the custom objects interface, use the following constructor:
Sample frontend or client-side file Copied Copy1 | const entity = client.db.entity({ version: 'v1' }); |
1 | const $entity = $db.entity({ version: 'v1' }); |
The constructor returns a versioned wrapper interface that can be used for custom objects operations.
Obtain a reference to the entity
To obtain a reference to the entity, use one of the following interface calls:
Copied Copy1 2 | const <entReference> = entity.get('<entity-name>'); const <entReference> = $entity.get('<entity-name>'); |
1 | const contact_entity = entity.get('kyc_status'); |
1 | const contact_entity = $entity.get('kyc_status'); |
A successful call returns a class that represents the entity and contains the static methods that can be used to perform operations on the entity records.
Copied Copy1 2 3 4 5 6 7 8 | { schema: async function() {}, create: async function() {}, get: async function() {}, getAll: async function() {}, update: async function() {}, delete: async function() {} } |
Create entities
The fdk validate and fdk pack commands validate the entities.json file, to ensure that the Entity Definition Specifications are appropriate. You can test entities creation and record operations before submitting the app.
App installation implicitly creates the entities specified in entities.json.
Retrieve entity schema
To verify the entity creation and view the schema of the created entity, use one of the following interface calls:
1 2 | <entReference>.schema(); $entity.get('<entity-name>').schema(); |
1 | contact_entity.schema(); |
1 | $entity.get('kyc_status').schema(); |
A successful call returns the entity object created based on entities.json specification, along with the following meta-data:
- id: Unique numeric identifier of the entity, auto-generated by the developer platform when the entity is created and stored.
- name: <entity-name> as specified in entities.json.
- prefix: Prefix associated with the entity and used in internal interface calls to uniquely identify entities, auto-generated by the developer platform when the entity is created.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 | { "entity": { "id": 59126, "name": "kyc_status", "prefix": "kycs", "fields": [ { "name": "customer_email", "label": "Email", "type": "text", "required": true, "filterable": true }, { "name": "status", "label": "KYC Status", "type": "enum", "choices": [ { "id": 1, "value": "Pending" }, { "id": 2, "value": "Approved" }, { "id": 3, "value": "Rejected" } ], "required": true, "filterable": true }, { "name": "applied_on", "label": "Date of KYC application", "type": "date", "required": true }, { "name": "processed_on", "label": "KYC application processed at", "type": "datetime", "required": false }, { "name": "document", "label": "Document", "type": "section", "fields": [ { "name": "document_details", "label": "Document details", "type": "section", "fields": [ { "name": "document_type", "label": "Document Type", "type": "enum", "choices": [ { "id": 1, "value": "Passport" }, { "id": 2, "value": "Voter ID" } ], "required": true }, { "name": "document_id", "type": "text", "label": "Document ID/number", "required": true } ] }, { "name": "document_url", "type": "paragraph", "label": "Document URL" } ] } } |
For information on the fields array, see Attributes of field object.
Delete entities
App uninstallation clean slates data and implicitly deletes the entities definition.
Modify entity definition specification
After an app is published to the marketplace, you can modify the entity definition specification, test the changes, and resubmit a new version of the app.
In entities.json,
- You can add new entities.
- You can delete existing entities. All records associated with the deleted entity are deleted.
- If you modify the <entity-name> of an existing entity, the entity with the previous <entity-name> is deleted and a new entity is created. All records associated with the previous <entity-name> are deleted.
In entities.json > <entities-name>.fields,
- You can add a new field object.
- You can delete an existing field object.
- If you modify the fields.name value, the attribute with the previous name is deleted and a new attribute is created.
- For an existing field, you cannot modify the fields.type value.
- For an existing field, you cannot modify the fields.filterable value.
- For an existing field, you can modify the fields.required value. If the fields.required value is modified to be true, for all existing entity records with no values for the field that is marked as required, the field value is stored as null.
- For an attribute of the type enum, you cannot modify the fields.choices array.
- For an attribute of the type section, you can add or delete new fields.
Define record operations
Through the app and its components, multiple records (objects) of a specific entity type can be created. These records provide data that can be processed by the app. As part of processing the data, the app can programmatically perform the following operations on the records:
- Create records.
- Update a record.
- Retrieve records.
The operations are performed through the custom objects interface, which returns promises. Successful calls return responses with requisite data and the following:
Response meta-data- display_id: Unique identifier of a record, auto-generated when the record is created. It is a combination of the prefix used to identify the entity and an incremental numeric value that uniquely identifies the record.
- created_at: Timestamp of when the record is created, specified in the ISO-8601 format.
- updated_at: Timestamp of when the record is last updated, specified in the ISO-8601 format.
Create a record
To create a record belonging to a specific entity, use one of the following interface calls:
- A maximum of 10k records can be created for each entity. Currently, batch operations/bulk record creation is not supported.
- Each record can be of maximum 100 kb.
- <entReference> is a reference to the actual entity.
1 2 3 4 | <entReference>.create({ <fields.name1>: <valid value for fields.name1>, <fields.name2>: "<valid value for fields.name2>" }); |
1 2 3 4 | const record = await $entity.get(‘<entity-name>’).create({ <fields.name1>: <valid value for fields.name1>, <fields.name2>: "<valid value for fields.name2>" }); |
1 2 3 4 5 6 7 | contact_entity.create(newRecord) .then(function (data) { // Success message }) .catch(function (error) { // Error handling }) |
1 2 3 4 5 6 7 8 | { "customer_email": "Peterparker@customerplace.com", "status": "Pending", "applied_on": "2022-08-18", "document_type": "Passport", "document_id": "F897650", "document_url": "https://i.pinimg.com/736x/de/32/7b/de327b2a02ec37e43186a50d0d788e86.jpg", } |
Response: A successful create operation, returns the record object created based on the input and the corresponding meta-data. record.data contains the JSON object that is stored as the record text.
Sample response Copied Copy1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 | { "record": { "display_id": "kycs-13", "created_time": "2022-08-18T07:52:47.266Z", "updated_time": "2022-08-18T07:52:47.266Z", "data": { "customer_email": "Peterparker@customerplace.com", "status": "Pending", "applied_on": "2022-08-18", "processed_on": null, "document_type": "Passport", "document_id": "F897650", "document_url": "https://i.pinimg.com/736x/de/32/7b/de327b2a02ec37e43186a50d0d788e86.jpg", } } } |
Update a record
To update a record belonging to a specific entity, use one of the following interface calls:
- <entReference> is a reference to the actual entity. <display-id> is the unique identifier of a record, auto-generated when the record is created. <display-id> is returned as part of the response to a successful create record operation.
- Ensure that all attributes specified as required in entities.json are passed as part of the request call payload.
1 2 3 4 | <entReference>.update("<display-id>", { <fields.name1>: <valid value for fields.name1>, <fields.name2>: "<valid value for fields.name2>" }); |
1 2 3 4 | const record = await $entity.get(‘<entity-name>’).update(‘<display-id>’, { <fields.name1 of the field to be updated>: <valid value for fields.name1>, <fields.name2>: "<valid value for fields.name2>" }); |
1 2 3 4 | contact_entity.update("kycs-13", { "status": "Approved", "processed_on": "2022-08-18T07:57:47.266Z" }); |
Response: A successful update operation, returns the record object updated based on the input and the corresponding meta-data. record.data contains the JSON object that is stored as the updated record text.
Sample response Copied Copy1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 | { "record":{ "display_id": "kycs-13", "created_time": "2022-08-18T07:52:47.266Z", "updated_time": "2022-08-18T07:57:47.266Z", "data": { "customer_email": "Peterparker@customerplace.com", "status": "Approved", "applied_on": "2022-08-18", "processed_on": "2022-08-18T07:57:47.266Z", "document_type": "Passport", "document_id": "F897650", "document_url": "https://i.pinimg.com/736x/de/32/7b/de327b2a02ec37e43186a50d0d788e86.jpg", } } } |
Retrieve a record
To retrieve a specific record belonging to a specific entity, use one of the following interface calls:
1 | <entReference>.get("<display-id>"); |
1 | const record = await $entity.get('<entity-name>').get('<display-id>'); |
1 | contact_entity.get("kycs-13"); |
Response: A successful retrieve by display-id operation, returns the retrieved record object and the corresponding meta-data. record.data contains the JSON object that is stored as the record text.
Sample response Copied Copy1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 | { "record":{ "display_id": "kycs-13", "created_time": "2022-04-27T07:52:47.266Z", "updated_time": "2022-08-18T07:57:47.266Z", "data": { "customer_email": "Peterparker@customerplace.com", "status": "Approved", "applied_on": "2022-08-18", "processed_on": "2022-08-18T07:57:47.266Z", "document_type": "Passport", "document_id": "F897650", "document_url": "https://i.pinimg.com/736x/de/32/7b/de327b2a02ec37e43186a50d0d788e86.jpg", } } } |
Retrieve all records
To retrieve all records belonging to a specific entity, use one of the following interface calls:
1 | <entReference>.getAll(); |
1 | const records = await <entReference>.getAll({}); |
1 2 3 4 5 6 7 8 9 | function loadContacts() { contact_entity.getAll() .then(function (data) { //render details of all contacts as a list }) .catch(function (error) { //error message }) } |
Response: A successful retrieve all records operation, returns the retrieved records as an array of objects. The retrieved records are not paginated and are retrieved in sets of 100 records. The links attribute in the response provides a token to retrieve the next set of records.
Sample response Copied Copy1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 | { "records": [{ "display_id": "kycs-13", "created_time": "2022-08-18T07:52:47.266Z", "updated_time": "2022-08-18T07:52:47.266Z", "data": { "customer_email": "Peterparker@customerplace.com", "status": "Pending", "applied_on": "2022-08-18", "processed_on": null, "document_type": "Passport", "document_id": "F897650", "document_url": "https://i.pinimg.com/736x/de/32/7b/de327b2a02ec37e43186a50d0d788e86.jpg", } }, { "display_id": "kycs-14", "created_time": "2022-08-18T07:52:47.266Z", "updated_time": "2022-08-18T07:52:47.266Z", "data": { "customer_email": "lanceparker@customerplace.com", "status": "Pending", "applied_on": "2022-08-18", "processed_on": null, "document_type": "Voter ID", "document_id": "ASF10", "document_url": "https://i.pinimg.com/736x/de/32/7b/de50d0d788e86.jpg", } }], "links": { "next": { "marker": "Lbr2zerj3WHNDsZ1NsdFj7NiigDlittVkGc7RmPjKF3" } } } |
Attribute name | Data type | Description | ||
---|---|---|---|---|
records | array of objects | All retrieved records belonging to a specific entity, specified as an array of objects. Each array element is an object with the following attributes:
|
||
links | link object | Link to the next set of records. Attribute of the link object: next (object): Identifier of the next set of records, in the following key: value format: Copied Copy
|
1 2 3 4 5 6 7 8 9 10 11 12 | function loadContacts() { contact_entity.getAll({ next: { marker: "Lbr2zerj3WHNDsZ1NsdFj7NiigDlittVkGc7RmPjKF3" }}) .then(function (data) { //render details of all contacts as a list }) .catch(function (error) { //error message }) } |
Response: The marker value, in the call, is an encoded token of a record id. A successful call retrieves the next set of records, starting from the record identified by the marker value. The marker value of the last set of records is null.
Apply filters and retrieve specific records
You can include queries as part of the retrieve all records call and thereby specify filter criteria for the filterable fields. On successful processing of the call only specific records that satisfy the criteria are retrieved.
To specify queries as part of the interface call, use the following format:
- When filtering by a datetime field, ensure that the filter criteria is specified in the ISO-8601 format. Range querying on datetime fields is currently not supported.
- <entReference> is a reference to the actual entity.
1 2 3 4 5 | <entReference>.getAll({ query: { <filterable field-name>: "<filter criteria value>" } }); |
1 2 3 4 5 | const record = await <entReference>.getAll({ query: { <filterable field-name>: "<filter criteria value>" } }); |
To use the and or or operations to construct a query with multiple query parameters, use the following samples:
- When constructing a query with multiple query parameters, a minimum of two query parameters and a maximum of three filterable fields or query parameters should be used.
- In an and operation, ensure that the attributes (filterable fields) used are different.
- In an or operation, ensure that the attributes (filterable fields) used are the same.
- Nested queries are not supported.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 | const record = contact_entity.getAll({ query: { $or:[{ status: "Pending" }, { status: "Rejected" } ]} }).then(function(data){ // access to filtered contacts }).catch(function(data){ // Handle errors }) |
1 2 3 4 5 6 7 8 9 10 | const record = await contact_entity.getAll({ query: { $or:[{ status: "Pending" }, { status: "Rejected" }] } }); |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 | { "records": [{ "display_id": "kycs-13", "created_time": "2022-08-18T07:52:47.266Z", "updated_time": "2022-08-18T07:52:47.266Z", "data": { "customer_email": "Peterparker@customerplace.com", "status": "Pending", "applied_on": "2022-08-18", "processed_on": null, "document_type": "Passport", "document_id": "F897650", "document_url": "https://i.pinimg.com/736x/de/32/7b/de327b2a02ec37e43186a50d0d788e86.jpg", } }, { "display_id": "kycs-14", "created_time": "2022-08-18T07:52:47.266Z", "updated_time": "2022-08-18T07:52:47.266Z", "data": { "customer_email": "lanceparker@customerplace.com", "status": "Pending", "applied_on": "2022-08-18", "processed_on": null, "document_type": "Voter ID", "document_id": "ASF10", "document_url": "https://i.pinimg.com/736x/de/32/7b/de50d0d788e86.jpg", } }], "links": { "next": { "marker": "Lbr2zerj3WHNDsZ1NsdFj7NiigDlittVkGc7RmPjKF3" } } } |
Attribute name | Data type | Description | ||
---|---|---|---|---|
records | array of objects | All records belonging to a specific entity and meeting the filter criteria, specified as an array of objects. Each array element is an object with the following attributes:
|
||
links | link object | Link to the next set of records. Attribute of the link object: next (object): An identifier of the next set of records, specified in the following key: value format: Copied Copy
|
1 2 3 4 5 6 7 8 9 10 11 12 13 | const record = await contact_entity.getAll({ query: { $or: [{ status: "Pending" }, { status: "Rejected" } ]}, next: { marker: "Lbr2zerj3WHNDsZ1NsdFj7NiigDlittVkGc7RmPjKF3" } }); |
1 2 3 4 5 6 7 8 9 10 11 12 13 | const record = await $entity.get(‘kyc_status’).getAll({ query: { $and: [{ status: "Pending" }, { document_type: "Voter ID" } ]}, next: { marker: "Lbr2zerj3WHNDsZ1NsdFj7NiigDlittVkGc7RmPjKF3" } }); |
Delete a record
To delete a specific record belonging to a specific entity, use one of the following interface calls:
1 | <entReference>.delete("<display-id>"); |
1 | const record = await <entReference>.delete('<display-id>'); |
1 | contact_entity.delete("kycs-14"); |
Error Responses
If a call fails, the custom objects interface returns an error response similar to following sample:
Copied Copy1 2 3 4 5 6 7 8 9 10 11 | { "message": "Invalid input field", "status": 400, "errors": [ { "message": "Field name should be of type string", "name": "label" } ], "errorSource": "APP" } |
Attribute name | Data type | Description |
---|---|---|
message | string | Generic message specifying the reason for the error. |
status | number | HTTP status code. |
errors | array of error objects |
All errors that caused the call to fail, specified as an array.
Attributes of the error object:
|
errorSource | string | Specifies whether the error is app or platform related. Possible values: APP, PLATFORM |
Test
Note: To test your app, use the latest version of the Chrome browser
- To test the configured custom objects, from the command prompt navigate to the app project folder and run the following command:
Copied
Copy
1
fdk run The command validates the entities.json file and displays the validation errors, if any. Fix the validation errors and run the command. The command creates a .sqlite file and the entities that are defined in entity.json. .sqlite mimics the platform’s entity storage, in the local setting.
Note: If the entity definition specification in entities.json is modified, for the modification to reflect in the local .sqlite file, you will have to rerun the fdk run command. A prompt to resync is displayed and a resync deletes all existing entities, associated data, and records and creates a clean instance. Log in to your Freshsales Suite account.
- To the account URL, append ?dev=true.
Example URL: https://domain.myfreshworks.com/crm/sales?dev=true
If the app is successfully created, it is rendered in the app location specified in manifest.json.
- To test the custom objects interface calls, from the app, simulate record operations. If the calls fail, appropriate error responses are displayed.