Working with Helpdesk API Data in n8n
I am building an n8n workflow that needs to retrieve information from a helpdesk API. This API provides two distinct JSON arrays that I want to merge into one coherent object.
First API response includes support requests:
[
{
"request_id": 42,
"department_id": 1,
"urgency_level": 3,
"status_id": 1,
"company_id": null,
"reference_number": "REQ-2023-001",
"subject": "Login Issue - Database Access",
"assigned_to": 7,
"requester_id": 15,
"description": null,
"initial_response_time": "2023-03-20T09:15:22.456Z",
"escalation_deadline": null,
"response_time_minutes": 0,
"response_delay_minutes": 2880,
"resolution_time": null,
"resolution_deadline": null,
"total_resolution_minutes": null,
"resolution_delay_minutes": null,
"next_escalation_time": null,
"estimated_work_minutes": null,
"actual_work_minutes": null,
"last_activity_time": "2023-03-20T09:22:15.789Z",
"last_agent_contact": "2023-03-20T09:18:33.123Z",
"last_customer_contact": "2023-03-20T09:22:15.789Z",
"last_assignment_change": "2023-03-20T14:30:12.654Z",
"initial_contact_method": 2,
"initial_sender_type": 1,
"total_messages": 5,
"next_escalation": null,
"hold_until": null,
"category": null,
"billable_hours": null,
"settings": {
"contact_method_id": 2,
"sla_calculation": {
"initial_response_time": "2023-03-20T09:15:22.456Z",
"last_modification_time": "2023-03-20T09:22:15.789Z",
"last_interaction_time": "2023-03-20T09:22:15.789Z",
"service_level_id": 1,
"sla_last_updated": "2023-04-10T11:45:33.987Z",
"schedule_id": 1,
"schedule_last_updated": "2023-04-12T08:30:45.321Z",
"escalation_active": true
}
},
"last_modified_by": 7,
"created_by_user": 15,
"creation_timestamp": "2023-03-20T09:15:22.401Z",
"modification_timestamp": "2023-04-18T12:15:44.876Z",
"final_resolution_time": null
}
]
Second API response contains conversation history:
[
{
"message_id": 245,
"request_id": 42,
"message_type": 2,
"sender_type": 2,
"sender_email": "john.doe <[email protected]>",
"recipient_email": "[email protected]",
"cc_recipients": null,
"message_subject": "Login Issue - Database Access",
"reply_to_address": null,
"unique_message_id": "<[email protected]>",
"message_hash": "1a2b3c4d5e6f7g8h9i0j1k2l3m4n5o6p",
"in_response_to": null,
"message_format": "text/plain",
"email_references": null,
"message_content": "\nI cannot access the database system after the recent update.\n\n-- \nBest regards | John Doe | Ext: 1234 | Mobile: +1-555-0123\n",
"private_note": false,
"message_settings": {
"auto_reply_sent": true,
"is_automated_response": false
},
"last_modified_by": 7,
"created_by_user": 15,
"original_author_id": null,
"creation_timestamp": "2023-03-20T09:15:22.456Z",
"modification_timestamp": "2023-03-20T09:15:22.456Z",
"file_attachments": [],
"communication_type": "email",
"sender_role": "Customer",
"created_by_email": "[email protected]",
"modified_by_email": "[email protected]"
}
]
Desired output structure:
{
"SupportRequest": {
"request_id": 42,
"department_id": 1,
// ... remaining request data
},
"messages": [
{
"message_id": 245,
"request_id": 42,
// ... remaining message data
}
]
}
I have a custom Node.js service that requires this combined format. I seek guidance on how to write JavaScript in n8n to merge these two JSON responses into a single object with labeled sections.
I’ve looked into methods for merging JSON, but I find it challenging to include property names such as “SupportRequest” and “messages”. I’m new to JavaScript, so I would really appreciate any guidance!
Thank you for your help!