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 7.3.x or a later version.
Note:: Custom objects created as part of the Freshdesk in-product experience or through an app (as specified in this section) cannot be accessed by another app.
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 - Relational information: Restaurant cataloguing for a food delivery business that uses Freshdesk. The business has photography vendors who visit restaurants based on a schedule. Restaurants send their request to Freshdesk, as a ticket (native object). An app using custom objects (restaurants and vendor availability), maps the request to vendors and schedules a visit.
Notes:- 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 to Freshdesk accounts on a,
- Support Desk - Enterprise plan or Omnichannel - Enterprise plan, Pro plan, and Customer Service Suite - Pro plan.
- (For older accounts) Support Desk - Forest plan or Omnichannel - Estate, Forest plans.
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. Tickets, Contacts, Users, Agents, and so on are some default native objects. tickets.description, tickets.status and tickets.priority are some of the attributes of the ticket 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.
Note: After an app is published, you can update or modify the entity definition and submit a new version of the app.
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 syntax shown on the right pane to configure all custom objects that the app uses, as JSON objects.
- You can define a maximum of five entities per app for each business account. This limit is applicable to each installation of the app. For a custom app, which is installed only once on an account, this limit applies to that single installation. For public apps, which can be installed by numerous accounts, each installation has its own separate limit of five entities.
- You can define a maximum of 20 fields (attributes) for each entity.
Attributes 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 restaurants , <entity-name> in entities.json is restaurants.
The app and its users can create multiple records or objects of type restaurants. Each record is a collection of attributes. In entities.json, specify the attributes’ definition through the fields array.
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:
const entity = client.db.entity({ version: "v1" });
const $entity = $db.entity({ version: "v1" });
Response
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:
const <entReference> = entity.get("<entity-name>");
const <entReference> = $entity.get("<entity-name>");
Response
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.
{
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:
Note:<entReference> is a reference to the actual entity.
<entReference>.schema();
$entity.get("<entity-name>").schema();
Response
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.
For information on the fields array, see Attributes of <entity-name>.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 > <entity-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:
Notes:- There is no limitation on the number of records you can create for an 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.
<entReference>.create({
<fields.name1>: <valid value for fields.name1>,
<fields.name2>: "<valid value for fields.name2>"
});
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.
Update a record
To update a record belonging to a specific entity, use one of the following interface calls:
Notes:- <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.
<entReference>.update("<display-id>", {
<fields.name1>: "<valid value for fields.name1>",
<fields.name2>: <valid value for fields.name2>
});
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.
Retrieve a record
To retrieve a specific record belonging to a specific entity, use one of the following interface calls:
Note:<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.
<entReference>.get("<display-id>");
const record = await $entity.get("<entity-name>").get("<display-id>");
restaurant.get("scshv-2");
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.
Retrieve all records
To retrieve all records belonging to a specific entity, use one of the following interface calls:
Note: <entReference> is a reference to the actual entity.
<entReference>.getAll();
const records = await <entReference>.getAll({});
async function loadRestaurants() {
try {
let data = await restaurant.getAll();
//render details of all restaurants as a list
} catch (error) {
// Error Handling
console.error(error)
}
}
Response: A successful retrieve all records operation, returns the retrieved records as an array of objects. The retrieved records are not paginated, retrieved in sets of 100 records, and ordered by created_time chronologically. The links attribute in the response provides a token to retrieve the next set of records.
Response attributes
- linksobject
Link to the next set of records.
- recordsarray of objects
All retrieved records belonging to a specific entity, specified as an array of objects.
async function loadRestaurants() {
try {
let data = await restaurant.getAll({
next: {
marker: "Lbr2zerj3WHNDsZ1NsdFj7NiigDlittVkGc7RmPjKF3"
}
});
//render details of all restaurants as a list
} catch (error) {
// Error Handling
console.error(error)
}
}
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:
Notes:- 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.
<entReference>.getAll({
query: {
<filterable field-name>: "<filter criteria value>"
}
});
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:
Notes:- 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.
Sample 1 - $or query construct
async function loadRestaurants() {
try {
let data = await restaurant.getAll({
query: {
$or: [
{
loc_zipcode: "600123"
},
{
loc_zipcode: "600106"
}
]
}
});
// access to filtered restaurant details
}
catch (error) {
// Error Handling
console.error(error)
}
}
Response: A successful retrieve all records operation with filters, returns the records that meet the filter criteria as an array of objects.
Response attributes
- linksobject
Link to the next set of records.
- recordsarray of objects
All records belonging to a specific entity and meeting the filter criteria, specified as an array of objects.
Sample 2- retrieve subsequent sets of filtered records
const record = await restaurant.getAll({
query: {
$or: [{
loc_zipcode: "600123"
},
{
loc_zipcode: "600106"
}]
},
next: {
marker: "Lbr2zerj3WHNDsZ1NsdFj7NiigDlittVkGc7RmPjKF3"
}
});
Sample 3 - $and query construct
const record = await $entity.get("restaurants").getAll({
query: {
$and: [{
loc_zipcode: "600123"
},
{
short_code: "HT1"
}]
},
next: {
marker: "Lbr2zerj3WHNDsZ1NsdFj7NiigDlittVkGc7RmPjKF3"
}
});
Delete a record
To delete a specific record belonging to a specific entity, use one of the following interface calls:
Note: <entReference> is 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.
<entReference>.delete("<display-id>");
Response: A successful delete operation returns an empty object.
Error responses
If a call fails, the custom objects interface returns an error response with the following attributes.
Error response attributes
- messagestring
Generic message specifying the reason for the error.
- statusinteger
HTTP status code.
- errorsarray of objects
All errors that caused the call to fail, specified as an array.
- errorSourcestring
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:
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 Freshworks product account.
If the app is successfully created, it is rendered in the app location specified in manifest.json.
To the Freshworks product account URL, append ?dev=true.
Example URL: https://subdomain.freshdesk.com/helpdesk/tickets/1?dev=trueTo test the custom objects interface calls, from the app, simulate record operations. If the calls fail, appropriate error responses are displayed.