I am currently working with a helpdesk system API that provides data in separate requests. My goal is to consolidate this information into a single format suitable for my external service.
Current Situation
I first retrieve order details:
[
{
"order_id": 42,
"department_id": 1,
"status_id": 3,
"client_id": 15,
"reference": "ORD-2024-001",
"description": "Inquiry about the product from a client",
"assigned_to": 8,
"requester_id": 15,
"notes": null,
"opened_at": "2024-01-10T09:30:15.123Z",
"due_date": null,
"resolution_time": 0,
"time_difference": 2880,
"completed_at": null,
"last_activity": "2024-01-10T14:45:22.456Z",
"agent_contact": "2024-01-10T10:15:33.789Z",
"client_contact": "2024-01-10T14:45:22.456Z",
"settings": {
"source_id": 2,
"priority_calculation": {
"initial_response": "2024-01-10T10:15:33.789Z",
"updated_at": "2024-01-10T14:45:22.456Z",
"contact_time": "2024-01-10T14:45:22.456Z",
"level_id": 1,
"escalation_disabled": false
}
},
"modified_by": 8,
"created_by": 8,
"creation_date": "2024-01-10T09:30:15.067Z",
"modification_date": "2024-01-11T08:15:44.333Z"
}
]
Next, I fetch related messages:
[
{
"message_id": 85,
"order_id": 42,
"category_id": 2,
"author_id": 15,
"sender": "John Smith <[email protected]>",
"recipient": "[email protected]",
"subject": "Inquiry about product from client",
"thread_id": "<[email protected]>",
"content": "Hello, I require information regarding your services.",
"is_private": false,
"options": {
"auto_reply_sent": true,
"automated_message": false
},
"last_modified_by": 8,
"author_user_id": 8,
"timestamp": "2024-01-10T10:15:33.789Z",
"last_update": "2024-01-10T10:15:33.789Z",
"message_type": "email",
"author_role": "Customer",
"created_by_email": "[email protected]",
"updated_by_email": "[email protected]"
}
]
What I Require
I am looking to merge these into this structure:
{
"OrderData": {
"order_id": 42,
"department_id": 1,
// ... other order fields
},
"messages": [
{
"message_id": 85,
"order_id": 42,
// ... other message fields
}
]
}
I need assistance in writing the JavaScript code for n8n to effectively merge these arrays with customized property names. How should I structure this correctly?