I build a workflow which execute an http api call and return as a response an array of objects, than i want to send this array of objects to a discord message but the message is published with [object Object].
This is the mark down i created
## Alert Details
- **Campaign items**: {{$json}}
- **Time of Occurrence**: {{ new Date() }}
Can you please share the workflow as that will help see the issue better. This could be a number of things so it would help to see the implementation. Please also share the JSON as the embedded workflows remove your pinned data for security
To help troubleshoot you can wrap what you’re currently returning with {{ JSON.stringify( $json.key ) }}
Unfortunately i can not share it since we run on a hosted instance and it contain some sensitive data. there is a way to copy the nodes without the data?
I will at lest need to see the discord node and a sample of the JSON. You can copy the json and censor all sensitive info. You can copy and paste just one node
replace the expressions with this and let me know how it works
{{ $json.items.join(', ') }} This makes the list a string and separates each item with a comma and space
{{ $now.toFormat('t D') }}$now gets current time in a DateTime obj. .toFormat('t D') turns it to this format “9:14 AM 3/7/2024”. You can format the date however you want, ref the luxon docs for their syntax.
It’s because you have arrays or objects in that array which i didn’t notice. When you try to add something like an array [ "thing 1", "thing 2" ] or an object { "thing 1":"this", "thing 2":"that"} it will return something like [object object].
Can you share a sample of what is in the items of the list? You can remove sensitive information first.
Like @barn4k said you’ll need to use the {{ JSON.stringify($json.items) }} as a catch-all to convert any object to a string, but it won’t be particularly pretty usually.
If you send the JSON and an example of what you want it to look like in the message we can help you with a method that gets you there. (provided the objects in the list are consistant)
but when i use it like your suggestion i am get the following error, see image attached
NodeOperationError:
at Object.parseDiscordError (/usr/local/lib/node_modules/n8n/packages/nodes-base/dist/nodes/Discord/v2/helpers/utils.js:66:12)
at Object.execute (/usr/local/lib/node_modules/n8n/packages/nodes-base/dist/nodes/Discord/v2/actions/webhook/sendLegacy.operation.js:125:51)
at processTicksAndRejections (node:internal/process/task_queues:95:5)
at Object.router (/usr/local/lib/node_modules/n8n/packages/nodes-base/dist/nodes/Discord/v2/actions/router.js:69:26)
at Object.execute (/usr/local/lib/node_modules/n8n/packages/nodes-base/dist/nodes/Discord/v2/DiscordV2.node.js:19:16)
at Workflow.runNode (/usr/local/lib/node_modules/n8n/packages/workflow/dist/Workflow.js:700:19)
at /usr/local/lib/node_modules/n8n/packages/core/dist/WorkflowExecute.js:656:53
at /usr/local/lib/node_modules/n8n/packages/core/dist/WorkflowExecute.js:1058:20