I’m working with a customer support system API that returns data in separate calls. I need help combining these JSON responses into one structured object.
First API call returns customer requests:
[
{
"request_id": 45,
"department_id": 1,
"urgency_level": 3,
"status_id": 1,
"company_id": null,
"reference": "REQ-2023-001",
"subject": "System Integration Query",
"assigned_to": 5,
"requester_id": 8,
"description": null,
"initial_response_time": "2023-03-20T09:15:22.045Z",
"response_due": null,
"resolution_time_minutes": 0,
"resolution_variance": 2880,
"closed_date": null,
"closure_deadline": null,
"created_timestamp": "2023-03-20T09:15:22.001Z",
"modified_timestamp": "2023-03-22T14:30:15.789Z",
"final_closure": null
}
]
Second API call gets related messages:
[
{
"message_id": 87,
"request_id": 45,
"category_id": 2,
"author_id": 8,
"sender_email": "john.doe <[email protected]>",
"recipient_email": "[email protected]",
"copied_to": null,
"message_title": "System Integration Query",
"response_to": null,
"thread_id": "<[email protected]>",
"thread_hash": "9a8b7c6d5e4f3g2h1i0j",
"parent_message": null,
"format_type": "text/plain",
"message_content": "Hello, I need assistance with API integration setup.",
"is_private": false,
"system_settings": {
"auto_reply_enabled": true,
"automated_response": false
},
"last_modified_by": 5,
"author_user_id": 5,
"created_timestamp": "2023-03-20T09:15:22.045Z",
"modified_timestamp": "2023-03-20T09:15:22.045Z",
"file_attachments": [],
"communication_type": "email",
"sender_role": "Customer",
"author_email": "[email protected]",
"modifier_email": "[email protected]"
}
]
Target structure needed:
{
"support_request": {
"request_id": 45,
"department_id": 1,
// ... all request fields
},
"communications": [
{
"message_id": 87,
"request_id": 45,
// ... all message fields
}
]
}
I need to write JavaScript code in my n8n workflow to combine these arrays into this nested structure. The tricky part for me is adding the wrapper keys like “support_request” and “communications”. I’m not experienced with JavaScript so any help would be great!