A Middleware application that stores FreshService tickets and Creates a replica of the same in FreshDesk
GET /api/FreshService/
POST /api/Tickets/createTickets
Parameter | Type | Description |
---|---|---|
FS_fields |
JSON |
Required. FreshServiceTicket data |
POST /api/Tickets/storeFieldMap
Parameter | Type | Description |
---|---|---|
map |
JSON |
Required. FreshDesk and FreshService ticket map |
FD_Fields |
JSON |
Required. FreshDesk Field names |
To run this project, you will need to add the following environment variables to your .env file.
also check out the sample.env
file
PORT
FRESHDESK_API
DB_PASSWORD
DB_NAME
FRESHDESK_URL
FS_URL
FS_API
Clone the project
git clone https://github.com/Maanaesh/FreshService-Middleware.git
Go to the project directory
cd FreshService-Middleware
Install dependencies
npm install
Start the server
npm run dev
server should return something like this
MySQL pool created
Database connected successfully
Middleware listening on port 5001
onAppInstall
EventWhen the onAppInstall event is triggered, the middleware performs the following actions:
The event is triggered when the app is installed in Freshservice
Field Mapping:
A map of Freshservice fields and Freshdesk fields is passed to the Node.js server.
These field maps are used to define the columns in the Tickets table.
The app connects to the MySQL server and checks if the Tickets table exists.
It creates a backup of the existing table (renaming the table to Ticketsbackup
Drops the old Tickets table.
A new Tickets table is created based on the provided field mappings.
onTicketCreate
EventWhen the onTicketCreate
event is triggered in the serverless Freshservice application, the middleware performs the
following actions:
Field Filtering
Filters out fields based on the map of Freshdesk and Freshservice fields stored in the iparams
.
The serverless app appends the email id field to the ticket, where the value is the requester’s email id.
Ticket Forwarding
email
and pushed_to_freshdesk
.email
and pushed_to_freshdesk
columns.Tickets
table.handler.js
- Scheduled Ticket Pusher to FreshdeskThe handler.js
file is responsible for automating the process of pushing unsynchronized tickets from the local SQL database to Freshdesk using their API. It is designed to run periodically using the cron
module, ensuring that any new or unsynced tickets are submitted to Freshdesk.
Cron Scheduling:
*/30 * * * * *
) to check for tickets in the local database that haven't been pushed to Freshdesk yet.node-cron
library.Fetching Tickets:
getConnection()
method and queries the Tickets
table to fetch all tickets where the pushed_to_freshdesk
field is set to 0
.Formatting Tickets:
pushed_to_freshdesk
field, which is omitted from the request).Pushing Tickets to Freshdesk:
/api/v2/tickets
) using axios
, including the API key in the headers for authentication.201
), the system marks the ticket as pushed in the local database by updating the pushed_to_freshdesk
field to 1
.Error Handling:
handler(key, url)
Parameters:
key
: Your Freshdesk API key, used for authenticating API requests.url
: The base URL for your Freshdesk instance, e.g., https://yourcompany.freshdesk.com
.Description:
pushed_to_freshdesk
field.pushed_to_freshdesk
to 1
.getConnection()
method from the db.js
file to interact with the SQL database.Bulk Upload of Tickets:
Handling SQL Data Types:
status
and priority
fields. However, Freshdesk ticket fields might have different data types (e.g., dates, numbers, booleans). The implementation should be improved by fetching and dynamically applying the correct field types when processing ticket data from SQL to ensure consistency with Freshdesk’s ticket schema.