Need assistance merging JSON data from separate API responses
I’m currently handling an API for a support ticketing system that returns information in multiple parts. One part consists of JSON data for the main ticket, and another includes comments related to that ticket.
Here’s the format of the main ticket data:
[
{
"order_id": 789,
"department_id": 5,
"urgency_level": 3,
"status_id": 1,
"company_id": null,
"reference": "REF-2024-001",
"subject": "System Integration Issue",
"assigned_to": 12,
"requester_id": 45,
"description": "Database connection problems",
"opened_at": "2024-01-10T09:30:15.123Z",
"due_date": "2024-01-15T17:00:00.000Z",
"resolution_time": 240,
"last_activity": "2024-01-12T14:22:30.456Z",
"tags": ["database", "urgent"],
"custom_fields": {
"priority_score": 85,
"category": "technical"
}
}
]
And below is the comments data:
[
{
"comment_id": 567,
"order_id": 789,
"author_id": 12,
"author_email": "[email protected]",
"recipient": "[email protected]",
"comment_text": "Initial investigation shows connection timeout issues",
"visibility": "public",
"posted_at": "2024-01-10T10:15:22.789Z",
"edited_at": "2024-01-10T10:16:05.234Z",
"comment_type": "update",
"author_name": "John Doe"
},
{
"comment_id": 568,
"order_id": 789,
"author_id": 45,
"author_email": "[email protected]",
"recipient": "[email protected]",
"comment_text": "The issue started after the recent server update",
"visibility": "public",
"posted_at": "2024-01-10T11:45:33.567Z",
"edited_at": null,
"comment_type": "reply",
"author_name": "Jane Smith"
}
]
I want to merge these into a single object formatted like this:
{
"MainTicket": {
"order_id": 789,
"department_id": 5,
"urgency_level": 3,
"status_id": 1,
"company_id": null,
"reference": "REF-2024-001",
"subject": "System Integration Issue",
"assigned_to": 12,
"requester_id": 45,
"description": "Database connection problems",
"opened_at": "2024-01-10T09:30:15.123Z",
"due_date": "2024-01-15T17:00:00.000Z",
"resolution_time": 240,
"last_activity": "2024-01-12T14:22:30.456Z",
"tags": ["database", "urgent"],
"custom_fields": {
"priority_score": 85,
"category": "technical"
}
},
"Comments": [
{
"comment_id": 567,
"order_id": 789,
"author_id": 12,
"author_email": "[email protected]",
"recipient": "[email protected]",
"comment_text": "Initial investigation shows connection timeout issues",
"visibility": "public",
"posted_at": "2024-01-10T10:15:22.789Z",
"edited_at": "2024-01-10T10:16:05.234Z",
"comment_type": "update",
"author_name": "John Doe"
},
{
"comment_id": 568,
"order_id": 789,
"author_id": 45,
"author_email": "[email protected]",
"recipient": "[email protected]",
"comment_text": "The issue started after the recent server update",
"visibility": "public",
"posted_at": "2024-01-10T11:45:33.567Z",
"edited_at": null,
"comment_type": "reply",
"author_name": "Jane Smith"
}
]
}
Could someone provide me with JavaScript code to achieve this in n8n? I’m struggling with how to format it correctly to include sections like “MainTicket” and “Comments”. Any guidance would be greatly appreciated. Thank you!